Call stack
This section will explain what a call stack is, how it works on the Arm Cortex-M, and how it can be utilized for debugging.
What is a call stack?
To understand what a call stack is, we first need to understand how a stack works on microcontrollers. A stack is a data structure that operates in a last in, first out (LIFO) fashion. It is located in RAM and grows "backward" on the Arm Cortex-M architecture. That means that the initial top of the stack address will be higher than the top of the stack address of a filled stack.
The standard operations to add or remove data from the stack are called push and pop. On a microcontroller, the stack is mostly used to track function calls, local variables, and interrupt context handling.
A call stack is a visual representation of the function call order that was stored on the stack. On each function call, the function return address and optionally other CPU register values are stored on the stack, the so-called stack frame.
If...