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

How and when to use separate stack pointers in a non-RTOS application?

Hi,

We are developing a safety critical product based on Cortex-M4 CPU. In the Definitive Guide for ARM Cortex-M3/4 I read that it is recommended to use both (MSP and SPS) stacks even, if program does not use RTOS. By using both stacks, the program is supposed to be more robust. I also see in the book how this should be implemented in the startup file, but I don't understand in which cases these separate stacks would be more beneficial than just one stack (MSP).

I would be very grateful, if someone could explain this a little bit.

Best regards.

Parents
  • Hi matic,


    if programs are running on PSP, the stack pointer will switch to MSP when interrupt or exception occurs. This means that an interrupt stack (i.e. MSP) will be protected from a user stack (i.e. PSP) even if the user stack may be overflowed. Don't you think it will be a benefit?
    Also important registers such as r0 to r3, r14 (lr), r15 (pc) and xPSR are pushed on PSP stack. This would be useful for context switching. In the case of no RTOS, it will also work like a register bank.

    Best regards,
    Yasuhiko Koumoto.

Reply
  • Hi matic,


    if programs are running on PSP, the stack pointer will switch to MSP when interrupt or exception occurs. This means that an interrupt stack (i.e. MSP) will be protected from a user stack (i.e. PSP) even if the user stack may be overflowed. Don't you think it will be a benefit?
    Also important registers such as r0 to r3, r14 (lr), r15 (pc) and xPSR are pushed on PSP stack. This would be useful for context switching. In the case of no RTOS, it will also work like a register bank.

    Best regards,
    Yasuhiko Koumoto.

Children