28
CHAPTER 5
Task stack for Cortex-M
5.1 Task stack for Cortex-M
Each task uses its individual stack. The stack pointer is initialized and set every time a task
is activated by the scheduler. The stack-size required for a task is the sum of the stack-
size of all routines, plus a basic stack size, plus size used by exceptions.
The basic stack size is the size of memory required to store the registers of the CPU plus
the stack size required by calling embOS-routines.
For the Cortex-M CPUs, this minimum basic task stack size is about 112 bytes. Because any
function call uses some amount of stack and every exception also pushes at least 32 bytes
onto the current stack, the task stack size has to be large enough to handle one exception
too. For privileged tasks, we recommend at least 512 bytes stack as a start. Unprivileged
tasks will require an additional 128 bytes of task stack.
5.2 System stack for Cortex-M
The embOS system executes in thread mode, the scheduler executes in handler mode.
The minimum system stack size required by embOS is about 160 bytes (stack check &
profiling build). However, since the system stack is also used by the application before
the start of multitasking (the call to
OS_Start()
), and because softwaretimers and C-level
interrupt handlers also use the system-stack, the actual stack requirements depend on the
application.
The size of the system stack can be changed by modifying the project settings. We recom-
mend a minimum stack size of 256 bytes for the
CSTACK
.
5.3 Interrupt stack for Cortex-M
If a normal hardware exception occurs, the Cortex-M core switches to handler mode which
uses the main stack pointer. With embOS, the main stack pointer is initialized to use the
CSTACK
which is defined in the linker command file. The main stack is also used as stack by
the embOS scheduler and during idle times, when no task is ready to run and
OS_Idle()
is executed.
Note
When using an embOS Safe build, please note that the stack-check-limit is config-
urable through
OS_STACK_SetCheckLimit()
and by default is configured at 70 percent
of the total stack size. This will impact the minimum size requirement for both task
stacks and the
CSTACK
.
embOS-MPU for Cortex-M and IAR
© 2010-2020 SEGGER Microcontroller GmbH