1

I want to calculate space left on my embedded target.

The Arduino IDE shows this in the output window:

Sketch uses 9544 bytes (3%) of program storage space. Maximum is 262144 bytes.

avr-size has -C option that shows "xx% left":

$ avr-size -C --mcu=atmega32u4 build/myproject.hex
AVR Memory Usage
----------------
Device: atmega32u4

Program:    8392 bytes (25.6% Full)
(.text + .data + .bootloader)

Data:       2196 bytes (85.8% Full)
(.data + .bss + .noinit)

However, I'm actually writing a CMake file to develop code for an Arduino board with an Arm Cortex M0 CPU, so I use arm-none-eabi-size, which shows the code size like this:

[100%] Built target hex
   text    data     bss     dec     hex filename
   8184     208    1988   10380    288c build/myproject
[100%] Built target size
*** Finished ***

Is there a way to calculate the program and data space left on the device? Or do I need to regex the output and calculate percent of a hard-coded value?

Laurenz
  • 1,810
  • 12
  • 25
  • how deep does your stack get worst case? Or are you talking flash only? – old_timer Dec 24 '17 at 14:24
  • For now, I mostly care about flash. I was hoping there is a hidden option like with `avr-size`, an alternative `arm-none-eabi-size` that can do the calculation, or a program that runs `arm-none-eabi-size` and parses its output... – Laurenz Dec 24 '17 at 14:41
  • avr-whatever-objcopy -O binary myprog.elf myprog.bin and see how big the .bin file is. readelf and others should also have similar information. – old_timer Dec 24 '17 at 22:31
  • and it looks like the tools are already telling you this? – old_timer Dec 24 '17 at 22:31

1 Answers1

3

If you are using arm-none-eabi toolchain, you can add linker option -Wl,--print-memory-usage which prints RAM and Flash usage in percentage. Output looks like this:

Memory region         Used Size  Region Size  %age Used
             RAM:        8968 B        20 KB     43.79%
           FLASH:       34604 B       128 KB     26.40%

I am using make file generated by CubeMX, to enable this print I added the option at the end of LDFLAGS line. For CMake this thread might be useful.

Creek Drop
  • 464
  • 3
  • 13