I am porting FreeRTOS with TrustZone on LPC5500, I put FreeRTOS in secure memory, and created several user tasks in non-secure memory, as shown below:
But so far, I have not successfully switched from a secure task to a non-secure task.
How to switch from a secure task to a non-secure task?
- Non-secure task use PSP_NS (pointing to return stack for the Non-secure task)
- At the beginning of the Non-secure task, FPCA was 0 (no floating point context at start)
You can return from Secure handler to Non-secure thread with a EXC_RETURN code of 0xFFFFFFBD.
However, with the guidance from PSA & Trusted Firmware team, the plan for FreeRTOS port is to have the OS running in Non-secure world, and OS helper APIs in Secure world to help context switching.
Thank you for your answer, but after I change the value of r14 (EXC_RETURN) from 0XFFFFFFFD to 0XFFFFFFBD in the PendSV interrupt, when the "bx r14" is executed, the program enters the hardfault state, it seems 0XFFFFFFBD is an illegal EXC_RETURN value?
There could be different causes for the HardFault:
- is the PSP_NS set correctly to Non-secure memory?
- what is in the stack frame? Was the stacked xPSR correct? (T bit set and IPSR=0)
- Is the PC value really pointing to Non-secure memory?
- what is showing in the fault status registers?
1) The psp_ns set to Non-secure memory.
2) The stack frame is standard stack frame , the value of the xPSR seems to be incorrect(T bit set , IPSR=3)
3) In PendSV interrupt, the PC is pointing Secure memory, new PC value is stored in the non-secure task stack and the new PC will point Non-secure memory.
4) The value of the fault status registers are shown as following:
Can you help me analyze the cause of the HardFault?
Regarding stack frame, sorry for not clear. I meant the stack frame you created in Non-secure stack for the exception return to take place. What is in that stack frame?
In Non-secure task stack：
The stack frame as following:
What is the value in the xPSR you put in for that stack frame?
The value of xPSR in stack frame is 0x01000000.
Thanks. That's look correct.
There is nothing flagged up the in FSR values you shown:
DFSR:0X00000001 - Halted bit is set
HFSR:0X40000000 - there is an escalated exception
But none of the other FSR is set which is a bit strange.
In your Non-secure code, the diagram showing that you are using printf. Have the C startup for the Non-secure work been executed? What happen if you replace that Non-secure task with just simple LED toggling?
Thank you for your answer, https://xender.vip/ https://discord.software/ https://omegle.onl/ but after I change the value of r14 (EXC_RETURN) from 0XFFFFFFFD to 0XFFFFFFBD in the PendSV interrupt, when the "bx r14" is executed, the program enters the hardfault state, it seems 0XFFFFFFBD is an illegal EXC_RETURN value?