Skip to content

Commit

Permalink
soc: espressif: Remove ESP heap and use heap adapter
Browse files Browse the repository at this point in the history
Remove ESP heap from the sources. System heap is default heap.
Use heap adapter layer to configure used heap.
Use MEM_POOL memory request config to Wi-Fi and Bluetooth drivers.

Signed-off-by: Marek Matej <[email protected]>
  • Loading branch information
Marek Matej committed Jan 31, 2025
1 parent b222b78 commit e50546c
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 162 deletions.
18 changes: 12 additions & 6 deletions drivers/bluetooth/hci/Kconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

if BT_ESP32

config HEAP_MEM_POOL_ADD_SIZE_ESP_BT
int
default 40960 if ESP_BT_HEAP_SYSTEM
default 0
help
Make sure there is a minimal heap available for BT driver.

choice ESP_BT_HEAP
prompt "Bluetooth adapter heap in use"
default ESP_BT_HEAP_RUNTIME

config ESP_BT_HEAP_RUNTIME
bool "Bluetooth adapter use ESP runtime heap"
depends on ESP_HEAP_RUNTIME
default ESP_BT_HEAP_SYSTEM

config ESP_BT_HEAP_SYSTEM
bool "Bluetooth adapter use system heap"
bool "Bluetooth adapter use the kernel mempool heap (k_malloc)"

config ESP_BT_HEAP_LIBC
bool "Bluetooth adapter use libc heap (malloc)"

endchoice # ESP_BT_HEAP

Expand Down
33 changes: 14 additions & 19 deletions drivers/wifi/esp32/Kconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ menuconfig WIFI_ESP32

if WIFI_ESP32

config HEAP_MEM_POOL_ADD_SIZE_WIFI
config HEAP_MEM_POOL_ADD_SIZE_ESP_WIFI
int
default 4096
default 51200 if ESP_WIFI_HEAP_SYSTEM
default 0
help
Make sure there is a minimal heap available for Wi-Fi driver.

choice ESP_WIFI_HEAP
prompt "Wi-Fi adapter heap memory"

config ESP_WIFI_HEAP_SYSTEM
bool "Wi-Fi adapter use kernel mempool heap (k_malloc)"

config ESP_WIFI_HEAP_LIBC
bool "Wi-Fi adapter use libc heap (malloc)"

endchoice # ESP_WIFI_HEAP

config NET_TCP_WORKQ_STACK_SIZE
default 2048

Expand Down Expand Up @@ -333,23 +345,6 @@ config ESP32_WIFI_SLP_DEFAULT_WAIT_BROADCAST_DATA_TIME
before entering the sleep process. If a broadcast packet is received with more data bits, the time
will refreshed. unit: milliseconds.

choice ESP_WIFI_HEAP
prompt "Wifi adapter heap in use"
default ESP_WIFI_HEAP_RUNTIME

config ESP_WIFI_HEAP_RUNTIME
bool "Wifi adapter use ESP runtime heap"
depends on ESP_HEAP_RUNTIME

config ESP_WIFI_HEAP_SPIRAM
bool "Wifi adapter use SPIRAM heap"
depends on ESP_SPIRAM

config ESP_WIFI_HEAP_SYSTEM
bool "Wifi adapter use system heap"

endchoice # ESP_WIFI_HEAP

config ESP32_WIFI_FTM_ENABLE
bool "WiFi FTM"
default n
Expand Down
1 change: 0 additions & 1 deletion soc/espressif/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
zephyr_include_directories(include)

if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
zephyr_sources_ifdef(CONFIG_ESP_HEAP_RUNTIME esp_heap_runtime.c)
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c)
endif()
8 changes: 0 additions & 8 deletions soc/espressif/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ config ESP_SIMPLE_BOOT
Please note that this method brings the system up with all memories set-up, but
all other features, such as secure boot OTA or slots management are not available.

config ESP_HEAP_RUNTIME
bool
default y
help
Enabling this will allocate SRAM area starting from the last linked data at the symbolic `_end`,
ending at the last memory location that can be safely accessed (depending on a boot mode).
This is a memory pool used in runtime to create a new heap memory.

config ESP32_TIMER_TASK_STACK_SIZE
int "Stack size of the high resolution ESP Timer"
default 4096
Expand Down
77 changes: 0 additions & 77 deletions soc/espressif/common/esp_heap_runtime.c

This file was deleted.

43 changes: 0 additions & 43 deletions soc/espressif/common/include/esp_heap_runtime.h

This file was deleted.

12 changes: 8 additions & 4 deletions soc/espressif/common/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static HDR_ATTR void (*_entry_point)(void) = &__start;
esp_image_header_t WORD_ALIGNED_ATTR bootloader_image_hdr;
extern uint32_t _image_irom_start, _image_irom_size, _image_irom_vaddr;
extern uint32_t _image_drom_start, _image_drom_size, _image_drom_vaddr;
extern uint32_t _libc_heap_size;

