2025-12-02 10:01 AM
I've been struggling with this problem for several hours.
I would assume this is related to the thread stack.
I am using the following:
In the secure project is secure_nsc.c, I define my API:
CMSE_NS_ENTRY void ToggleBackLight(void)
{
HAL_GPIO_TogglePin(BACKLIGHT_GPIO_Port, BACKLIGHT_Pin);
}In the non-secure project, I invoke this from a thread as follows:
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
typedef void (*SecureFunc_t)(void) __attribute__((cmse_nonsecure_call));
void doBlinkyThread(void *argument)
{
/* USER CODE BEGIN defaultTask */
SecureFunc_t secure_func = (SecureFunc_t)ToggleBackLight; // from veneer table
/* Infinite loop */
for(;;)
{
secure_func();
osDelay(500);
}
/* USER CODE END defaultTask */
}
/* USER CODE END Application */Notes:
I've used Cube MX to generate the thread-initialisation code, as shown below:
/* Definitions for blinkyThread */
osThreadId_t blinkyThreadHandle;
uint32_t MyBufferTask02[ 256 ];
osStaticThreadDef_t MycontrolBlocTask02;
const osThreadAttr_t blinkyThread_attributes = {
.name = "blinkyThread",
.stack_mem = &MyBufferTask02[0],
.stack_size = sizeof(MyBufferTask02),
.cb_mem = &MycontrolBlocTask02,
.cb_size = sizeof(MycontrolBlocTask02),
.priority = (osPriority_t) osPriorityRealtime7,
};
...
/* creation of blinkyThread */
blinkyThreadHandle = osThreadNew(doBlinkyThread, NULL, &blinkyThread_attributes);I note that there is nothing in the attribute structure to make this TrustZone (see below). I tried setting .tz_module=1 (as suggested in another forum post), but this did not solve it.
typedef struct {
const char *name; ///< name of the thread
uint32_t attr_bits; ///< attribute bits
void *cb_mem; ///< memory for control block
uint32_t cb_size; ///< size of provided memory for control block
void *stack_mem; ///< memory for stack
uint32_t stack_size; ///< size of stack
osPriority_t priority; ///< initial thread priority (default: osPriorityNormal)
TZ_ModuleId_t tz_module; ///< TrustZone module identifier
uint32_t reserved; ///< reserved (must be 0)
} osThreadAttr_t;I also noted a warning:
warning: 'cmse_nonsecure_call' attribute ignored without '-mcmse' option [-Wattributes]
So, in addition to the above, I added this parameter to the compiler (on both sides), and the warning went away, but I still get the hard fault.
When I find myself having to mess with MX generated code and settings, it suggests I've missed something in Cube MX?