Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/bluetooth/hci/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ config BT_AIROC
Infineon's AIROC™ Wi-Fi & combos portfolio integrates
IEEE 802.11a/b/g/n/ac/ax Wi-Fi and Bluetooth® 5.2 in a single-chip
solution to enable small-form-factor IoT designs.
source "drivers/bluetooth/hci/Kconfig.esp32"
source "drivers/bluetooth/hci/Kconfig.infineon"
source "drivers/bluetooth/hci/Kconfig.nxp"

Expand Down
19 changes: 19 additions & 0 deletions drivers/bluetooth/hci/Kconfig.esp32
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

if BT_ESP32

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

config ESP_BT_HEAP_SYSTEM
bool "Bluetooth adapter use system heap"

endchoice # ESP_BT_HEAP

endif
12 changes: 8 additions & 4 deletions drivers/bluetooth/hci/hci_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,19 @@ static int bt_esp32_ble_init(void)
#endif

ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
LOG_ERR("Bluetooth controller init failed %d", ret);
return ret;
if (ret == ESP_ERR_NO_MEM) {
LOG_ERR("Not enough memory to initialize Bluetooth.");
LOG_ERR("Consider increasing CONFIG_HEAP_MEM_POOL_SIZE value.");
return -ENOMEM;
} else if (ret != ESP_OK) {
LOG_ERR("Unable to initialize the Bluetooth: %d", ret);
return -EIO;
}

ret = esp_bt_controller_enable(mode);
if (ret) {
LOG_ERR("Bluetooth controller enable failed: %d", ret);
return ret;
return -EIO;
}

esp_vhci_host_register_callback(&vhci_host_cb);
Expand Down
6 changes: 6 additions & 0 deletions drivers/wifi/esp32/Kconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ menuconfig WIFI_ESP32

if WIFI_ESP32

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

config NET_TCP_WORKQ_STACK_SIZE
default 2048

Expand Down
9 changes: 7 additions & 2 deletions drivers/wifi/esp32/src/esp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,13 @@ static int esp32_wifi_dev_init(const struct device *dev)
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
esp_err_t ret = esp_wifi_init(&config);

if (ret != ESP_OK) {
LOG_ERR("Unable to initialize the wifi");
if (ret == ESP_ERR_NO_MEM) {
LOG_ERR("Not enough memory to initialize Wi-Fi.");
LOG_ERR("Consider increasing CONFIG_HEAP_MEM_POOL_SIZE value.");
return -ENOMEM;
} else if (ret != ESP_OK) {
LOG_ERR("Unable to initialize the Wi-Fi: %d", ret);
return -EIO;
}

if (IS_ENABLED(CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4)) {
Expand Down
6 changes: 2 additions & 4 deletions soc/espressif/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_SOC_SERIES_ESP32 OR CONFIG_SOC_SERIES_ESP32S2 OR CONFIG_SOC_SERIES_ESP32S3)
zephyr_include_directories(include)
endif()
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_SPIRAM psram.c)
zephyr_sources_ifdef(CONFIG_ESP_RUNTIME_HEAP heap.c)
zephyr_sources_ifdef(CONFIG_ESP_HEAP_RUNTIME esp_heap_runtime.c)
endif()
2 changes: 1 addition & 1 deletion soc/espressif/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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_RUNTIME_HEAP
config ESP_HEAP_RUNTIME
bool
default y
help
Expand Down
2 changes: 1 addition & 1 deletion soc/espressif/common/Kconfig.wifi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ choice ESP_WIFI_HEAP

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

config ESP_WIFI_HEAP_SPIRAM
bool "Wifi adapter use SPIRAM heap"
Expand Down
77 changes: 77 additions & 0 deletions soc/espressif/common/esp_heap_runtime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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);
48 changes: 0 additions & 48 deletions soc/espressif/common/heap.c

This file was deleted.

43 changes: 43 additions & 0 deletions soc/espressif/common/include/esp_heap_runtime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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);
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ manifest:
groups:
- hal
- name: hal_espressif
revision: 61a002ad757f567cdef92014b483e6f325c41afc
revision: 5e7220b429caa5d374286b3a3122c5d303c5f78a
path: modules/hal/espressif
west-commands: west/west-commands.yml
groups:
Expand Down