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

Use case of MSP and PSP in Cortex M

Hi Experts,

What is the key difference between Master Stack pointer and the Process stack pointer and how an OS can take advantage of it ?

Parents
  • HI,

    Having two separate stack pointers allows the operating system to be safer and more robust. Usually, you would configure the operating system toy use Main Stack Pointer (MSP) and user applications to use Process Stack Pointer (PSP). The switch from one stack to another then happens automatically when an exception is handled.

    The fact that the operating system and exception handlers use a different stack from the application means that the OS can protect its stack and prevent applications from accessing or corrupting it. You can also ensure that the OS does not run out of stack if the application consumes all the available PSP stack space - that means that there is always space on the stack to run an exception handler in the case of an error occurring.

    Note that you don't have to use both stack pointers. By default, the system will only use a single stack pointer (MSP) and must be manually configured to use PSP. Also, some Cortex-M microcontrollers do not support two stack pointers.

    Hope this helps.

    Chris

Reply
  • HI,

    Having two separate stack pointers allows the operating system to be safer and more robust. Usually, you would configure the operating system toy use Main Stack Pointer (MSP) and user applications to use Process Stack Pointer (PSP). The switch from one stack to another then happens automatically when an exception is handled.

    The fact that the operating system and exception handlers use a different stack from the application means that the OS can protect its stack and prevent applications from accessing or corrupting it. You can also ensure that the OS does not run out of stack if the application consumes all the available PSP stack space - that means that there is always space on the stack to run an exception handler in the case of an error occurring.

    Note that you don't have to use both stack pointers. By default, the system will only use a single stack pointer (MSP) and must be manually configured to use PSP. Also, some Cortex-M microcontrollers do not support two stack pointers.

    Hope this helps.

    Chris

Children
No data