I'm trying to reduce the amount of memory being used my the Arduion core and I was told to start by looking at the ELF file for my project. Problem I that I have no idea where to begin looking. Can someone point me in the right direction?
Have you done simple things such as using byte vs int for value that are <=255?
If you have large arrays, that can save a lot of space.
Or things like compressing data, using a byte to store 8 0s and 1s:
byte dataArray[] = {0,1,1,0,1,1,1,0, -> 8 bytes
vs
byte dataArray[] = {0b01101110, -> 1 byte
I was told to start by looking at the ELF file for my project. Problem I that I have no idea where to begin looking.
You can find the file by following these instructions:
- Select File > Preferences from the Arduino IDE menus.
- Check the box next to "Show verbose output during: ☐ compilation".
- Click the OK button.
- Select Sketch > Verify/Compile from the Arduino IDE menus.
After it finishes compiling, look at the black output panel at the bottom of the IDE window. The last few lines will look something like:
"C:\Program Files (x86)\arduino-1.6.9\hardware\tools\avr/bin/avr-objcopy" -O ihex -R .eeprom "C:\Users\per\AppData\Local\Temp\build057f2fe5b49ad39f7725d80630ea8121.tmp/Blink.ino.elf" "C:\Users\per\AppData\Local\Temp\build057f2fe5b49ad39f7725d80630ea8121.tmp/Blink.ino.hex"
Sketch uses 1,066 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.
As you can see, in this case the location of the .elf
file is:
C:\Users\per\AppData\Local\Temp\build057f2fe5b49ad39f7725d80630ea8121.tmp/Blink.ino.elf
I'm not sure if that will be useful for reducing memory usage, but knowing how to find the build folder can be helpful for other reasons.
I'd look at your source code instead, as CrossRoads suggested.
Using the F()
macro can be a big help in moving strings to flash to save SRAM.
Except if one runs out of code memory (Flash) instead of data (SRAM)
pert:
I'm not sure if that will be useful for reducing memory usage
Actually having the .elf file is critical to being able to analyze code and data usage.
But having the raw .elf file isn't that helpful. What you really need is a link map or a listing file, but you can easily generate those from the elf file using avr-nm and avr-objdump
Doing anything else is simply wasting lots of time as you are just firing shots in the dark.
for the listing file:
avr-objdump -S -h $elfname
for the linkmap:
avr-nm -S $elfname
I use a wrapper script around avr-objcopy to automatically create a listing file and symbol table file each time the sketch is built but it requires an operating system that has real commandline tools (not Windows).
That way I automatically get the files every time a build a sketch and if I need them I can just go down into the sketch build area and they are there.
--- bill
Heey, I've updated boards to latest 1.6.18 and now getting elf sized about 160kb, and near .hex sized about 65kb; but IDE write "Sketch uses 22,932 bytes (74%) of program storage space". I assume, 22932 != 160000, so how could I get straight .bin file that goes to avr flash instead of this complete .elf with all the symbols? Did complete search on my "c:/" by size 22932, and no files were found.
The Arduino IDE computes the size using the avr-size tool on the file which is part of avr-gcc, included with the Arduino IDE as part of the Arduino AVR Boards package. You can see the command the IDE uses here:
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
If you like you can convert the file to .bin using the avr-objcopy tool which is part of avr-gcc, included with the Arduino IDE as part of the Arduino AVR Boards package.
pert, Thank you very much, did this successfully!
avr-objcopy -O binary mysketch.ino.elf out.bin