This is the size of firmware binary that must be transported to the board as reported by PlatformIO. Around 135.24 kBytes. Note that PlatformIO determines this size by only looking at a few specific sections in the ELF, so if any custom ones are in there, those won’t be counted.
Flash is arranged in pages and blocks. When programming a device, the old content has to be erased first. Erasing is done in a block size. So really, the J-Link (or any debug probe) cannot just delete the exact 138486 Bytes in flash – it must always erase whole blocks. Per datasheet page 24 we see the
and read on page 29
When erase is enabled, the Flash can be erased page by page using the ERASEPAGE register.
As illustrated in Memory on page 23, the Flash is divided into multiple pages that are further divided into multiple blocks. […] See the memory size and organization in Memory onpage 23 for block size
As one can see from the addresses, one page is 0x1000 bytes, or 4096 bytes decimal, big, and flash has to be erased in multiples of 4 kBytes. However, the firmware size was not a multiple 4096, but we still have to erase in full blocks, thus leading to more bytes being erased than the firmware is actually big. This is perfectly normal.
A Intel hex file encodes the binary content (and addresses, and some other metainformation) in human-readable ASCII text. Binary to HEX conversion at least doubles the amount of space requires as compared to the pure binary format (.bin
). So, the actual amount of bytes written will be less than half of the sie of the .hex
file.
A 1:1 correlation would be there if the file was in .bin
format – the size of that file matches 1:1 the length and binary contents of what’s actually written into flash then. In this case for flashing, PlatformIO doesn’t need the file in .bin
format, so it doesn’t generate it. You can still generate it by converting it from the .hex
file (or the .elf
file), by running the toolchain tool objcopy
, as in e.g.
~/.platformio/packges/toolchain-gccarmnoneeabi/bin/arm-none-eabi-objcopy -I ihex -O binary <path to firmware.hex> firmware.bin
will create firmware.bin
, whose size is 1:1 representative as to that in flash, as said before.