Skip to content

Commit 6e6ab2f

Browse files
Marek Matejkartben
authored andcommitted
soc: espressif: Remove ESP heap and use heap adapter
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. Update the Wi-Fi and BLE memory needs. Signed-off-by: Marek Matej <[email protected]>
1 parent 65d2139 commit 6e6ab2f

File tree

15 files changed

+45
-162
lines changed

15 files changed

+45
-162
lines changed

drivers/bluetooth/hci/Kconfig.esp32

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
if BT_ESP32
44

5+
config HEAP_MEM_POOL_ADD_SIZE_ESP_BT
6+
int
7+
default 25600 if ESP_BT_HEAP_SYSTEM
8+
default 0
9+
help
10+
Make sure there is a minimal heap available for BT driver.
11+
512
choice ESP_BT_HEAP
613
prompt "Bluetooth adapter heap in use"
7-
default ESP_BT_HEAP_RUNTIME
8-
9-
config ESP_BT_HEAP_RUNTIME
10-
bool "Bluetooth adapter use ESP runtime heap"
11-
depends on ESP_HEAP_RUNTIME
14+
default ESP_BT_HEAP_SYSTEM
1215

1316
config ESP_BT_HEAP_SYSTEM
14-
bool "Bluetooth adapter use system heap"
17+
bool "Bluetooth adapter use the kernel mempool heap (k_malloc)"
1518

1619
endchoice # ESP_BT_HEAP
1720

drivers/wifi/esp32/Kconfig.esp32

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ menuconfig WIFI_ESP32
2020

2121
if WIFI_ESP32
2222

23-
config HEAP_MEM_POOL_ADD_SIZE_WIFI
23+
config HEAP_MEM_POOL_ADD_SIZE_ESP_WIFI
2424
int
25-
default 4096
25+
default 40960 if ESP_WIFI_HEAP_SYSTEM
26+
default 0
2627
help
2728
Make sure there is a minimal heap available for Wi-Fi driver.
2829

30+
choice ESP_WIFI_HEAP
31+
prompt "Wi-Fi adapter heap memory"
32+
default ESP_WIFI_HEAP_SYSTEM
33+
34+
config ESP_WIFI_HEAP_SYSTEM
35+
bool "Wi-Fi adapter use kernel mempool heap (k_malloc)"
36+
37+
endchoice # ESP_WIFI_HEAP
38+
2939
config NET_TCP_WORKQ_STACK_SIZE
3040
default 2048
3141

@@ -333,23 +343,6 @@ config ESP32_WIFI_SLP_DEFAULT_WAIT_BROADCAST_DATA_TIME
333343
before entering the sleep process. If a broadcast packet is received with more data bits, the time
334344
will refreshed. unit: milliseconds.
335345

336-
choice ESP_WIFI_HEAP
337-
prompt "Wifi adapter heap in use"
338-
default ESP_WIFI_HEAP_RUNTIME
339-
340-
config ESP_WIFI_HEAP_RUNTIME
341-
bool "Wifi adapter use ESP runtime heap"
342-
depends on ESP_HEAP_RUNTIME
343-
344-
config ESP_WIFI_HEAP_SPIRAM
345-
bool "Wifi adapter use SPIRAM heap"
346-
depends on ESP_SPIRAM
347-
348-
config ESP_WIFI_HEAP_SYSTEM
349-
bool "Wifi adapter use system heap"
350-
351-
endchoice # ESP_WIFI_HEAP
352-
353346
config ESP32_WIFI_FTM_ENABLE
354347
bool "WiFi FTM"
355348
default n

soc/espressif/common/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@
44
zephyr_include_directories(include)
55

66
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
7-
zephyr_sources_ifdef(CONFIG_ESP_HEAP_RUNTIME esp_heap_runtime.c)
87
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c)
98
endif()

soc/espressif/common/Kconfig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ config ESP_SIMPLE_BOOT
2424
Please note that this method brings the system up with all memories set-up, but
2525
all other features, such as secure boot OTA or slots management are not available.
2626

