Find what consumes flash in an STM32 firmware build
Use the ELF and linker map to measure code size and identify expensive STM32 or Arduino dependencies.
Measure the linked image
Run arm-none-eabi-size on the ELF and compare the sections reported by the linker. Initialized data consumes both flash storage and runtime RAM. BSS consumes RAM at runtime. Use the board's flash region in the link script, including any area reserved for a bootloader, to determine whether the image fits.
Generate a link map with -Wl,-Map=firmware.map and sort ELF symbols by size with arm-none-eabi-nm -S --size-sort firmware.elf. Compare maps after changing one input at a time. The ELF file's on-disk size includes debug and symbol data beyond the sections written to the device.
Reduce the largest measured dependencies
Try size optimization, function and data sections, and linker garbage collection when supported by the build. Compare the map to confirm the effect. Floating-point printf, large protocol stacks and default peripheral initialization can increase size, so check which instance actually accounts for the growth.
Verify that any change to the C library, optimization flags or linker options still gives the output and startup behaviour required by your application.
