Embedded systems often include bugs developers have a hard time to find. One common cause of such tricky bugs are stacks that grow beyond their dedicated memory area, thus causing unpredictable behavior and a malfunctioning system.
This is because the stack can overwrite important variable values, that thus inadvertently get the wrong value. Alternatively, a variable overwrite the stack, as the stack has expanded into the memory area dedicated to that variable. Upon the next function call return, the software crashes as it returns to the wrong location (the return address is stored on the overwritten stack and execution continues on a random location). Due to these reasons, stack related bugs often appear to be completely random, in most cases making them incredibly difficult to find.
If you use an RTOS running parallel tasks, these problems can multiply. Each task has its own stack, and with more tasks, you get more stacks that can cause stack related bugs. The stack depth analyzer in TrueSTUDIO Pro can help resolve such problems and help develop more robust systems. Read this blog post to learn more on analyzing the stack usage on Cortex-M systems developed with the GNU GCC compiler in TrueSTUDIO!