avr-device icon indicating copy to clipboard operation
avr-device copied to clipboard

RFC: Advanced stack usage analysis

Open mbuesch opened this issue 1 month ago • 0 comments

I'm not sure of this is fundamental enough to warrant being integrated into the avr-device, but since we already have a related feature get_stack_size() in avr-device, I think this is worth discussing.

In my application I need an estimate of the maximum stack usage rather than the current stack usage (get_stack_size()).

I wrote the following crate to do that:

https://github.com/mbuesch/avr-stack

It works by poisoning the whole stack area during .init4 with a known byte pattern. The crate provides a function to scan the stack for this pattern and counts how many bytes still contain the pattern.

The advantage to get_stack_size is that it can be called at any time and still get a maximum usage value.

The disadvantage is that this is only an estimate. It does not detect if the application code writes the pattern itself. But I think in most application this is a negligible disadvantage.

For me there currently are two options:

  • Publish the avr-stack crate as-is
  • or integrate this feature into avr-device

What do you think? I'm fine with either option. If you don't like to have this advanced stack scanning in avr-device, then please just close this issue. If you'd like to have this feature in avr-device, then I'll prepare a PR.

Thanks and have fun!

mbuesch avatar Nov 19 '25 19:11 mbuesch