diff --git a/components/openthread/src/port/esp_spi_spinel_interface.cpp b/components/openthread/src/port/esp_spi_spinel_interface.cpp index 61d6cfab2f..3a40949169 100644 --- a/components/openthread/src/port/esp_spi_spinel_interface.cpp +++ b/components/openthread/src/port/esp_spi_spinel_interface.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -266,8 +266,8 @@ otError SpiSpinelInterface::WaitForFrame(uint64_t timeout_us) otError SpiSpinelInterface::HardwareReset(void) { if (mRcpFailureHandler) { - ConductSPITransaction(true, 0, 0); // clear mRcpFailureHandler(); + ConductSPITransaction(true, 0, 0); // clear } return OT_ERROR_NONE; } diff --git a/examples/openthread/ot_br/main/Kconfig.projbuild b/examples/openthread/ot_br/main/Kconfig.projbuild index b18168829b..e8d3a95717 100644 --- a/examples/openthread/ot_br/main/Kconfig.projbuild +++ b/examples/openthread/ot_br/main/Kconfig.projbuild @@ -8,6 +8,18 @@ menu "OpenThread Border Router Example" SSID and PSK, and then form a Thread network automatically. Otherwise, user need to configure Wi-Fi and Thread manually. + config OPENTHREAD_SUPPORT_HW_RESET_RCP + bool 'Enable hardware RCP resetting' + default False + help + If enabled, the Thread Border Router will support hardware resetting the RCP + when processing RCP failure. + + config OPENTHREAD_HW_RESET_RCP_PIN + int 'Pin to RCP reset' + depends on OPENTHREAD_SUPPORT_HW_RESET_RCP + default 7 + menu "External coexist wire type and pin config" config EXTERNAL_COEX_WIRE_TYPE int "The wire_type of external coexist" diff --git a/examples/openthread/ot_br/main/esp_ot_br.c b/examples/openthread/ot_br/main/esp_ot_br.c index 46bbc54810..bbd5ae3f0a 100644 --- a/examples/openthread/ot_br/main/esp_ot_br.c +++ b/examples/openthread/ot_br/main/esp_ot_br.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 * @@ -38,6 +38,7 @@ #include "mdns.h" #include "nvs_flash.h" #include "protocol_examples_common.h" +#include "driver/gpio.h" #include "driver/uart.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -62,6 +63,26 @@ #define TAG "esp_ot_br" +#if CONFIG_OPENTHREAD_SUPPORT_HW_RESET_RCP +#define PIN_TO_RCP_RESET CONFIG_OPENTHREAD_HW_RESET_RCP_PIN +static void rcp_failure_hardware_reset_handler(void) +{ + gpio_config_t reset_pin_config; + memset(&reset_pin_config, 0, sizeof(reset_pin_config)); + reset_pin_config.intr_type = GPIO_INTR_DISABLE; + reset_pin_config.pin_bit_mask = BIT(PIN_TO_RCP_RESET); + reset_pin_config.mode = GPIO_MODE_OUTPUT; + reset_pin_config.pull_down_en = GPIO_PULLDOWN_DISABLE; + reset_pin_config.pull_up_en = GPIO_PULLUP_DISABLE; + gpio_config(&reset_pin_config); + gpio_set_level(PIN_TO_RCP_RESET, 0); + vTaskDelay(pdMS_TO_TICKS(10)); + gpio_set_level(PIN_TO_RCP_RESET, 1); + vTaskDelay(pdMS_TO_TICKS(30)); + gpio_reset_pin(PIN_TO_RCP_RESET); +} +#endif + #if CONFIG_EXTERNAL_COEX_ENABLE static void ot_br_external_coexist_init(void) { @@ -192,6 +213,9 @@ void app_main(void) ESP_ERROR_CHECK(nvs_flash_init()); ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); +#if CONFIG_OPENTHREAD_SUPPORT_HW_RESET_RCP + esp_openthread_register_rcp_failure_handler(rcp_failure_hardware_reset_handler); +#endif xTaskCreate(ot_task_worker, "ot_br_main", 8192, xTaskGetCurrentTaskHandle(), 5, NULL); xTaskCreate(ot_br_init, "ot_br_init", 6144, NULL, 4, NULL); } diff --git a/examples/openthread/ot_br/sdkconfig.ci.br b/examples/openthread/ot_br/sdkconfig.ci.br index e69de29bb2..ceb3c1a0a0 100644 --- a/examples/openthread/ot_br/sdkconfig.ci.br +++ b/examples/openthread/ot_br/sdkconfig.ci.br @@ -0,0 +1,2 @@ +CONFIG_OPENTHREAD_SUPPORT_HW_RESET_RCP=y +CONFIG_OPENTHREAD_HW_RESET_RCP_PIN=6 diff --git a/examples/openthread/ot_br/sdkconfig.ci.br_spi b/examples/openthread/ot_br/sdkconfig.ci.br_spi index 1778799eb7..7afe286169 100644 --- a/examples/openthread/ot_br/sdkconfig.ci.br_spi +++ b/examples/openthread/ot_br/sdkconfig.ci.br_spi @@ -1 +1,3 @@ CONFIG_OPENTHREAD_RADIO_SPINEL_SPI=y +CONFIG_OPENTHREAD_SUPPORT_HW_RESET_RCP=y +CONFIG_OPENTHREAD_HW_RESET_RCP_PIN=7