avr-stack 1.0.0

Stack analysis for AVR
Documentation
  • Coverage
  • 100%
    4 out of 4 items documented0 out of 1 items with examples
  • Size
  • Source code size: 32.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 558.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • mbuesch/avr-stack
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mbuesch

Stack analysis for AVR

This crate provides helper functions for stack analysis on AVR microcontrollers.

  • Stack Usage Estimation: Estimate the amount of unused stack space.

Usage

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.

Example Cargo.toml

[dependencies]
avr_stack = "1"
avr_device = { version = "0.8", features = [ "atmega328p", "rt", "critical-section" ] }

Example code

#[avr_device::entry]
fn main() -> ! {
    loop {
        // ...
        let nr_unused_stack_bytes = avr_stack::estimate_unused_stack_space();
        // ...
    }
}

avr_stack::init_stack_pattern!();

Details: Stack Usage Estimation

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.

License

This project is licensed under either:

at your option.

Copyright (C) 2025 - 2026 Michael Büsch m@bues.ch