2024-10-29 03:14 AM - edited 2024-10-29 03:14 AM
Hello,
I am using the STM32U575ZIT6 microcontroller and have created a simple TrustZone project where all applications run in the non-secure zone. However, when the program attempts to switch to the non-secure zone, it triggers a hard fault handler error, showing the message "no signal source available for 0xfffffff9." I have configured the secure zone as follows:
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* Non-secure Vector table to jump to (internal Flash Bank2 here) */
/* Caution: address must correspond to non-secure internal Flash where is */
/* mapped in the non-secure vector table */
#define VTOR_TABLE_NS_START_ADDR 0x08100000UL
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
static void NonSecure_Init(void);
static void MX_GTZC_S_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* SAU/IDAU, FPU and interrupts secure/non-secure allocation setup done */
/* in SystemInit() based on partition_stm32u575xx.h file's definitions. */
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
SCB->SHCSR |= SCB_SHCSR_SECUREFAULTENA_Msk;
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* GTZC initialisation */
MX_GTZC_S_Init();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
HAL_GPIO_ConfigPinAttributes(GPIOA, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOB, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOC, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOD, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOE, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOF, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOG, GPIO_PIN_ALL, GPIO_PIN_NSEC);
HAL_GPIO_ConfigPinAttributes(GPIOH, GPIO_PIN_ALL, GPIO_PIN_NSEC);
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/*************** Setup and jump to non-secure *******************************/
NonSecure_Init();
/* Non-secure software does not return, this code is not executed */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief Non-secure call function
* This function is responsible for Non-secure initialization and switch
* to non-secure state
* @retval None
*/
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();
}
/**
* @brief GTZC_S Initialization Function
* None
* @retval None
*/
static void MX_GTZC_S_Init(void)
{
/* USER CODE BEGIN GTZC_S_Init 0 */
/* USER CODE END GTZC_S_Init 0 */
MPCBB_ConfigTypeDef MPCBB_Area_Desc = {0};
/* USER CODE BEGIN GTZC_S_Init 1 */
/* USER CODE END GTZC_S_Init 1 */
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_SecConfig_array[20] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[21] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[22] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[23] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[24] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[25] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[26] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[27] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[28] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[29] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[30] = 0x00000000;
MPCBB_Area_Desc.AttributeConfig.MPCBB_SecConfig_array[31] = 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_PrivConfig_array[20] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[21] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[22] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[23] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[24] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[25] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[26] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[27] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[28] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[29] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[30] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_PrivConfig_array[31] = 0xFFFFFFFF;
MPCBB_Area_Desc.AttributeConfig.MPCBB_LockConfig_array[0] = 0x00000000;
if (HAL_GTZC_MPCBB_ConfigMem(SRAM3_BASE, &MPCBB_Area_Desc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN GTZC_S_Init 2 */
/* USER CODE END GTZC_S_Init 2 */
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
2024-11-04 12:02 AM
Hello @Istillaga ,
have you set the flash watermark option byte ?
- SECWM1_PSTRT=0x0 SECWM1_PEND=0x7F meaning all 128 pages of Bank1 set as secure
- SECWM2_PSTRT=0x7F SECWM2_PEND=0x0 meaning all 128 pages of Bank2 set as non_secure
2024-11-04 12:38 AM
Yes, I have configured the flash byte watermark option but instead of 0x7f in SECWM2_PSTR I have set the value to 0x1
2024-11-04 02:15 AM
I would suggest to check code example provided in the CubeFW:
STM32Cube_FW_U5_V1.6.0\Projects\NUCLEO-U575ZI-Q\Examples\GPIO\GPIO_IOToggle_TrustZone
If you still faced an issue please share your complete project.