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 software cannot set Secure PSP. Given that in your arrangement your RTOS is in Secure side, when you create the task you can allocate the Secure stack for it at the same time.
The context switching code (in Secure privileged side) can set the PSP_S.
I understand what you said, I wiil try it.
Thanks a lot.
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?
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?
Sorry for delay. I must have missed the notification email (too many emails).
A task (assume Non-secure unprivileged) can update SP (R13), and if the current selected SP is PSP, then it is updating PSP_NS.
But normally in an RTOS environment, the initial value of PSP_NS is initialized by the OS (not by the task itself) before the Non-secure task starts.
Sorry for the delay - my workload recently has been crazy.
0XFFFFFFBD is not illegal, but it depends on several requirements:
- Returning from Secure handler to Non-secure thread
- Non-secure world was using PSP_NS (SPSEL_NS=1 before the exception)
- Secure world's thread was using PSP_S (SPSEL_S=1 before the exception)
- FPU was inactive (CONTROL.FPCA=0 before the exception)
View all questions in TrustZone for Armv8-M forum