This Page

User

Stack problems

There is no stack checking on the Cortex-M families, so you have to be careful where you place the stack, program data, and the heap (e.g. malloc() space).

If you are using the standard (provided) linker scripts, the stack is placed at the top of RAM, program data is at the bottom on RAM, and the heap immediately after that.

If you are using a lot of stack, it can grow into the heap or even the program data space. If the stack has 'overflowed' into those spaces, when you write to the heap/program data it can overwrite values on the stack and thus corrupt it.

The stack is used for both your application AND any interrupts that may be firing (including nested interrupt), so you need to ensure there is enough space for the worst-case scenario.

Also, check that you are not allocating large amounts of data on the stack (e.g. allocating a local array, as this will be placed on the stack).