CMSIS-RTOS RTX  Version 4.51
CMSIS-RTOS RTX: Real-Time Operating System for Cortex-M processor-based devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Thread Stack and Processor Mode

The CMSIS-RTOS RTX provides several parameters for the thread configuration.

Configuration of Thread Stack Space

The osThreadDef defines a thread function. The parameter stacksz specifies thereby the stack requirements of this thread function. CMSIS-RTOS RTX defines two methods for defining the stack requirements:

  • when stacksz is 0, a fixed-size memory pool is used to for the thread stack. In this case OS_STKSIZE specifies the stack size for the thread function.
  • when stacksz is not 0, the thread stack is allocated from a user space. The size of this user space is specified with OS_PRIVSTKSIZE.

The following #defines specify the stack for thread execution:

  • #define OS_TASKCNT indicates the number of threads that allocate the stack from the fixed size memory pool when osThreadDef stacksz = 0.
  • #define OS_STKSIZE specifies the default stack size (in words) for threads that are defined with osThreadDef stacksz = 0.
  • #define OS_MAINSTKSIZE is the stack requirement (in words) for the main function that is started by default as an RTOS thread.
  • #define OS_PRIVCNT indicates the number of threads that are defined with osThreadDef stacksz != 0. stacksz specifies the stack size requirement of that thread.
  • #define OS_PRIVSTKSIZE is the combined stack requirement (in words) of all threads that are defined with with osThreadDef stacksz != 0.

Stack Overflow Checking

CMSIS-RTOS RTX implements a software stack overflow checking that traps stack overruns. Stack is used for return addresses and automatic variables and extensive usage or incorrect stack configuration may cause a stack overflow. Software stack overflow checking is controlled with the #define OS_STKCHECK.

If a stack overflow is detected, the function os_error with error code = 1 is called. By default, this function is implemented as endless loop and will practically stop code execution.

Processor Mode for Thread Execution

CMSIS-RTOS RTX allows to execute threads in unprivileged or privileged processor mode. The processor mode is controlled with the #define OS_RUNPRIV.

In unprivileged processor mode, the software:

  • has limited access to the MSR and MRS instructions, and cannot use the CPS instruction.
  • cannot access the system timer, NVIC, or system control block.
  • might have restricted access to memory or peripherals.

In privileged processor mode the software can use all the instructions and has access to all resources.

Note
It is recommended to use the privileged processor mode.