I have spent a few hours investigating where all the RAM has gone in my new Arduino project. I need to investigate newer versions (still running 1.0), I really hope there are improvements.
My favorite WTFs:
- string constants are stored in RAM
- string constants can be stored in Flash. For that you need to wrap them in F(“blah”) macro.
- when using F(), the string is wrapped into an object and is no longer a char*. You can no longer pass such strings into functions expecting a const char*. Therefore only useless constants can be off-loaded to Flash
- no warning is given when the precious RAM is wasted
- no warning is given when RAM usage reaches 100%. Only Flash consumption is shown
Check out more info at http://arduino.cc/en/Reference/PROGMEM
Here are a couple of useful commands that give RAM usage and allocation listing. Let’s say Arduino is installed at ~/arduino. First you need to enable verbose output during compilation in the Arduino IDE preferences. When compilation is done, find and replace my /tmp/build582139005597328143.tmp with your compilation directory found in the messages. Replace the Atmega model if necessary
~/arduino/hardware/tools/avr/bin$ avr-objdump -t -j .bss /tmp/build582139005597328143.tmp/controller.cpp.elf /tmp/build582139005597328143.tmp/controller.cpp.elf: file format elf32-avr SYMBOL TABLE: 008003c8 l d .bss 00000000 .bss 0080041e l O .bss 00000001 timer0_fract 00800416 g O .bss 00000004 timer0_overflow_count 0080041a g O .bss 00000004 timer0_millis 00800406 g O .bss 00000008 keyCounters 008004c6 g .bss 00000000 __bss_end 008003c8 g O .bss 0000003e SCmd 0080041f g O .bss 00000044 rx_buffer 00800463 g O .bss 00000044 tx_buffer 008004a7 g O .bss 0000001f Serial 008003c8 g .bss 00000000 __bss_start 0080040e g O .bss 00000008 startup_values ~/arduino/hardware/tools/avr/bin$ avr-size /tmp/build582139005597328143.tmp/controller.cpp.elf -C --mcu=atmega168p AVR Memory Usage ---------------- Device: atmega168p Program: 5992 bytes (36.6% Full) (.text + .data + .bootloader) Data: 358 bytes (35.0% Full) (.data + .bss + .noinit)