27-
config ESP_HEAP_RUNTIME
28-
bool
29-
default y
30-
help
31-
Enabling this will allocate SRAM area starting from the last linked data at the symbolic `_end`,
32-
ending at the last memory location that can be safely accessed (depending on a boot mode).
33-
This is a memory pool used in runtime to create a new heap memory.
34-
3527
config ESP32_TIMER_TASK_STACK_SIZE
3628
int "Stack size of the high resolution ESP Timer"
3729
default 4096

soc/espressif/common/esp_heap_runtime.c

Lines changed: 0 additions & 77 deletions
This file was deleted.

soc/espressif/common/include/esp_heap_runtime.h

Lines changed: 0 additions & 43 deletions
This file was deleted.

soc/espressif/common/loader.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static HDR_ATTR void (*_entry_point)(void) = &__start;
7474
esp_image_header_t WORD_ALIGNED_ATTR bootloader_image_hdr;
7575
extern uint32_t _image_irom_start, _image_irom_size, _image_irom_vaddr;
7676
extern uint32_t _image_drom_start, _image_drom_size, _image_drom_vaddr;
77+
extern uint32_t _libc_heap_size;
7778

7879
#ifndef CONFIG_MCUBOOT
7980
static uint32_t _app_irom_start =
@@ -84,6 +85,7 @@ static uint32_t _app_drom_start =
8485
(FIXED_PARTITION_OFFSET(slot0_partition) + (uint32_t)&_image_drom_start);
8586
static uint32_t _app_drom_size = (uint32_t)&_image_drom_size;
8687

88+
static uint32_t libc_heap_size = (uint32_t)&_libc_heap_size;
8789
#endif
8890

8991
static uint32_t _app_irom_vaddr = ((uint32_t)&_image_irom_vaddr);
@@ -260,7 +262,7 @@ void __start(void)
260262
".option norelax\n"
261263
"la gp, __global_pointer$\n"
262264
".option pop");
263-
#endif /* CONFIG_RISCV_GP */
265+
#endif
264266

265267
#ifndef CONFIG_BOOTLOADER_MCUBOOT
266268
/* Init fundamental components */
@@ -278,12 +280,14 @@ void __start(void)
278280
#ifndef CONFIG_SOC_SERIES_ESP32C2
279281
/* Disable RNG entropy source as it was already used */
280282
soc_random_disable();
281-
#endif /* CONFIG_SOC_SERIES_ESP32C2 */
283+
#endif
282284
#if defined(CONFIG_SOC_SERIES_ESP32S3) || defined(CONFIG_SOC_SERIES_ESP32C3)
283285
/* Disable glitch detection as it can be falsely triggered by EMI interference */
284286
ESP_EARLY_LOGI(TAG, "Disabling glitch detection");
285287
ana_clock_glitch_reset_config(false);
286-
#endif /* CONFIG_SOC_SERIES_ESP32S2 */
287-
ESP_EARLY_LOGI(TAG, "Jumping to the main image...");
288+
#endif
289+
#if !defined(CONFIG_MCUBOOT)
290+
ESP_EARLY_LOGI(TAG, "libc heap size %d kB.", libc_heap_size / 1024);
291+
#endif
288292
__esp_platform_start();
289293
}

soc/espressif/esp32/default.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ _rom_store_table = 0;
100100
PROVIDE(_memmap_vecbase_reset = 0x40000450);
101101
PROVIDE(_memmap_reset_vector = 0x40000400);
102102

103+
/* Heap size calculations for PROCPU is also valid for AMP scenario */
103104
_heap_sentry = SRAM2_DRAM_END;
105+
_libc_heap_size = _heap_sentry - _end;
104106

105107
SECTIONS
106108
{

soc/espressif/esp32/default_appcpu.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ _rom_store_table = 0;
7272
PROVIDE(_memmap_vecbase_reset = 0x40000450);
7373
PROVIDE(_memmap_reset_vector = 0x40000400);
7474

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

7779
SECTIONS
7880
{

soc/espressif/esp32c2/default.ld

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ _rom_store_table = 0;
8585

8686
_iram_dram_offset = IRAM_DRAM_OFFSET;
8787

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

9192
SECTIONS
9293
{

0 commit comments

Comments
 (0)