cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H573i-DK with Trustzone: HardFault with ThreadX and NSC Calls

funkii
Associate III

Hi everyone,

I'm currently trying to switch to the Secure World within ThreadX using a NSC function (I use an empty function for debugging, but the problem does persist also if I do anything there).

Problem:

If i call my NSC function in the NonSecure main.c before the MX_ThreadX_Init() it works fine.

If i call it after it in some application, it does not work.

More precise, i get an HardFault with the STKERR, BFARVALID, PRECISERR, bit set in the BFSR register. see here for more infos about the registers . Also the stackpointer sp is at the end of the secure RAM (Increasing the RAM does not help, it then still is at the end) 

 

After debugging a while, I found after what instruction/function my error occurs. 

In _tx_initialize_kernel_enter() in the file tx_initialize_kernel_enter.c the function _tx_thread_secure_stack_initialize() gets executed by the macro TX_PORT_SPECIFIC_PRE_INITIALIZATION. 

Before that call, the NSC function works, after it I go straight to the HardFault handler. If i just comment out that callto the secure stack initialize, everything seems to just works fine, including the rest of my setup.

I tried to look at the function in Middlewares/ST/threadx/ports/cortex_m33/gnu/src/tx_thread_secure_stack_initialize.S but I don't really understand whats happening there tbh.

 

Anyone got an Idea why this is happening or what good the secure stack init does? Is it a problem if I just remove it from my code?

 

Best,

funkii

 

3 REPLIES 3
STea
ST Employee

Hello @funkii ,

Did you try to increase the stack size? because it seems from a first glance that the stack allocation done by _tx_thread_secure_stack_initialize() eats up the stack .

BR

In order 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.
funkii
Associate III

Hi @STea ,

thank you for your reply.

Yes, i have tried to increase the _Min_Stack_size in the STM32H573IIKXQ_FLASH.ld file both of the secure and nonsecure subproject with the values 0x400, 0x4000 and 0x40000. 

Unfortunately this did not change anything.

Best and sorry for my delayed response,

funkii

Jocelyn RICARD
ST Employee

Hello @funkii 

please have a look to threadX example with TrustZone:

STM32Cube_FW_H5_V1.1.1\Projects\NUCLEO-H563ZI\Applications\ThreadX\Tx_SecureLEDToggle_TrustZone\

Best regards

Jocelyn