A stack holds temporary execution state in last-in, first-out order. In bare-metal Rust, it stores function arguments, local variables, return addresses, and register frames saved on exception entry. Each function’s frame is cleaned up automatically when the function returns. section 7.1.1
The stack occupies a bounded region of RAM. As functions are called, the stack pointer moves down; as they return, it moves back up. Allocation and cleanup are fast, but available RAM is limited. A recursive function can exhaust the stack and silently corrupt static data. section 7.1.1 section 7.0
SECTIONS
{
.vector_table :
{
LONG(ORIGIN(RAM) + LENGTH(RAM)); /* Initial stack pointer (
top of RAM) */
KEEP(*(.vector_table.reset_vector)) /* Reset vector (
entry point) */
KEEP(*(.vector_table.exceptions)) /* Other exceptions and
interrupts */
} > FLASH
This linker-script fragment places the initial stack pointer at the end of RAM as the first Cortex-M vector-table entry. The next entry identifies the reset handler. section 4.1.3
Unlike stack frames, static data persists for the program’s lifetime. The heap supports data with runtime-dependent size or lifetime, but in no_std firmware it requires an explicitly reserved RAM region and allocator. Fixed-capacity containers from heapless or arrayvec offer heap-free alternatives. section 7.1.1 section 7.5
Keep stack usage within the available RAM, especially when using recursion or large local data. Tools and protections include cargo-call-stack, emitted stack sizes, flip-link, software canaries, and MPU guard regions. section 7.0
















