cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-H563ZI: Blink LED with TrustZone enabled

Shubham08
Associate II

Hii Sir,

Recently I have got Nucleo-H563ZI nucleo board and i was trying to do programming for blinking led present on the board with the trust zone activated, but i am unable to get how to do it.

The process i follow is;

1) Created new stm32 project -> Give the name of the project -> selected with TrustZone -> Finish. As the onboard LED was already defined in the .ioc file. Therefore generated the project with the default configuration, under main folder, two more folder were generated secure and non-secure. in nonsecure folder -> Core ->  Src -> main.c in this main.c file searched for while loop and added toggleing of led code in it and build the code. As there was confusion which code to be uploaded first i tried to upload the nonsecure folder but the led was not blinking (only the led was on ) during this when I press the reset button the led was off. second time, I build the secure folder code and flash it in the microcontroller toggleing was working but the led that was on was off.

 

2) I followed some youtube tutorial in that in stm32cube ide there was example code, i searched for the GPIO_Toggle code with trustzone for the particular board (STM32H563ZI nucleo) and generated code for it but that was also not working.

 

I am getting confused and not getting the flow that how write code for this microcontoller as in this I was facing problem with led blinking, consider i want to connect mpu6050 which has i2c protocol for communication how to write code for it like after initializing the pin in ioc file and code generation what steps to be done.

 

As previously, I was using STM32F407 there was direct coding that due to Trustzone I am getting confused about the flow. 

 

 

Thankyou,

Regards,

Shubham

5 REPLIES 5
Bubbles
ST Employee

Hi @Shubham08,

when TZ is selected, the MCU always starts by executing the secure code. This typically sets the boundaries in which the non-secure code can execute. Then it invokes the non-secure code.

In STM32Cube_FW_H5_V1.5.0\Projects\NUCLEO-H563ZI\Examples\GPIO\GPIO_IOToggle_TrustZone is very nice example of the LED blinking demo with TZ enabled.

The readme.file included there will explain how to initiate the debugging with TZ.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Shubham08
Associate II
  • STM32CubeIDE
  • Open STM32CubeIDE
  • File > Import. Point to the STM32CubeIDE folder of the example project. Click Finish.
  • Select and build the xxxxx_NS project, this will automatically trigger build of xxxxx_S project
  • Select the xxxxx_S project and select “Debug configuration”
    • Double click on “STM32 Cortex-M C/C++ Application”
    • Select “Startup” > “Add” >
  • Select the xxxxx_NS project
  • Build configuration : Select Release/Debug
  • Click Debug to debug the example

Sir I followed this step but the highlighted step is not working in stm32cube ide and the steps after that is more confusing.

Hello @Shubham08 ,

the point is to have both loaded, which for some reason is not default.

Bubbles_0-1739983230750.png

It's easier in normal commercial IDE.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Shubham08
Associate II

Thank you sir for giving the step through image. I tried to debug after it but was unable to see the Toggle of led. I doubt that the toggle will be seen on the port or in the user-led present on the board. As in the readme file, LED1 corresponds to secure IO and LED2 corresponds to non-secure IO. 

If I have connected button and led externally to any pin of the microcontroller then how to write code for it and in which folder 

Elhem_ZAY
ST Employee

Hello,
at first you make sure if you borad Nucleo-H563ZI is TZEN enable using STM32CubeProgrammer and verify the option byte(TZEN,SECWM1_PSTRT,SECWM1_PEND,SECWM2_PSTRT,SECWM2_PEND) are configured correctly.  
please apply the step in readme in the part of Hardware and software environment 

User Option Bytes requirement (with STM32CubeProgrammer tool)

  • TZEN=B4 System with TrustZone-M enabled
  • SECWM1_PSTRT=0x0 SECWM1_PEND=0x7F All 128 pages of internal Flash Bank1 set as secure
  • SECWM2_PSTRT=0x1 SECWM2_PEND=0x0 No page of internal Flash Bank2 set as secure, hence Bank2 non-secure

this is link of application Tx_SecureLEDToggle_TrustZone that you can try it 

https://github.com/STMicroelectronics/STM32CubeH5/tree/main/Projects/NUCLEO-H563ZI/Applications/ThreadX/Tx_SecureLEDToggle_TrustZone


the part of "How to use it ?" in the readme can help you  to work the application in 3 IDE (EWARM, MDK-ARM, STM32CubeIDE)

Always  Build xxxxx_S Build xxxxx_NS Load non-secure binary Load secure binary

Best regards.