Stack Size Estimator — worst-case depth
Estimate worst-case stack depth from call nesting, locals and interrupt frames.
Example: A worst case of about 832 bytes suggests allocating 1248 bytes of stack at a 1.5× margin.
Check it against real silicon
Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.
Formula
stack = deepest call chain + interrupt frames + marginWorked example
A worst case of about 832 bytes suggests allocating 1248 bytes of stack at a 1.5× margin.
call tree = depth × frame + largest buffer
8 × 48 + 256
640 bytes
interrupts = nesting × frame
2 × 96
192 bytes
Interrupts stack on top of the deepest point of the call tree, not beside it.
recommended = (call tree + interrupts) × margin
832 × 1.5
1248 bytes
Frequently asked questions
How much stack does an embedded application need?
It depends entirely on the deepest call chain and the largest local buffers in it. A simple bare-metal loop might need 512 bytes; anything using printf, a filesystem or a network stack can need several kilobytes. Estimate first, then measure.
Why do interrupt frames matter so much?
Because an interrupt can arrive at the deepest point of your call tree, and its frame stacks on top. Nested interrupts add more. Sizing for the call tree alone works on the bench and overflows in the field, when an interrupt happens to land at the wrong moment.
How do I measure actual stack usage?
Fill the stack region with a known pattern at boot, run the firmware through its heaviest workload, then look for the highest address still holding the pattern. That high-water mark is your real peak. GCC's -fstack-usage plus a call-graph analyser gives a static bound too.
What happens when the stack overflows?
Usually nothing obvious at first. It writes past its allocated region into whatever is next in RAM — commonly globals — and the corruption surfaces later somewhere unrelated. That is why an MPU guard region or a stack canary is worth the setup cost.
Related tools
C Struct Padding Calculator
Paste a C struct to see member offsets, inserted padding and total size for 32-bit and 64-bit targets — and how to reorder it smaller.
Firmware
Interrupt Latency Calculator
Worst-case interrupt response from clock speed, cycle counts and priority nesting.
Firmware
Flash & EEPROM Endurance Calculator
How long your flash survives at a given write rate, and how much wear levelling buys you.
Firmware
Hex, Binary & Decimal Converter
Convert between hex, binary, decimal, octal and ASCII, with width-aware bit grids and endianness swapping.
Firmware
Bitwise Operation Calculator
AND, OR, XOR, NOT and shifts with a live bit grid so you can see exactly which bits moved.
Firmware
CRC Calculator
CRC-8, CRC-16 (CCITT, Modbus, XMODEM) and CRC-32 over hex or ASCII input, with the polynomial and shift steps explained.
Firmware