From 31c1f34053b828a595983706b330c592122b1f5b Mon Sep 17 00:00:00 2001 From: zwx Date: Mon, 12 Jan 2026 22:18:17 +0800 Subject: [PATCH] feat(openthread): support openthread heap allocation from PSRAM --- .../openthread-core-esp32x-ftd-config.h | 12 +++++++++++- .../openthread/src/port/esp_openthread_memory.c | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index 0f776479ce..673d030b43 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -99,6 +99,16 @@ #define OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE 0 #endif // CONFIG_OPENTHREAD_RADIO_TREL +#if CONFIG_OPENTHREAD_RADIO_TREL +/** + * @def OPENTHREAD_CONFIG_TREL_USE_HEAP_ENABLE + * + * Set to 1 to allow TREL modules to use heap allocated objects (e.g. for the TREL peer table). + * + */ +#define OPENTHREAD_CONFIG_TREL_USE_HEAP_ENABLE 1 +#endif // CONFIG_OPENTHREAD_RADIO_TREL + /** * @def OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE * diff --git a/components/openthread/src/port/esp_openthread_memory.c b/components/openthread/src/port/esp_openthread_memory.c index 661e62c70e..67c3c6df45 100644 --- a/components/openthread/src/port/esp_openthread_memory.c +++ b/components/openthread/src/port/esp_openthread_memory.c @@ -1,10 +1,11 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "esp_openthread.h" +#include "esp_openthread_platform.h" #include "openthread/platform/memory.h" @@ -12,10 +13,10 @@ void *otPlatCAlloc(size_t num, size_t size) { - return calloc(num, size); + return heap_caps_calloc(num, size, esp_openthread_get_alloc_caps()); } void otPlatFree(void *ptr) { - free(ptr); + heap_caps_free(ptr); }