This crate provides helper functions for stack analysis on AVR microcontrollers.
This crate provides two main items:
init_stack_pattern!(): A macro to initialize the stack
with a known pattern. This must be called once in your application’s
main crate.estimate_unused_stack_space(): A function that returns
an estimate of the number of unused bytes on the stack.Cargo.toml[dependencies]
avr_stack = "1"
avr_device = { version = "0.8", features = [ "atmega328p", "rt", "critical-section" ] }#[avr_device::entry]
fn main() -> ! {
loop {
// ...
let nr_unused_stack_bytes = avr_stack::estimate_unused_stack_space();
// ...
}
}
avr_stack::init_stack_pattern!();The init_stack_pattern! macro defines a function that
runs in the .init4 section of the AVR’s program memory.
This function executes before main and fills the entire
stack with a pattern.
The estimate_unused_stack_space() function then walks
the stack from its end towards its beginning, counting the number of
bytes that still contain the initialization pattern. This provides an
estimate of how much stack space has never been touched.
This project is licensed under either:
at your option.
Copyright (C) 2025 - 2026 Michael Büsch m@bues.ch