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 <marek.matej@espressif.com>
This commit is contained in:
parent
65d2139dc6
commit
6e6ab2f8ab
15 changed files with 45 additions and 162 deletions
|
@ -2,16 +2,19 @@
|
||||||
|
|
||||||
if BT_ESP32
|
if BT_ESP32
|
||||||
|
|
||||||
|
config HEAP_MEM_POOL_ADD_SIZE_ESP_BT
|
||||||
|
int
|
||||||
|
default 25600 if ESP_BT_HEAP_SYSTEM
|
||||||
|
default 0
|
||||||
|
help
|
||||||
|
Make sure there is a minimal heap available for BT driver.
|
||||||
|
|
||||||
choice ESP_BT_HEAP
|
choice ESP_BT_HEAP
|
||||||
prompt "Bluetooth adapter heap in use"
|
prompt "Bluetooth adapter heap in use"
|
||||||
default ESP_BT_HEAP_RUNTIME
|
default ESP_BT_HEAP_SYSTEM
|
||||||
|
|
||||||
config ESP_BT_HEAP_RUNTIME
|
|
||||||
bool "Bluetooth adapter use ESP runtime heap"
|
|
||||||
depends on ESP_HEAP_RUNTIME
|
|
||||||
|
|
||||||
config 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)"
|
||||||
|
|
||||||
endchoice # ESP_BT_HEAP
|
endchoice # ESP_BT_HEAP
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,22 @@ menuconfig WIFI_ESP32
|
||||||
|
|
||||||
if WIFI_ESP32
|
if WIFI_ESP32
|
||||||
|
|
||||||
config HEAP_MEM_POOL_ADD_SIZE_WIFI
|
config HEAP_MEM_POOL_ADD_SIZE_ESP_WIFI
|
||||||
int
|
int
|
||||||
default 4096
|
default 40960 if ESP_WIFI_HEAP_SYSTEM
|
||||||
|
default 0
|
||||||
help
|
help
|
||||||
Make sure there is a minimal heap available for Wi-Fi driver.
|
Make sure there is a minimal heap available for Wi-Fi driver.
|
||||||
|
|
||||||
|
choice ESP_WIFI_HEAP
|
||||||
|
prompt "Wi-Fi adapter heap memory"
|
||||||
|
default ESP_WIFI_HEAP_SYSTEM
|
||||||
|
|
||||||
|
config ESP_WIFI_HEAP_SYSTEM
|
||||||
|
bool "Wi-Fi adapter use kernel mempool heap (k_malloc)"
|
||||||
|
|
||||||
|
endchoice # ESP_WIFI_HEAP
|
||||||
|
|
||||||
config NET_TCP_WORKQ_STACK_SIZE
|
config NET_TCP_WORKQ_STACK_SIZE
|
||||||
default 2048
|
default 2048
|
||||||
|
|
||||||
|
@ -333,23 +343,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
|
before entering the sleep process. If a broadcast packet is received with more data bits, the time
|
||||||
will refreshed. unit: milliseconds.
|
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
|
config ESP32_WIFI_FTM_ENABLE
|
||||||
bool "WiFi FTM"
|
bool "WiFi FTM"
|
||||||
default n
|
default n
|
||||||
|
|
|
@ -4,6 +4,5 @@
|
||||||
zephyr_include_directories(include)
|
zephyr_include_directories(include)
|
||||||
|
|
||||||
if(NOT CONFIG_MCUBOOT AND NOT CONFIG_SOC_ESP32_APPCPU AND NOT CONFIG_SOC_ESP32S3_APPCPU)
|
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)
|
zephyr_sources_ifdef(CONFIG_ESP_SPIRAM esp_psram.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -24,14 +24,6 @@ config ESP_SIMPLE_BOOT
|
||||||
Please note that this method brings the system up with all memories set-up, but
|
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.
|
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
|
config ESP32_TIMER_TASK_STACK_SIZE
|
||||||
int "Stack size of the high resolution ESP Timer"
|
int "Stack size of the high resolution ESP Timer"
|
||||||
default 4096
|
default 4096
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <zephyr/types.h>
|
|
||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <soc.h>
|
|
||||||
#include <esp_err.h>
|
|
||||||
#include <esp_heap_runtime.h>
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
#define TAG "heap_runtime"
|
|
||||||
|
|
||||||
/* ESP dynamic pool heap */
|
|
||||||
extern unsigned int z_mapped_end;
|
|
||||||
extern unsigned int _heap_sentry;
|
|
||||||
static void *esp_heap_runtime_init_mem = &z_mapped_end;
|
|
||||||
|
|
||||||
#define ESP_HEAP_RUNTIME_MAX_SIZE ((uintptr_t)&_heap_sentry - (uintptr_t)&z_mapped_end)
|
|
||||||
|
|
||||||
static struct k_heap esp_heap_runtime;
|
|
||||||
|
|
||||||
static int esp_heap_runtime_init(void)
|
|
||||||
{
|
|
||||||
ESP_EARLY_LOGI(TAG, "ESP heap runtime init at 0x%x size %d kB.\n",
|
|
||||||
esp_heap_runtime_init_mem, ESP_HEAP_RUNTIME_MAX_SIZE / 1024);
|
|
||||||
|
|
||||||
k_heap_init(&esp_heap_runtime, esp_heap_runtime_init_mem, ESP_HEAP_RUNTIME_MAX_SIZE);
|
|
||||||
|
|
||||||
#if defined(CONFIG_WIFI_ESP32) && defined(CONFIG_BT_ESP32)
|
|
||||||
assert(ESP_HEAP_RUNTIME_MAX_SIZE > 65535);
|
|
||||||
#elif defined(CONFIG_WIFI_ESP32)
|
|
||||||
assert(ESP_HEAP_RUNTIME_MAX_SIZE > 51200);
|
|
||||||
#elif defined(CONFIG_BT_ESP32)
|
|
||||||
assert(ESP_HEAP_RUNTIME_MAX_SIZE > 40960);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *esp_heap_runtime_malloc(size_t size)
|
|
||||||
{
|
|
||||||
return k_heap_alloc(&esp_heap_runtime, size, K_NO_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *esp_heap_runtime_calloc(size_t n, size_t size)
|
|
||||||
{
|
|
||||||
size_t sz;
|
|
||||||
|
|
||||||
if (__builtin_mul_overflow(n, size, &sz)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
void *ptr = k_heap_alloc(&esp_heap_runtime, sz, K_NO_WAIT);
|
|
||||||
|
|
||||||
if (ptr) {
|
|
||||||
memset(ptr, 0, sz);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *esp_heap_runtime_realloc(void *ptr, size_t bytes)
|
|
||||||
{
|
|
||||||
return k_heap_realloc(&esp_heap_runtime, ptr, bytes, K_NO_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void esp_heap_runtime_free(void *mem)
|
|
||||||
{
|
|
||||||
k_heap_free(&esp_heap_runtime, mem);
|
|
||||||
}
|
|
||||||
|
|
||||||
SYS_INIT(esp_heap_runtime_init, PRE_KERNEL_2, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
|
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Allocate memory from the esp_heap_runtime.
|
|
||||||
*
|
|
||||||
* @param size Amount of memory requested (in bytes).
|
|
||||||
*
|
|
||||||
* @return Address of the allocated memory if successful; otherwise NULL.
|
|
||||||
*/
|
|
||||||
void *esp_heap_runtime_malloc(size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Allocate memory from esp_heap_runtime, array style
|
|
||||||
*
|
|
||||||
* @param n Number of elements in the requested array
|
|
||||||
* @param size Size of each array element (in bytes).
|
|
||||||
*
|
|
||||||
* @return Address of the allocated memory if successful; otherwise NULL.
|
|
||||||
*/
|
|
||||||
void *esp_heap_runtime_calloc(size_t n, size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Reallocate memory from a esp_heap_runtime
|
|
||||||
*
|
|
||||||
* @param ptr Original pointer returned from a previous allocation
|
|
||||||
* @param bytes Desired size of block to allocate
|
|
||||||
*
|
|
||||||
* @return Pointer to memory the caller can now use, or NULL
|
|
||||||
*/
|
|
||||||
void *esp_heap_runtime_realloc(void *ptr, size_t bytes);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Free memory allocated from esp_heap_runtime.
|
|
||||||
*
|
|
||||||
* If @a ptr is NULL, no operation is performed.
|
|
||||||
*
|
|
||||||
* @param ptr Pointer to previously allocated memory.
|
|
||||||
*/
|
|
||||||
void esp_heap_runtime_free(void *mem);
|
|
|
@ -74,6 +74,7 @@ static HDR_ATTR void (*_entry_point)(void) = &__start;
|
||||||
esp_image_header_t WORD_ALIGNED_ATTR bootloader_image_hdr;
|
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_irom_start, _image_irom_size, _image_irom_vaddr;
|
||||||
extern uint32_t _image_drom_start, _image_drom_size, _image_drom_vaddr;
|
extern uint32_t _image_drom_start, _image_drom_size, _image_drom_vaddr;
|
||||||
|
extern uint32_t _libc_heap_size;
|
||||||
|
|
||||||
#ifndef CONFIG_MCUBOOT
|
#ifndef CONFIG_MCUBOOT
|
||||||
static uint32_t _app_irom_start =
|
static uint32_t _app_irom_start =
|
||||||
|
@ -84,6 +85,7 @@ static uint32_t _app_drom_start =
|
||||||
(FIXED_PARTITION_OFFSET(slot0_partition) + (uint32_t)&_image_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 _app_drom_size = (uint32_t)&_image_drom_size;
|
||||||
|
|
||||||
|
static uint32_t libc_heap_size = (uint32_t)&_libc_heap_size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint32_t _app_irom_vaddr = ((uint32_t)&_image_irom_vaddr);
|
static uint32_t _app_irom_vaddr = ((uint32_t)&_image_irom_vaddr);
|
||||||
|
@ -260,7 +262,7 @@ void __start(void)
|
||||||
".option norelax\n"
|
".option norelax\n"
|
||||||
"la gp, __global_pointer$\n"
|
"la gp, __global_pointer$\n"
|
||||||
".option pop");
|
".option pop");
|
||||||
#endif /* CONFIG_RISCV_GP */
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_BOOTLOADER_MCUBOOT
|
#ifndef CONFIG_BOOTLOADER_MCUBOOT
|
||||||
/* Init fundamental components */
|
/* Init fundamental components */
|
||||||
|
@ -278,12 +280,14 @@ void __start(void)
|
||||||
#ifndef CONFIG_SOC_SERIES_ESP32C2
|
#ifndef CONFIG_SOC_SERIES_ESP32C2
|
||||||
/* Disable RNG entropy source as it was already used */
|
/* Disable RNG entropy source as it was already used */
|
||||||
soc_random_disable();
|
soc_random_disable();
|
||||||
#endif /* CONFIG_SOC_SERIES_ESP32C2 */
|
#endif
|
||||||
#if defined(CONFIG_SOC_SERIES_ESP32S3) || defined(CONFIG_SOC_SERIES_ESP32C3)
|
#if defined(CONFIG_SOC_SERIES_ESP32S3) || defined(CONFIG_SOC_SERIES_ESP32C3)
|
||||||
/* Disable glitch detection as it can be falsely triggered by EMI interference */
|
/* Disable glitch detection as it can be falsely triggered by EMI interference */
|
||||||
ESP_EARLY_LOGI(TAG, "Disabling glitch detection");
|
ESP_EARLY_LOGI(TAG, "Disabling glitch detection");
|
||||||
ana_clock_glitch_reset_config(false);
|
ana_clock_glitch_reset_config(false);
|
||||||
#endif /* CONFIG_SOC_SERIES_ESP32S2 */
|
#endif
|
||||||
ESP_EARLY_LOGI(TAG, "Jumping to the main image...");
|
#if !defined(CONFIG_MCUBOOT)
|
||||||
|
ESP_EARLY_LOGI(TAG, "libc heap size %d kB.", libc_heap_size / 1024);
|
||||||
|
#endif
|
||||||
__esp_platform_start();
|
__esp_platform_start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,9 @@ _rom_store_table = 0;
|
||||||
PROVIDE(_memmap_vecbase_reset = 0x40000450);
|
PROVIDE(_memmap_vecbase_reset = 0x40000450);
|
||||||
PROVIDE(_memmap_reset_vector = 0x40000400);
|
PROVIDE(_memmap_reset_vector = 0x40000400);
|
||||||
|
|
||||||
|
/* Heap size calculations for PROCPU is also valid for AMP scenario */
|
||||||
_heap_sentry = SRAM2_DRAM_END;
|
_heap_sentry = SRAM2_DRAM_END;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,7 +72,9 @@ _rom_store_table = 0;
|
||||||
PROVIDE(_memmap_vecbase_reset = 0x40000450);
|
PROVIDE(_memmap_vecbase_reset = 0x40000450);
|
||||||
PROVIDE(_memmap_reset_vector = 0x40000400);
|
PROVIDE(_memmap_reset_vector = 0x40000400);
|
||||||
|
|
||||||
|
/* Heap size calculations for APPCPU */
|
||||||
_heap_sentry = BOOTLOADER_DRAM_SEG_START + APPCPU_DRAM_SIZE;
|
_heap_sentry = BOOTLOADER_DRAM_SEG_START + APPCPU_DRAM_SIZE;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,8 +85,9 @@ _rom_store_table = 0;
|
||||||
|
|
||||||
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
||||||
|
|
||||||
/* Used as a pointer to the heap end */
|
/* Heap size calculations */
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,8 +98,9 @@ _rom_store_table = 0;
|
||||||
|
|
||||||
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
||||||
|
|
||||||
/* Stack sentry */
|
/* Heap size calculations */
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,7 +100,9 @@ REGION_ALIAS("rtc_data_location", rtc_iram_seg );
|
||||||
/* Default entry point: */
|
/* Default entry point: */
|
||||||
ENTRY(CONFIG_KERNEL_ENTRY)
|
ENTRY(CONFIG_KERNEL_ENTRY)
|
||||||
|
|
||||||
|
/* Heap size calculations */
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -105,6 +105,7 @@ _rom_store_table = 0;
|
||||||
|
|
||||||
/* Used as a pointer to the heap end */
|
/* Used as a pointer to the heap end */
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,13 +102,15 @@ MEMORY
|
||||||
/* Default entry point: */
|
/* Default entry point: */
|
||||||
ENTRY(CONFIG_KERNEL_ENTRY)
|
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
|
#ifdef CONFIG_SOC_ENABLE_APPCPU
|
||||||
_heap_sentry = procpu_dram_end;
|
_heap_sentry = procpu_dram_end;
|
||||||
#else
|
#else
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
_iram_dram_offset = IRAM_DRAM_OFFSET;
|
||||||
|
|
|
@ -66,8 +66,9 @@ MEMORY
|
||||||
/* Default entry point: */
|
/* Default entry point: */
|
||||||
ENTRY(__appcpu_start)
|
ENTRY(__appcpu_start)
|
||||||
|
|
||||||
/* Used as a pointer to the heap end */
|
/* Heap size calculations for APPCPU */
|
||||||
_heap_sentry = DRAM_RESERVED_START;
|
_heap_sentry = DRAM_RESERVED_START;
|
||||||
|
_libc_heap_size = _heap_sentry - _end;
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue