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 Stack Pointer, what memory address does it point to?

In the ARM Cortex M4, If the PSP stack pointer is configured, what address space does it point to?  Is it the same address space as the MSP (main stack pointer)? Or do we create a new and separate stack for it?  And how do we configure the TOP of stack for the PSP pointer?

Parents
  • One use model is for PSP to be used as the private stack for each thread, while MSP is retained as the stack for the RTOS kernel and all subsequent nested exceptions.

    For each thread that executes, there would be a reserved area of memory for it to use as a stack (your toolchain may be able to tell you how much is required for a given program), and at thread initialisation time, the kernel would set the SP for that thread to the top of this area.

    Context switching of the thread would then involve preserving the outgoing and restoring the incoming versions of the non-automatically store registers and the PSP.

    Another dedicated (potentially larger) memory space would be reserved for the exception handlers (which if nested can consume considerable memory space), and the MSP set to this (likely via the automatic assignment at reset time).

    It is very unlikely that having the PSP and MSP set to the same or overlapping values is useful.

    If you are using separate PSP and MSP, then you may also want to consider using the memory protection unit, and restricting what regions are accessible for threads vs handlers.

    hth

    Simon.

Reply
  • One use model is for PSP to be used as the private stack for each thread, while MSP is retained as the stack for the RTOS kernel and all subsequent nested exceptions.

    For each thread that executes, there would be a reserved area of memory for it to use as a stack (your toolchain may be able to tell you how much is required for a given program), and at thread initialisation time, the kernel would set the SP for that thread to the top of this area.

    Context switching of the thread would then involve preserving the outgoing and restoring the incoming versions of the non-automatically store registers and the PSP.

    Another dedicated (potentially larger) memory space would be reserved for the exception handlers (which if nested can consume considerable memory space), and the MSP set to this (likely via the automatic assignment at reset time).

    It is very unlikely that having the PSP and MSP set to the same or overlapping values is useful.

    If you are using separate PSP and MSP, then you may also want to consider using the memory protection unit, and restricting what regions are accessible for threads vs handlers.

    hth

    Simon.

Children