Heap Memory Allocation - Espressif ESP32-S2 Programming Manual

Table of Contents

Advertisement

Chapter 2. API Reference
• [in] cpuid: id of the core
void
esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t
Unregister a tick callback. If the tick callback is registered to the tick hooks of both cores, the tick hook will
be unregistered from both cores.
Parameters
• [in] old_tick_cb: Callback to be unregistered
Type Definitions
typedef bool (*esp_freertos_idle_cb_t)(void)
typedef void (*esp_freertos_tick_cb_t)(void)

2.6.12 Heap Memory Allocation

Stack and Heap
ESP-IDF applications use the common computer architecture patterns of stack (dynamic memory allocated by pro-
gram control flow) and heap (dynamic memory allocated by function calls), as well as statically allocated memory
(allocated at compile time).
Because ESP-IDF is a multi-threaded RTOS environment, each RTOS task has its own stack. By default, each of
these stacks is allocated from the heap when the task is created. (See
where stacks are statically allocated.)
Because ESP32-S2 uses multiple types of RAM, it also contains multiple heaps with different capabilities. A
capabilities-based memory allocator allows apps to make heap allocations for different purposes.
For most purposes, the standard libc malloc() and free() functions can be used for heap allocation without any
special consideration.
However, in order to fully make use of all of the memory types and their characteristics, ESP-IDF also has a
capabilities-based heap memory allocator. If you want to have memory with certain properties (for example,
Capable Memory
or executable-memory), you can create an OR-mask of the required capabilities and pass that to
heap_caps_malloc().
Memory Capabilities
The ESP32-S2 contains multiple types of RAM:
• DRAM (Data RAM) is memory used to hold data. This is the most common kind of memory accessed as
heap.
• IRAM (Instruction RAM) usually holds executable data only. If accessed as generic memory, all accesses must
be
32-bit
aligned.
• D/IRAM is RAM which can be used as either Instruction or Data RAM.
For more details on these internal memory types, see
It' s also possible to connect external SPI RAM to the ESP32-S2 -
s memory map using the flash cache, and accessed similarly to DRAM.
DRAM uses capability MALLOC_CAP_8BIT (accessible in single byte reads and writes). When calling mal-
loc(), the ESP-IDF malloc() implementation internally calls heap_caps_malloc(size,
LOC_CAP_8BIT) in order to allocate DRAM that is byte-addressable. To test the free DRAM heap size at runtime,
call cpp:func:heap_caps_get_free_size(MALLOC_CAP_8BIT).
Because malloc uses the capabilities-based allocation system, memory allocated using
can be freed by calling the standard free() function.
Espressif Systems
Memory
Types.
external RAM
972
Submit Document Feedback
old_tick_cb)
xTaskCreateStatic()
can be integrated into the ESP32-S2'
heap_caps_malloc()
for the alternative
DMA-
MAL-
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Questions and answers

Table of Contents

Save PDF