Program freezes if compiled in debug mode. #528
-
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. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
If, by debug build, you mean a build without optimizations, you are pretty much guaranteed to run into tons of issues. Due to the extremely limited amount of SRAM on AVR microcontrollers, we must rely on a lot of compiler optimizations to get the code into a shape whose memory footprint is small enough. Because of this, we usually configure the dev profile (that's Lines 1 to 11 in 2eb28fa Please make sure you are also using similar settings in your codegen-units = 1
incremental = false
debug-assertions = false
overflow-checks = false |
Beta Was this translation helpful? Give feedback.
If, by debug build, you mean a build without optimizations, you are pretty much guaranteed to run into tons of issues. Due to the extremely limited amount of SRAM on AVR microcontrollers, we must rely on a lot of compiler optimizations to get the code into a shape whose memory footprint is small enough.
Otherwise, the stack will quickly grow too large and either corrupt statics or simply lead to an overflow.
Because of this, we usually configure the dev profile (that's
cargo run
) to also apply optimizations, similar to the release profile (cargo run --release
). The relevant code is here:avr-hal/Cargo.toml
Lines 1 to 11 in 2eb28fa