2024-04-03 03:11 AM
#define VTOR_TABLE_NS_START_ADDR 0x08100000UL
static void NonSecure_Init(void);
static void MX_GPIO_Init(void);
static void MX_GTZC_S_Init(void);
static void MX_ICACHE_Init(void);
int main(void)
{
HAL_Init();
/* GTZC initialisation */
MX_GTZC_S_Init();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ICACHE_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/*************** Setup and jump to non-secure *******************************/
NonSecure_Init();
while (1)
{
}
}
static void NonSecure_Init(void)
{
funcptr_NS NonSecure_ResetHandler;
SCB_NS->VTOR = VTOR_TABLE_NS_START_ADDR;
/* Set non-secure main stack (MSP_NS) */
__TZ_set_MSP_NS((*(uint32_t *)VTOR_TABLE_NS_START_ADDR));
/* Get non-secure reset handler */
NonSecure_ResetHandler = (funcptr_NS)(*((uint32_t *)((VTOR_TABLE_NS_START_ADDR) + 4U)));
/* Start non-secure state software application */
NonSecure_ResetHandler();
}
static void MX_GTZC_S_Init(void)
{
MPCBB_ConfigTypeDef MPCBB_Area_Desc = {0};
/* USER CODE BEGIN GTZC_S_Init 1 */
/* USER CODE END GTZC_S_Init 1 */
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_USART3, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_UCPD1, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_USB, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_LPUART1, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_I2C3, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_ETHERNET, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
if (HAL_GTZC_TZSC_ConfigPeriphAttributes(GTZC_PERIPH_ADC12, GTZC_TZSC_PERIPH_SEC|GTZC_TZSC_PERIPH_NPRIV) != HAL_OK)
{
Error_Handler();
}
MPCBB_Area_Desc.SecureRWIllegalMode = GTZC_MPCBB_SRWILADIS_ENABLE;
MPCBB_Area_Desc.InvertSecureState = GTZC_MPCBB_INVSECSTATE_NOT_INVERTED;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[0] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[1] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[2] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[3] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[4] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[5] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[6] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[7] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[8] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[9] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[10] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[11] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[12] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[13] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[14] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[15] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[16] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[17] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[18] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[19] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[0] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[1] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[2] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[3] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[4] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[5] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[6] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[7] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[8] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[9] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[10] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[11] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[12] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[13] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[14] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[15] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[16] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[17] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[18] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[19] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_LockConfig_array[0] = 0x00000000;
if (HAL_GTZC_MPCBB_ConfigMem(SRAM3_BASE, &MPCBB_Area_Desc) != HAL_OK)
{
Error_Handler();
}
}
Hi
I am trying to launch debug for TrustZone enabled setup but when NonSecure_Init() function hit in secure region instead of jumping into Nonsecure region . it's giving hardfault handler.
Also can I know what are the configuration settings to be done in STM32CubeProgrammer for my application to run in both secure and non secure correctly.
I suspect the issue seems to be because of settings in STM32cubeprogrammer.
Can anyone help me configure correct memory allocation and settings to be done for TrustZone enaled secure-NonSecure to work without trouble.
Thank You.
Solved! Go to Solution.
2024-04-03 04:15 AM
Hello @Riya and welcome to the community,
The problem of the NonSecure_Init() function hitting the secure region instead of jumping to the non-secure region is due to improper memory allocation of secure and non-secure.
According to your configuration, it looks like both your banks are configured as secure. Try to change this:
SECWM2_START value = 0x01
SECWM2_END value = 0x00
apply and save and try to debug.
Check your jump address in the secure firmware, it should be the start of your bank 2 address 0x08100000UL, which is not the case as your CubeProgrammer configuration is for bank 2.
Hope this helps!
Thanks,
Rim.
2024-04-03 04:15 AM
Hello @Riya and welcome to the community,
The problem of the NonSecure_Init() function hitting the secure region instead of jumping to the non-secure region is due to improper memory allocation of secure and non-secure.
According to your configuration, it looks like both your banks are configured as secure. Try to change this:
SECWM2_START value = 0x01
SECWM2_END value = 0x00
apply and save and try to debug.
Check your jump address in the secure firmware, it should be the start of your bank 2 address 0x08100000UL, which is not the case as your CubeProgrammer configuration is for bank 2.
Hope this helps!
Thanks,
Rim.
2024-04-03 04:31 AM
Hi @Rim LANDOLSI ,
Thank you for replying to my post !
The above solution resolved my Hardfault in NonSecure_Init issue ,but in Non secure region I have configured for FreeRtos.
It's going to the infinite loop in function prvInitialiseNewTask().
Can you please help me resolve this issue.
I have attached my linker file for secure and non secure in .c format.
Thank You.
2024-04-04 03:25 AM
Hi @Riya ,
Glad to hear this has solved the problem.
Could you provide the FreeRTOS task configuration you have created?
Thank you.
2024-04-04 04:33 AM
Thank you for replying to my post !
I am attaching my FreeRtosConfig.h file of Non-secure region.