Hello,
I am currently using the LPC55S16EVK board and developing a small program using TrustZone and ThreadX. I am running using the hello_world_s example from the SDK version 2.15 and I am adding ThreadX component into the hello_world_ns application. I have added the TX_SINGLE_MODE_NON_SECURE flag in the Preprocessor of the mentioned project. My main file for the secure world only performs a call to Normal World, while the non-secure main file is shown here:
/*
* Copyright 2018 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "veneer_table.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "fsl_power.h"
#include "tx_api.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define DEMO_STACK_SIZE 1024
#define DEMO_BYTE_POOL_SIZE 9120
#define DEMO_BLOCK_POOL_SIZE 100
#define DEMO_QUEUE_SIZE 100
#define PRINTF_NSE DbgConsole_Printf_NSE
/*******************************************************************************
* Prototypes
******************************************************************************/
TX_THREAD my_thread;
void my_thread_fnc(ULONG thread_input);
/* memory pool */
char mem_pool[DEMO_BYTE_POOL_SIZE];
TX_BYTE_POOL byte_pool_0;
/*******************************************************************************
* Code
******************************************************************************/
void SystemInit(void)
{
}
/*!
* @brief Main function
*/
int main(void)
{
int result;
/* set BOD VBAT level to 1.65V */
POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
PRINTF_NSE("Welcome in normal world!\r\n");
tx_kernel_enter();
return 0;
}
void tx_application_define(VOID *first_unused_memory)
{
int ret = 0xFF;
CHAR *pointer = TX_NULL;
TX_THREAD_NOT_USED(first_unused_memory);
/* Create a byte memory pool from which to allocate the thread stacks. */
tx_byte_pool_create(&byte_pool_0, "byte pool 0", (VOID *)mem_pool, DEMO_BYTE_POOL_SIZE);
/* Allocate the stack for thread 0. */
tx_byte_allocate(&byte_pool_0, (VOID **)&pointer, DEMO_STACK_SIZE, TX_NO_WAIT);
/* Create the main thread. */
ret = tx_thread_create(&my_thread, "thread 0", my_thread_fnc, 0, pointer, DEMO_STACK_SIZE, 1, 1, TX_NO_TIME_SLICE,
TX_AUTO_START);
/* Release the block back to the pool. */
tx_block_release(pointer);
}
void my_thread_fnc(ULONG thread_input)
{
PRINTF_NSE("Thread 0 started...\r\n");
while(1)
{
tx_thread_sleep(10);
}
}
After starting the kernel and the task (ret value inside tx_application_define returns correctly), it triggers an HardFault on the instruction shown below:
The BX lr instruction crashes the system as the Link Registers shows an invalid memory value.
Any help would be appreciated.
I attached the TrustZone config file.
Kind regards,
Rui
I was able to get ThreadX runnig on non-secure world by adding the SDK ThreadX folder into a VSCode generated hello_word TrustZone project. I added ThreadX on both secure and non-secure apps and added the macro TX_SINGLE_MODE_SECURE on the secure app and TX_SINGLE_MODE_NON_SECURE on the non-secure app.
Althrough it seems to work correctly I am not sure if this configuration is correct.
Furhter testing shows that LR does not present invalid values. The call for _tx_thread_shell_entry when a thread is ready to run triggers an HardFault_Handler