This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

two seperate call stacks with MSP and PSP

Hello,

I intended to implement an application without OS. Due to safety concerns I would like to have two call stacks : one for softdevice using MSP and the other for my application using PSP.

Is there an example for how to do this ?

Regards,

Parents
  • Hi telemedcar, Like butch said, compiler takes care of this stuff and thinking about this is normally done by people implementing an Operating system. That said, it is quite simple to select stack pointer for an application. Exception handlers always use MSP. So if the application is making SVC call or for any application peripheral specific IRQs, only MSP will be used. For thread mode you can control which stack pointer to use by writing to Control Register. If you initialize the control register quite early in your application, then when exception occur (softdevice always run in exception handlers) proper EXEC_RETURN will be pushed to the stack to mark that when it returns to thread mode then it should pop stack pointer value to PSP . Look at table 2.17. One you have selected PSP in control register and initialized it proper value at the start of the application, then compilers and ARM core will handle the rest.

  • The processor is in Thread mode when it is reset (That is executing its reset handler).

    You can do the following

    __set_CONTROL(__get_CONTROL | CONTROL_nPRIV_Msk );
    

    you can initialize PSP using MSR command like below Once you have selected in the Control register that you CONTROL-nPRIV = 1;

    "msr   psp, r0\t\n" 
    

    The value you put in this psp should not conflict with your linker so make sure you configure your linker correctly.

    That is all you need to do for your application to use PSP when in Thread mode and the rest of the system will use MSP (assuming you are not using any RTOS, otherwise RTOS will redefine this for you).

Reply
  • The processor is in Thread mode when it is reset (That is executing its reset handler).

    You can do the following

    __set_CONTROL(__get_CONTROL | CONTROL_nPRIV_Msk );
    

    you can initialize PSP using MSR command like below Once you have selected in the Control register that you CONTROL-nPRIV = 1;

    "msr   psp, r0\t\n" 
    

    The value you put in this psp should not conflict with your linker so make sure you configure your linker correctly.

    That is all you need to do for your application to use PSP when in Thread mode and the rest of the system will use MSP (assuming you are not using any RTOS, otherwise RTOS will redefine this for you).

Children
No Data
Related