STM32H573i-DK with Trustzone: HardFault with ThreadX and NSC Calls
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
