softdevice use precludes manual MSP?

i'm using the nRF52840 with a custom micro-kernel designed to support user-space applications with multi-tasking.  multi-tasking is implemented using separate stack space for each of multiple threads, which means we're manually changing PSP and MSP to isolate and preserve stack contents.  from reading the S140_SDS_v2.1 SoftDevice documentation, i encountered the statement

> Do not change the value of MSP dynamically (i.e. never set the MSP register directly)

but there is nothing else in the documentation that explains why not.  Does this mean that our micro-kernel cannot be used with the softDevice?  it's seems odd that the SD cannot work in multi-threaded / multi-tasked environments, since this is done in the vast majority of embedded OSs.  I would appreciate any clarification of this requirement.

  • Hi,

    There are more info here: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsds_s140%2FSDS%2Fs1xx%2Fmem_usage%2Fmem_resource_reqs.html

    "
    By default, the nRF52 System on Chip (SoC) will have a shared call stack with both application stack frames and SoftDevice stack frames, managed by the Main Stack Pointer (MSP).

    The application configures the call stack, and the MSP gets initialized on reset to the address specified by the application vector table entry 0. In its reset vector the application may configure the CPU to use the Process Stack Pointer (PSP) in thread mode. This configuration is optional but may be required by an OS, for example, to isolate application threads and OS context memory. The application programmer must be aware that the SoftDevice will use the MSP as it is always executed in exception mode.

    "

    and,

    > Do not change the value of MSP dynamically (i.e. never set the MSP register directly)

    Above this statement we also have:

    "The location of the call stack is communicated to the SoftDevice through the contents of the Main Stack Pointer (MSP) register. " 

  • thank you. i've already read all of the documentation, but I cannot understand why the MSP cannot be changed by the kernel to support context-switching among user-space threads.  it should not be an issue, since all interaction would be done with the softdevice through system calls, but our kernel still changes the MSP per thread.  i still could not get a sense from the documentation of _why_ the MSP cannot be changed.  do i just need to try to incorporate the SD and see if it works or not?

Related