2025-11-09 2:52 PM
Hello,
STM32CubeIDE Version: 1.19.0
STM32CubeU3 Firmware Package V1.2.0 / 04-June-2025
When new project STM32 project with "enable Trust Zone" is created, template produced by STM32CubeIDE fail with HardFault. I have trace primary problem down to NonSecure_Init() function, where VTOR address is read from
vtor_ns = SCB_NS->VTOR;
Value of the SCB_NS->VTOR is 0x800000, and it is in secure area, so access to NonSecure_ResetHandler() fail with HF.
I have fixed it by adding SCB_NS->VTOR = 0x8080000; in the secure main.c.
If i look into GTZC_TZSC_MPCBB_TrustZone/Secure/Src/main.c, there is an addition effort to set correct NS VTOR value, which is missing in the generated code.
#if defined ( __ICCARM__ )
SCB_NS->VTOR= (uint32_t)&(__VTOR_TABLE_NS_start);
#elif defined(__ARMCC_VERSION)||defined(__GNUC__)
SCB_NS->VTOR= __VTOR_TABLE_NS_start;
#endif
This correction helps, and I am able switch from secure to nonsecure mode. Anyway, nonsecure code soon fail with HardFault again. Seems like part of SRAM supposed to be nonsecure isn't configured properly, and remain secure.
MX_GTZC_S_Init() function responsible for SRAM initialization contain only
MPCBB_Area_Desc.AttributeConfig.xxxx[x] = 0xFFFFFFFF;
To compare, in GTZC_TZSC_MPCBB_TrustZone/Secure/Src/main.c there are couple array values set to 0x00000000;
I am no sure it's bug, or am I miss some configuration somewhere. But, same way generated code for STM32U5 is working. How to fix all issues?
Regards,
Slavomir Tomascik
2025-11-09 3:48 PM
Right after I sent a question, I found note:
- NSBOOT0 address for non-secure automatic VTOR update : BOOT0R = 0x08080000
This solve problem with VTOR, but nonsecure code still fail with hardfault.
S.T.