diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index fa1cf9a918..7d7c0ff0ab 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -560,4 +560,22 @@ menu "OpenThread" failure. endmenu + menuconfig OPENTHREAD_DEBUG + bool "Enable ESP OpenThread Debug" + default n + help + Enable additional debugging support for ESP OpenThread integration. + This includes various diagnostic tools and logs to help track down + issues in OpenThread networking or system integration + + config OPENTHREAD_DUMP_MAC_ON_ASSERT + bool "Dump 802.15.4 MAC debug info on OpenThread assert" + depends on OPENTHREAD_DEBUG && OPENTHREAD_RADIO_NATIVE && IEEE802154_DEBUG + default n + help + When enabled, this option triggers the printing of 802.15.4 MAC layer debug + information whenever an OpenThread assert occurs. This can help developers + analyze unexpected failures by providing additional MAC layer context. + + endmenu diff --git a/components/openthread/private_include/esp_openthread_common_macro.h b/components/openthread/private_include/esp_openthread_common_macro.h index 354ea5128c..8595bc7684 100644 --- a/components/openthread/private_include/esp_openthread_common_macro.h +++ b/components/openthread/private_include/esp_openthread_common_macro.h @@ -1,11 +1,13 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once +#include "sdkconfig.h" + #define OT_PLAT_LOG_TAG "OPENTHREAD" #ifndef MS_PER_S @@ -21,3 +23,22 @@ #endif #define ESP_OPENTHREAD_UART_BUFFER_SIZE CONFIG_OPENTHREAD_UART_BUFFER_SIZE + +#if CONFIG_OPENTHREAD_DEBUG + +#if CONFIG_OPENTHREAD_DUMP_MAC_ON_ASSERT && CONFIG_IEEE802154_RECORD +#include "esp_ieee802154.h" +#define IEEE802154_RECORD_PRINT() esp_ieee802154_record_print() +#else +#define IEEE802154_RECORD_PRINT() +#endif + +#define ESP_OPENTHREAD_ASSERT(a) do { \ + if(unlikely(!(a))) { \ + IEEE802154_RECORD_PRINT(); \ + assert(a); \ + } \ + } while (0) +#else +#define ESP_OPENTHREAD_ASSERT(a) assert(a) +#endif diff --git a/components/openthread/src/port/esp_openthread_misc.c b/components/openthread/src/port/esp_openthread_misc.c index 95ac612a6a..a1d550b53d 100644 --- a/components/openthread/src/port/esp_openthread_misc.c +++ b/components/openthread/src/port/esp_openthread_misc.c @@ -76,5 +76,5 @@ otPlatMcuPowerState otPlatGetMcuPowerState(otInstance *instance) void otPlatAssertFail(const char *filename, int line) { ESP_LOGE(OT_PLAT_LOG_TAG, "Assert failed at %s:%d", filename, line); - assert(false); + ESP_OPENTHREAD_ASSERT(false); }