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,

  • Respectfully, I think you would get more discussion in a forum of an ARM website. Your question is about operating systems and this forum is mostly about radios. Also, see www.adamheinrich.com/.../. That says the NVIC automatically switches contexts (between the two stacks) for interrupts. It is not like the MSP is unused, available for you to use care free.

  • I am not saying that MSP is unused. My intention is to leave MSP to SoftDevice and handlers (ISRs and Exception). My user application would use PSP only. I will look at the link. Thanks.

  • Unless you are writing the OS yourself, I don't think you need to worry about it. For example, in my projects using C and with only one main thread and interrupt handlers, I don't worry about it. The compiler takes care of it without my knowing. I only know it happens because I can read the assembler code and see for example a MOVS instruction, where the "S" means it also switches context.

  • 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.

  • No the 'S' on MOVS means it updates the flags, it says nothing about switching context.

    @telemedcar, I've never used it myself but it really should be no more than adding an extra section to the linker file, or whatever you're using to generate sections, to be your process stack, and then edit the .s startup code to set both stack pointers, main to the main stack, process to the new sections and then set bit 1 in the CONTROL register which will move you to using PSP. I think that's everything which is needed.

    Should be 5 lines of assembler in the reset handler.

Related