In an RTOS like RT or NIL there are several dedicated stacks, each stack has a dedicated RAM space that must have a correctly sized assigned area.
There are several stacks in the systems, some are always present, some others are present only in some architectures:
main()function and the thread that executes it. It is not a normal thread stack because it is initialized in the startup code and its size is defined in a port dependent way. Details are in the various ports documentation.
The most critical thing when writing an embedded multithreaded application is to determine the correct stack size for main, threads and, when present, interrupts. Assigning too much space to a stack is a waste of RAM, assigning too little space leads to crashes or, worst scenario, hard to track instability.
You may try to examine the asm listings in order to calculate the exact stack requirements but this requires much time, experience and patience. An alternative way is to use an interactive method. Follow this procedure for each thread in the system:
CH_DBG_ENABLE_STACK_CHECK, this option enables a stack check before context switches. This option halts the system in
chSysHalt()just before a stack overflow happens.
CH_DBG_FILL_THREADS, this option fills the threads working area with an easily recognizable pattern (0x55).
sscanf() for example, can take a lot of space.
Note that ChibiStudio includes a debug plugin capable of calculating the remaining space in each stack automatically.
Some useful info:
chcore.h) is included in the total working area size by the system macros
PORT_INT_REQUIRED_STACKdefault value. Architectures with a dedicated interrupt stack do not require changes to this value. Resizing of the global interrupt stack may be required instead.