Chapter 4. API Guides
The first step to reducing the total firmware binary size is measuring what is causing the size to increase.
Measuring Static Sizes
statically allocated RAM ("data", "bss"), code ("text") and read-only data ("rodata") in your project.
Using the
idf.py
sub-commands size, size-components and size-files provides a summary of memory
used by the project:
Size Summary (idf.py size)
$ idf.py size
[...]
Total sizes:
DRAM .data size:
DRAM .bss
size:
Used static DRAM:
Used static IRAM:
Used stat D/IRAM:
136276
Flash code:
630508
Flash rodata:
177048
Total image size:~
924208
This output breaks down the size of all static memory regions in the firmware binary:
• DRAM .data size is statically allocated RAM that is assigned to non-zero values at startup. This uses
RAM (DRAM) at runtime and also uses space in the binary file.
• DRAM .bss size is statically allocated RAM that is assigned zero at startup. This uses RAM (DRAM) at
runtime but doesn't use any space in the binary file.
• Used static DRAM, Used static IRAM - these options are kept for compatibility with ESP32 target,
and currently read 0.
• Used stat D/IRAM - This is total internal RAM usage, the sum of static DRAM .data + .bss, and also
static
IRAM (Instruction RAM)
estimated amount of DRAM which will be available as heap memory at runtime (due to metadata overhead
and implementation constraints, and heap allocations done by ESP-IDF during startup, the actual free heap at
startup will be lower than this).
• Flash code is the total size of executable code executed from flash cache (IROM). This uses space in the
binary file.
• Flash rodata is the total size of read-only data loaded from flash cache (DROM). This uses space in the
binary file.
• Total image size is the estimated total binary file size, which is the total of all the used memory types
except for .bss.
Component Usage Summary (idf.py size-components)
not give enough detail to find the main contributor to excessive binary size. To analyze in more detail, use idf.py
size-components
$ idf.py size-components
[...]
Total sizes:
DRAM .data size:
DRAM .bss
size:
Used static DRAM:
Used static IRAM:
Flash code:
559943
Flash rodata:
176736
Total image size:~
835553
Per-archive contributions to ELF file:
Archive File DRAM .data & .bss & other
rodata
Total
→
Espressif Systems
To optimize both firmware binary size and memory usage it's necessary to measure
11584
bytes
19624
bytes
0
bytes
(
0
0
bytes
(
0
bytes
(
519084
bytes
bytes
bytes (.bin may be padded
used by the application for executable code. The available size is the
14956
bytes
15808
bytes
30764
bytes
(
149972
83918
bytes
(
47154
bytes
bytes
bytes (.bin may be padded
Submit Document Feedback
available, nan%
used)
available, nan%
used)
available, 20.8%
used)
larger)
The summary output provided by idf.py size does
available, 17.0%
used)
available, 64.0%
used)
larger)
IRAM
1444
D/IRAM Flash code
&␣
(continues on next page)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?