{"id":21058981,"url":"https://github.com/robotdad/gpio_iotoggle_trustzone_nucleo_u5","last_synced_at":"2025-07-19T02:32:59.027Z","repository":{"id":186505968,"uuid":"611559423","full_name":"robotdad/GPIO_IOToggle_TrustZone_Nucleo_U5","owner":"robotdad","description":"GPIO_IOToggle_TrustZone_Nucleo_U5","archived":false,"fork":false,"pushed_at":"2023-03-09T18:53:07.000Z","size":1163,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T18:02:55.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robotdad.png","metadata":{"files":{"readme":"README-ST.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-09T04:10:32.000Z","updated_at":"2023-03-09T04:10:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"d6c0bf2d-a85a-489e-aba6-c8ed91c81eed","html_url":"https://github.com/robotdad/GPIO_IOToggle_TrustZone_Nucleo_U5","commit_stats":null,"previous_names":["robotdad/gpio_iotoggle_trustzone_nucleo_u5"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robotdad/GPIO_IOToggle_TrustZone_Nucleo_U5","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2FGPIO_IOToggle_TrustZone_Nucleo_U5","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2FGPIO_IOToggle_TrustZone_Nucleo_U5/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2FGPIO_IOToggle_TrustZone_Nucleo_U5/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2FGPIO_IOToggle_TrustZone_Nucleo_U5/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robotdad","download_url":"https://codeload.github.com/robotdad/GPIO_IOToggle_TrustZone_Nucleo_U5/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robotdad%2FGPIO_IOToggle_TrustZone_Nucleo_U5/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265876925,"owners_count":23842956,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T17:09:38.372Z","updated_at":"2025-07-19T02:32:59.010Z","avatar_url":"https://github.com/robotdad.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## \u003cb\u003eGPIO_IOToggle_TrustZone Example Description\u003c/b\u003e\n\nHow to use HAL GPIO to toggle secure and unsecure IOs when TrustZone security is activated (Option bit TZEN=1).\n\nThe purpose of this example is to declare a secure IO with HAL GPIO and to toggle it\nevery second on Secure SysTick timer interrupt basis. All other IOs are released to\nnon-secure application and a non-secure IO is initialized by the non-secure application\nto toggle every two seconds on Non-secure Systick timer interrupt basis.\n\nThe secure IO is PC.07 which corresponds to LED1 and the non-secure toggling IO is PB.07 for LED2.\n\nThe secure **LED1 toggles** every second and remains on in case of error in secure code.\nThe non-secure **LED2 toggles** twice faster and remains on in case of error in non-secure code.\n\nThis project is composed of two sub-projects:\n\n- One for the secure application part (xxxxx_S)\n- One for the non-secure application part (xxxxx_NS).\n\nPlease remember that on system with security enabled:\n\n- the system always boots in secure and the secure application is responsible for\nlaunching the non-secure application.\n- the SystemInit() function in secure application sets up the SAU/IDAU, FPU and\nsecure/non-secure interrupts allocations defined in partition_stm32u575xx.h file.\n\nThis project shows how to switch from secure application to non-secure application\nthanks to the system isolation performed to split the internal Flash and internal SRAM memories\ninto two halves:\n\n - The first half for the secure application and\n - The second half for the non-secure application.\n\nUser Option Bytes configuration:\nPlease note the internal Flash is fully secure by default in TZEN=1 and User Option Bytes\nSECWM1_PSTRT/SECWM1_PEND and SECWM2_PSTRT/SECWM2_PEND should be set according to the application\nconfiguration. Here the proper User Option Bytes setup in line with the project linker/scatter\nfile is as follows:\n\n    - TZEN=1\n    - SECWM1_PSTRT=0x0  SECWM1_PEND=0x7F  meaning all 128 pages of Bank1 set as secure\n    - SECWM2_PSTRT=0x7F SECWM2_PEND=0x0   meaning all 128 pages of Bank2 set as non_secure\n\nAny attempt by the non-secure application to access unauthorized code, memory or\nperipheral generates a fault as demonstrated in non secure application by uncommenting some\ncode instructions in main.c.\n\nThis project is targeted to run on STM32U5 device on boards from STMicroelectronics.\n\nThis example configures the maximum system clock frequency at 160Mhz.\n\n#### \u003cb\u003eNotes\u003c/b\u003e\n\n 1. Care must be taken when using HAL_Delay(), this function provides accurate delay (in milliseconds)\n    based on variable incremented in SysTick ISR. This implies that if HAL_Delay() is called from\n    a peripheral ISR process, then the SysTick interrupt must have higher priority (numerically lower)\n    than the peripheral interrupt. Otherwise the caller ISR process will be blocked.\n    To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function.\n\n 2. The application need to ensure that the SysTick time base is always set to 1 millisecond\n    to have correct HAL operation.\n\n 3. The following sequence is needed to disable TrustZone:\n \n      - **Boot from user Flash memory**: \n         a.\tMake sure that secure and non-secure applications are well loaded and executed (jump done on non-secure application).\n         b.\tIf not yet done, set RDP to level 1 through STM32CubeProgrammer. Then only Hotplug connection is possible during non-secure application execution.\n         c.\tUse a power supply different from ST-LINK in order to be able to connect to the target.\n         d.\tUncheck the TZEN box and set RDP to level 0 (option byte value 0xAA), then click on Apply.\n\n     - **Boot from RSS**:\n         a.\tMake sure to apply a high level on BOOT0 pin (make sure that nSWBOOT0 Option Byte is checked).\n         b.\tIf not yet done, set RDP to level 1 through STM32CubeProgrammer. Then only Hotplug connection is possible during non-secure application execution.\n         c.\tUse a power supply different from ST-LINK in order to be able to connect to the target.\n         d.\tUncheck the TZEN box and set RDP to level 0 (option byte value 0xAA), then click on Apply.\n\t\t \n\tPlease refer to AN5347 for more details.\t \n\n### \u003cb\u003eKeywords\u003c/b\u003e\n\nSystem, GPIO, GTZC, Output, Alternate function, Push-pull, TrustZone\n\n### \u003cb\u003eDirectory contents\u003c/b\u003e\n\n  - Secure/Src/main.c                            Secure Main program\n  - Secure/Src/secure_nsc.c                      Secure Non-secure callable functions\n  - Secure/Src/stm32u5xx_hal_msp.c               Secure HAL MSP module\n  - Secure/Src/stm32u5xx_it.c                    Secure Interrupt handlers\n  - Secure/Src/system_stm32u5xx_s.c              Secure STM32U5xx system clock configuration file\n  - Secure/Inc/main.h                            Secure Main program header file\n  - Secure/Inc/partition_stm32u575xx.h           STM32U5 Device System Configuration file\n  - Secure/Inc/stm32u5xx_hal_conf.h              Secure HAL Configuration file\n  - Secure/Inc/stm32u5xx_it.h                    Secure Interrupt handlers header file\n  - Secure_nsclib/secure_nsc.h                   Secure Non-Secure Callable (NSC) module header file\n  - NonSecure/Src/main.c                         Non-secure Main program\n  - NonSecure/Src/stm32u5xx_hal_msp.c            Non-secure HAL MSP module\n  - NonSecure/Src/stm32u5xx_it.c                 Non-secure Interrupt handlers\n  - NonSecure/Src/system_stm32u5xx_ns.c          Non-secure STM32U5xx system clock configuration file\n  - NonSecure/Inc/main.h                         Non-secure Main program header file\n  - NonSecure/Inc/stm32u5xx_hal_conf.h           Non-secure HAL Configuration file\n  - NonSecure/Inc/stm32u5xx_it.h                 Non-secure Interrupt handlers header file\n\n### \u003cb\u003eHardware and Software environment\u003c/b\u003e\n\n  - This example runs on STM32U575xx devices with security enabled (TZEN=1).\n\n  - This example has been tested with STMicroelectronics NUCLEO-U575ZI-Q (MB1549)\n    board and can be easily tailored to any other supported device\n    and development board.\n\n  - User Option Bytes requirement (with STM32CubeProgrammer tool)\n\n        - TZEN = 1                            System with TrustZone-M enabled\n        - SECWM1_PSTRT=0x0  SECWM1_PEND=0x7F  All 128 pages of internal Flash Bank1 set as secure\n        - SECWM2_PSTRT=0x7F  SECWM2_PEND=0x0  No page of internal Flash Bank2 set as secure, hence Bank2 non-secure\n\n### \u003cb\u003eHow to use it ?\u003c/b\u003e\n\nIn order to make the program work, you must do the following :\n\n\u003cb\u003eIAR\u003c/b\u003e\n\n - Open your toolchain\n - Open Multi-projects workspace file Project.eww\n - Set the \"xxxxx_S\" as active application (Set as Active)\n - Rebuild xxxxx_S project\n - Rebuild xxxxx_NS project\n - Load the secure and non-secures images into target memory (Ctrl + D)\n - Run the example\n\n\u003cb\u003eMDK-ARM\u003c/b\u003e\n\n - Open your toolchain\n - Open Multi-projects workspace file Project.uvmpw\n - Select the xxxxx_S project as Active Project (Set as Active Project)\n - Build xxxxx_S project\n - Select the xxxxx_NS project as Active Project (Set as Active Project)\n - Build xxxxx_NS project\n - Load the non-secure binary (F8)\n   (this shall download the \\MDK-ARM\\xxxxx_ns\\Exe\\Project_ns.axf to flash memory)\n - Select the xxxxx_S project as Active Project (Set as Active Project)\n - Load the secure binary (F8)\n   (this shall download the \\MDK-ARM\\xxxxx_s\\Exe\\Project_s.axf to flash memory)\n - Run the example\n\n\u003cb\u003eSTM32CubeIDE\u003c/b\u003e\n\n - Open STM32CubeIDE\n - File \u003e Import. Point to the STM32CubeIDE folder of the example project. Click Finish.\n - Select and build the xxxxx_NS project, this will automatically trigger build of xxxxx_S project\n - Select the xxxxx_S project and select “Debug configuration”\n   - Double click on “STM32 Cortex-M C/C++ Application”\n   - Select  “Startup” \u003e  “Add” \u003e\n - Select the xxxxx_NS project\n - Build configuration : Select Release/Debug\n   - Click Debug to debug the example\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobotdad%2Fgpio_iotoggle_trustzone_nucleo_u5","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobotdad%2Fgpio_iotoggle_trustzone_nucleo_u5","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobotdad%2Fgpio_iotoggle_trustzone_nucleo_u5/lists"}