Arduino-Makefile icon indicating copy to clipboard operation
Arduino-Makefile copied to clipboard

Wrong Memory Usage report on Arduino Micro

Open rnestler opened this issue 9 years ago • 3 comments

The Arduino-Makefile reports wrong memory usage compared to the Arduino IDE:

Arduino-Makefile:

AVR Memory Usage
----------------
Device: atmega32u4

Program:   27396 bytes (83.6% Full)
(.text + .data + .bootloader)

Data:       1323 bytes (51.7% Full)
(.data + .bss + .noinit)

For the same sketch the Arduino IDE shows:

Sketch uses 27,392 bytes (95%) of program storage space. Maximum is 28,672 bytes.
Global variables use 1,323 bytes (51%) of dynamic memory, leaving 1,237 bytes for local variables. Maximum is 2,560 bytes.

Now the difference between the byte values is not that big, but the difference between the percentage values is.

The evil thing is, if the byte usage grows over the 28,672 bytes, make upload bricks the Arduino micro and I have to reprogram the bootloader! So the Arduino-Makefile doesn't seem to take the size of the bootloader into account and seem to break it when uploading.

Here are some relevant parts from the Makefile I use:

BOARD_TAG     = micro
CFLAGS_STD = -std=gnu11
CXXFLAGS_STD = -std=gnu++11 -fno-threadsafe-statics

System:

Ubuntu 14.04.4 LTS
arduino-1.6.7

rnestler avatar Mar 01 '16 17:03 rnestler

weird, as we just shell out to avr-size --mcu=atmega32u4 -C --format=avr build-leonardo/blink.elf

i've no idea how the ide calculates it, but calling avr-size on the elf file the ide creates, reports the same size info as the ide does - not the same as the makefile.

potentially its an avr-size bug....?

sej7278 avatar Mar 01 '16 18:03 sej7278

i think this must be something different the IDE and Makefile are doing with linking or flags, not anything to do with avr-size, they're just creating different sized binaries.

as the 1.0.5 IDE and avr-size on its /tmp file report the same:

avr-size --mcu=atmega32u4 -C --format=avr blink.cpp.elf 
AVR Memory Usage
----------------
Device: atmega32u4

Program:    4736 bytes (14.5% Full)
(.text + .data + .bootloader)

Data:        157 bytes (6.1% Full)
(.data + .bss + .noinit)

but the the makefile using the same 1.0.5 core, and avr-size report the same as each other, but different to the IDE - also the actual elf file on disk is different:

avr-size --mcu=atmega32u4 -C --format=avr build-leonardo/blink.elf
AVR Memory Usage
----------------
Device: atmega32u4

Program:    4304 bytes (13.1% Full)
(.text + .data + .bootloader)

Data:        154 bytes (6.0% Full)
(.data + .bss + .noinit)

the same happens with 1.6.12 - ide/builder make different size outputs to the makefile:

IDE:

Sketch uses 1,470 bytes (0%) of program storage space. Maximum is 253,952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8,183 bytes for local variables. Maximum is 8,192 bytes.

/tmp file created by the IDE (12448 bytes on disk):

/tmp/arduino_build_285509$ avr-size --mcu=atmega2560 -C --format=avr blink.ino.elf 
AVR Memory Usage
----------------
Device: atmega2560

Program:    1470 bytes (0.6% Full)
(.text + .data + .bootloader)

Data:          9 bytes (0.1% Full)
(.data + .bss + .noinit)

makefile (12544 bytes on disk):

AVR Memory Usage
----------------
Device: atmega2560

Program:    1564 bytes (0.6% Full)
(.text + .data + .bootloader)

Data:          9 bytes (0.1% Full)
(.data + .bss + .noinit)

So it seems its not reporting the wrong size, its just creating binaries of different size to the IDE.

sej7278 avatar Oct 12 '16 14:10 sej7278

i think this must be something different the IDE and Makefile are doing with linking or flags, not anything to do with avr-size, they're just creating different sized binaries.

That's what I think as well. But the worst part is, that the Makefile will produce binaries which will destroy the Arduino bootloader! If you try to produce binaries which are bigger than 28,672 bytes, the Arduino IDE will give you an error, but the Makefile will generate a binary which corrupts the bootloader if you try to download it.

rnestler avatar Oct 27 '16 11:10 rnestler