Let's Make Robots!

avr-size is quite a useful tool...

I was pulling my hairs out over unexplainable crashes yesterday, occuring on a Motoruino board.

It occured after simply enabling some more debugging stuff and it started to act all weird: crashing randomly and corrupted serial data.

It really had me going nuts at some point -- even wondering if the chip was bad. All until I read some interesting stuff about the .bss and .data size having limits. A shame that the  Arduino IDE does not check for the allowed sizes for SRAM.

The following command can easily reveal my problem:

avr-size /path/to/temporary_compile_dir/compiled.cpp.elf

text    data     bss     dec     hex                                                                                                     
11926    1594     474   13994    36aa

The values for .data and .bss exceed the allowed SRAM size limit. So that's were the problem came from! Perhaps adding all those ANSI escape codes to make my Serial debugging console all colourful and sexy was not such a good idea after all... :-D


As I had not read about this before, I thought it was interesting enough to share. I'm sorry if it wasn't :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Ah yes I see I forgot to specify that I'm using Linux.

The command is entered in a terminal on the command line interface, right after you let the Arduino IDE compile your project while holding "shift" to fully log the compilation process -- so you can see where it stored the temporary .cpp.elf file.

(Note that you have to run it on the .cpp.elf file generated in the penultimate step in the compilation process; the final .hex file will not be recognised.)


The SRAM size limit is 2048 for the ATmega368. However, this is also used for run-time stack. Too close to that limit, (say, 1940 bytes), the sketch will still crashes during run-time because it cannot pop stuff onto the stack when jumping to a subroutine.