Chapter 4. API Guides
4.19 Memory Types
ESP32-S2 chip has multiple memory types and flexible memory mapping features. This section describes how ESP-
IDF uses these features by default.
ESP-IDF distinguishes between instruction memory bus (IRAM, IROM, RTC FAST memory) and data memory
bus (DRAM, DROM). Instruction memory is executable, and can only be read or written via 4-byte aligned words.
Data memory is not executable and can be accessed via individual byte operations. For more information about the
different memory buses consult the ESP32-S2 Technical Reference Manual* > System and Memory [PDF].
4.19.1 DRAM (Data RAM)
Non-constant static data (.data) and zero-initialized data (.bss) is placed by the linker into Internal SRAM as data
memory. Remaining space in this region is used for the runtime heap.
By applying the EXT_RAM_ATTR macro, zero-initialized data can also be placed into external RAM. To use this
macro, the
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
ment placed in external
memory.
Note: The maximum statically allocated DRAM size is reduced by the
application. The available heap memory at runtime is reduced by the total static IRAM and DRAM usage of the
application.
Constant data may also be placed into DRAM, for example if it is used in an non-flash-safe ISR (see explanation
under
How to place code in
"noinit"DRAM
The macro __NOINIT_ATTR can be used as attribute to place data into .noinit section. The values placed into
this section will not be initialized at startup and should keep its value after software restart.
Example:
__NOINIT_ATTR uint32_t noinit_data;
4.19.2 IRAM (Instruction RAM)
ESP-IDF allocates part of Internal SRAM region for instruction RAM. The region is defined in ESP32-S2 Technical
Reference Manual > System and Memory > Internal Memory [PDF]. Except for the first block (up to 32 kB) which
is used for MMU cache, the rest of this memory range is used to store parts of application which need to run from
RAM.
Note: Any internal SRAM which is not used for Instruction RAM will be made available as
for static data and dynamic allocation (heap).
Why place code in IRAM
Cases when parts of application should be placed into IRAM:
• Interrupt handlers must be placed into IRAM if ESP_INTR_FLAG_IRAM is used when registering the in-
terrupt handler. For more information, see
• Some timing critical code may be placed into IRAM to reduce the penalty associated with loading the code
from flash. ESP32-S2 reads code and data from flash via the MMU cache. In some cases, placing a function
into IRAM may reduce delays caused by a cache miss and significantly improve that function's performance.
Espressif Systems
IRAM).
IRAM-Safe Interrupt
Submit Document Feedback
needs to be enabled. See
IRAM (Instruction RAM)
Handlers.
1421
Allow .bss seg-
size of the compiled
DRAM (Data RAM)
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?