STM32 Flash Memory Calculator
Calculate flash memory usage: sector sizes, code size, and available memory for STM32 MCUs.
Key Formulas
Free = Total – Used – Reserve
For OTA: need A+B partition (2× code size free).
Frequently Asked Questions
What does the STM32 Flash Memory Calculator actually compute?
This tool calculates total flash memory usage, available free space, and sector-level allocation for STM32 microcontrollers. It breaks down how much flash is consumed by application code, constants/data, bootloader, EEPROM emulation, and reserved margin. The output includes sector count, used/available KB, and percentage utilization — critical for firmware layout planning.
Why do I need to specify a “Reserve Margin”?
The reserve margin (default 10%) accounts for future firmware updates, versioning overhead, or unexpected growth in code/data size. STM32 flash sectors cannot be partially erased — reserving margin ensures at least one full sector remains available for safe OTA updates or runtime reprogramming without risking corruption.
What are typical values for Bootloader and EEPROM Emulation sizes?
A minimal UART/IAP bootloader typically uses 8–32 KB; larger ones with USB DFU or secure boot may require 64–128 KB. EEPROM emulation (e.g., using ST’s AN2594 or HAL_FLASHEx_DATAEEPROM) commonly consumes 2–16 KB depending on data volume and redundancy strategy — 4 KB is a common starting point for small configuration storage.
How do I determine my MCU’s total flash size?
Refer to your specific STM32 part’s datasheet (e.g., STM32F407VG = 1024 KB, STM32G071RB = 128 KB) or reference manual section “Memory mapping”. You can also check the linker script (.ld file) — look for the FLASH memory region definition — or use STM32CubeMX to confirm device-specific flash capacity.
Can this calculator help me avoid flash overflow during development?
Yes — it provides early visibility into flash budget constraints before flashing fails. By modeling code, data, bootloader, and margin together, you can identify over-allocation *before* compilation or linking. Pair it with `arm-none-eabi-size` output to validate actual .text/.rodata usage against your inputs.
Why does the calculator group “Data/Const” separately from “Code”?
In STM32, initialized global variables and const data (e.g., lookup tables, strings) reside in flash (`.rodata`) and contribute to flash usage — unlike RAM-based `.data` or `.bss`. Separating them reflects real flash consumption and helps optimize const placement (e.g., moving large arrays to external memory or compressing).
What happens if my calculated usage exceeds 100%?
The tool highlights over-allocation with visual warnings (e.g., red percentage, negative available space). This signals that your current partitioning won’t fit — you’ll need to reduce code size, optimize const data, shrink bootloader, adjust EEPROM emulation scheme, or select an MCU with larger flash. Sector alignment may also force rounding up.
Does this tool account for flash sector alignment and erase granularity?
Yes — while not exposing raw sector addresses, the calculator assumes standard STM32 flash organization (e.g., 16 KB / 64 KB / 128 KB sectors per bank) and computes minimum required sectors based on total used size + margin. This ensures realistic estimates aligned to hardware constraints — critical for bootloader and OTA design.
How does this differ from checking `map` file or `size` command output?
The `size` command shows static link-time footprint; this calculator adds *runtime-aware* allocations: bootloader, EEPROM emulation pages, and safety margin. It bridges the gap between compiled binary size and real-world flash layout — especially vital when multiple firmware components share the same flash space.
Can I use this for dual-bank OTA setups?
Absolutely — configure “MCU Flash Total” as half the physical flash (e.g., 256 KB for a 512 KB MCU), set “Code Size” to your full application image size, and include bootloader & margin. The result tells you whether both active and update banks fit within their allocated halves while respecting sector boundaries.