#ifndef CONFIG_MCUBOOT
static uint32_t _app_irom_start =
Expand All @@ -84,6 +85,7 @@ static uint32_t _app_drom_start =
(FIXED_PARTITION_OFFSET(slot0_partition) + (uint32_t)&_image_drom_start);
static uint32_t _app_drom_size = (uint32_t)&_image_drom_size;

static uint32_t libc_heap_size = (uint32_t)&_libc_heap_size;
#endif

static uint32_t _app_irom_vaddr = ((uint32_t)&_image_irom_vaddr);
Expand Down Expand Up @@ -260,7 +262,7 @@ void __start(void)
".option norelax\n"
"la gp, __global_pointer$\n"
".option pop");
#endif /* CONFIG_RISCV_GP */
#endif

#ifndef CONFIG_BOOTLOADER_MCUBOOT
/* Init fundamental components */
Expand All @@ -278,12 +280,14 @@ void __start(void)
#ifndef CONFIG_SOC_SERIES_ESP32C2
/* Disable RNG entropy source as it was already used */
soc_random_disable();
#endif /* CONFIG_SOC_SERIES_ESP32C2 */
#endif
#if defined(CONFIG_SOC_SERIES_ESP32S3) || defined(CONFIG_SOC_SERIES_ESP32C3)
/* Disable glitch detection as it can be falsely triggered by EMI interference */
ESP_EARLY_LOGI(TAG, "Disabling glitch detection");
ana_clock_glitch_reset_config(false);
#endif /* CONFIG_SOC_SERIES_ESP32S2 */
ESP_EARLY_LOGI(TAG, "Jumping to the main image...");
#endif
#if !defined(CONFIG_MCUBOOT)
ESP_EARLY_LOGI(TAG, "libc heap size %d kB.", libc_heap_size / 1024);
#endif
__esp_platform_start();
}
2 changes: 2 additions & 0 deletions soc/espressif/esp32/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ _rom_store_table = 0;
PROVIDE(_memmap_vecbase_reset = 0x40000450);
PROVIDE(_memmap_reset_vector = 0x40000400);

/* Heap size calculations for PROCPU is also valid for AMP scenario */
_heap_sentry = SRAM2_DRAM_END;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
2 changes: 2 additions & 0 deletions soc/espressif/esp32/default_appcpu.ld
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ _rom_store_table = 0;
PROVIDE(_memmap_vecbase_reset = 0x40000450);
PROVIDE(_memmap_reset_vector = 0x40000400);

/* Heap size calculations for APPCPU */
_heap_sentry = BOOTLOADER_DRAM_SEG_START + APPCPU_DRAM_SIZE;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
3 changes: 2 additions & 1 deletion soc/espressif/esp32c2/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ _rom_store_table = 0;

_iram_dram_offset = IRAM_DRAM_OFFSET;

/* Used as a pointer to the heap end */
/* Heap size calculations */
_heap_sentry = DRAM_RESERVED_START;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
3 changes: 2 additions & 1 deletion soc/espressif/esp32c3/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ _rom_store_table = 0;

_iram_dram_offset = IRAM_DRAM_OFFSET;

/* Stack sentry */
/* Heap size calculations */
_heap_sentry = DRAM_RESERVED_START;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
2 changes: 2 additions & 0 deletions soc/espressif/esp32c6/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ REGION_ALIAS("rtc_data_location", rtc_iram_seg );
/* Default entry point: */
ENTRY(CONFIG_KERNEL_ENTRY)

/* Heap size calculations */
_heap_sentry = DRAM_RESERVED_START;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
1 change: 1 addition & 0 deletions soc/espressif/esp32s2/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ _rom_store_table = 0;

/* Used as a pointer to the heap end */
_heap_sentry = DRAM_RESERVED_START;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down
4 changes: 3 additions & 1 deletion soc/espressif/esp32s3/default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ MEMORY
/* Default entry point: */
ENTRY(CONFIG_KERNEL_ENTRY)

/* Used as a pointer to the heap end */
/* Heap size calculations differs between the APPCPU and PROCPU */
#ifdef CONFIG_SOC_ENABLE_APPCPU
_heap_sentry = procpu_dram_end;
#else
_heap_sentry = DRAM_RESERVED_START;
#endif

_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
_iram_dram_offset = IRAM_DRAM_OFFSET;
Expand Down
3 changes: 2 additions & 1 deletion soc/espressif/esp32s3/default_appcpu.ld
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ MEMORY
/* Default entry point: */
ENTRY(__appcpu_start)

/* Used as a pointer to the heap end */
/* Heap size calculations for APPCPU */
_heap_sentry = DRAM_RESERVED_START;
_libc_heap_size = _heap_sentry - _end;

SECTIONS
{
Expand Down

0 comments on commit e50546c

Please sign in to comment.