In this article, we will take a look at the stack usage analysis functionality available in the IAR Embedded Workbench and introduce some techniques on how to calculate the maximum stack usage of your application at building time, as well as track the signs of stack pointer at runtime.
Background
The stack is a fixed block of continuous memory and has to be allocated statically by the developer. It contains local data for C/C++ functions, e.g.:
Local variables which are not stored in registers
Function parameters which are not stored in registers
Temporary result of expressions
The return value of a function (unless it is passed through registers)
Interrupt contexts
Processor registers that should be restored before the function returns
A stack can be divided into two parts. The first part contains allocated memory used by functions and the second part contains free memory that can be allocated.…