Understand and monitor the stack for system reliability
Nov 2, 2021
The stack is a fixed block of continuous memory and has to be allocated statically by the developer. It can contain interrupt contexts and local data like variables and parameters for C/C++ functions, which are not stored in registers among other information. The main advantage of stack is that functions in different parts of the application can share the same memory space to store their data.
A proper configuration of the stack is essential to your system stability and reliability. If the stack size is too small, an overflow situation could occur. On the other hand, setting the stack size too large means a waste of RAM resource, which could be very limited in MCU-based embedded systems. The handling of the stack is one of the major challenges for embedded software developers. A good practice is to employ static stack usage analysis and runtime stack usage tracking.
On top, it is recommended to take advantage of guarding against stack overflow with the use of stack canaries (stack protection).