This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PSP/MSP Stack pointer switching implementation

Hi, I am using a NXP S32K118 Cortex M0+ processor 

I have a scheduler function used to call different tasks ( all is time scheduled ) and i need to do the following:

-> Use the main stack pointer (MSP) for this scheduler function

-> Use the process stack pointer (PSP) for the scheduled tasks

I have 3 stacks defined in ram ( main stack, secondary stack 1, secondary stack 2 ). The idea is that the scheduler uses the main stack, and the scheduled tasks use the secondary stack 1 or secondary stack 2, so i need to switch from MSP to PSP when i´m in the scheduer, before calling the corresponding task, and switch back from PSP to MSP once the corresponding task is completed and im back on the scheduler.

I know how to switch these pointers writing to PSP/MSP/CONTROL registers, but the problem I have is i dont know how to do this context switch/ what i need to do in addition of simply changing stack pointers in order to keep all the stacks working properly, so im here just finding for any help/tips if anyone knows how to implement this properly.

Thank you! :)