From 33fbf82bdd6b3480a4b8ba3ae6ec45d4a4f534b9 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 7 Aug 2026 15:22:55 +0800 Subject: [PATCH] fix(openthread): fix configuration-related issues --- components/openthread/Kconfig | 13 ++++++------- components/openthread/src/esp_openthread.cpp | 2 ++ .../multiple_instances/esp_openthread_instance.cpp | 5 ++++- .../src/port/esp_openthread_messagepool.c | 2 ++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index 96973e38f25..a61b90abb95 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -333,7 +333,7 @@ menu "OpenThread" bool "Enable link metrics feature" default n select IEEE802154_TIMING_OPTIMIZATION if IEEE802154_ENABLED - select OPENTHREAD_TIMING_OPTIMIZATION + select OPENTHREAD_TIMING_OPTIMIZATION if OPENTHREAD_RADIO_NATIVE help Select this option to enable link metrics feature @@ -437,17 +437,16 @@ menu "OpenThread" endmenu menu "Thread Memory Allocation" - depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC) config OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM + depends on (SPIRAM_USE_CAPS_ALLOC || SPIRAM_USE_MALLOC) bool 'Allocate memory from PSRAM' default y help Select this option to allocate buffer from PSRAM for Thread config OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT - bool 'Allocate message pool buffer from PSRAM' - depends on OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM - default y + bool 'Allocate message pool buffer from platform' + default n help If enabled, the message pool is managed by platform defined logic. endmenu @@ -481,8 +480,8 @@ menu "OpenThread" config OPENTHREAD_NUM_MESSAGE_BUFFERS int "The number of openthread message buffers" - default 65 if !OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT - default 1024 if OPENTHREAD_PLATFORM_MSGPOOL_MANAGEMENT + default 65 if !OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM + default 1024 if OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM config OPENTHREAD_XTAL_ACCURACY int "The accuracy of the XTAL" diff --git a/components/openthread/src/esp_openthread.cpp b/components/openthread/src/esp_openthread.cpp index 8bb8fe58659..2fea58c0750 100644 --- a/components/openthread/src/esp_openthread.cpp +++ b/components/openthread/src/esp_openthread.cpp @@ -241,7 +241,9 @@ esp_err_t esp_openthread_launch_mainloop(void) esp_err_t esp_openthread_deinit(void) { + esp_openthread_lock_acquire(portMAX_DELAY); esp_openthread_instances_deinit(esp_openthread_get_instance()); + esp_openthread_lock_release(); return esp_openthread_platform_deinit(); } diff --git a/components/openthread/src/multiple_instances/esp_openthread_instance.cpp b/components/openthread/src/multiple_instances/esp_openthread_instance.cpp index e19e5f7b44e..133eec44cf1 100644 --- a/components/openthread/src/multiple_instances/esp_openthread_instance.cpp +++ b/components/openthread/src/multiple_instances/esp_openthread_instance.cpp @@ -30,7 +30,10 @@ bool esp_openthread_instances_init(void) void esp_openthread_instances_deinit(otInstance *instance) { - otInstanceFinalize(instance); + (void)instance; + for (int i = 0; i < OT_INSTANCE_COUNT; i++) { + otInstanceFinalize(s_instances[i]); + } } bool esp_openthread_tasklets_are_pending(otInstance *instance) diff --git a/components/openthread/src/port/esp_openthread_messagepool.c b/components/openthread/src/port/esp_openthread_messagepool.c index 37046033494..0e2372ae247 100644 --- a/components/openthread/src/port/esp_openthread_messagepool.c +++ b/components/openthread/src/port/esp_openthread_messagepool.c @@ -28,11 +28,13 @@ void otPlatMessagePoolInit(otInstance *aInstance, uint16_t aMinNumFreeBuffers, s uint16_t num_buffers = aMinNumFreeBuffers; +#if CONFIG_OPENTHREAD_PLATFORM_MALLOC_CAP_SPIRAM if (!esp_psram_is_initialized() && num_buffers > OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM) { ESP_LOGW(OT_PLAT_LOG_TAG, "PSRAM not available, reducing message pool from %u to %u buffers", num_buffers, OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM); num_buffers = OT_MSGPOOL_NUM_BUFFERS_NO_PSRAM; } +#endif otMessageBuffer *buffer_pool = (otMessageBuffer *)heap_caps_calloc_prefer(num_buffers, aBufferSize, 3, esp_openthread_get_alloc_caps(), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); s_buffer_pool_pointer = (otMessageBuffer **)heap_caps_calloc_prefer(num_buffers, sizeof(otMessageBuffer **), 3, esp_openthread_get_alloc_caps(), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);