Rahix / avr-hal

embedded-hal abstractions for AVR microcontrollers
Apache License 2.0
1.3k stars 219 forks source link

Program freezes if compiled in debug mode. #527

Closed crmoratelli closed 6 months ago

crmoratelli commented 6 months ago

Hi.

Recently I was working on this project BMP180-ATmega2560-rust, where I implemented a driver to the BMP180 using this HAL. I was using cargo run to upload code to an Arduino Mega 2560 board.

Everything was working fine. However, as the code got bigger, the program started to freeze. I could still see initialization messages, but it stopped execution at some point. I did some tests, and I noticed that commenting out some code lines allows the execution to continue. However, the local variables had wrong values, which I checked with prints.

Compiling with cargo run --release makes it work without any problem. My experience in C programming with embedded makes me think that, for some reason, the stack could be corrupted. I would like to understand better if there is any restriction in building a debugging target (cargo run) or what else could be causing this behavior.

The link in this message takes you to the repository. This error can be reproduced with cargo run and the running version with cargo run --release, but you need a BMP180 to see it working.