| CMSIS-RTOS RTX Version 4.75 CMSIS-RTOS RTX: Real-Time Operating System for Cortex-M processor-based devices

- RTX

- Main Page
- Usage and Description
- Reference

Thread Configuration

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

- Configuration of Thread count and Stack Space
- Stack Overflow Checking
- Processor Mode for Thread Execution

# Configuration of Thread count and Stack Space

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 thread count and stack for thread execution:

- #define OS_TASKCNT indicates the maximum number of threads that will run at the same time (including main).
- #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 (excluding main). 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 (excluding main).

# 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.