From 7e09c54490fb0ea49c3456e3963475920d467226 Mon Sep 17 00:00:00 2001 From: oarcher Date: Wed, 17 Jul 2024 13:55:00 +0200 Subject: [PATCH] increase / restore WDT --- esphome/components/modem/__init__.py | 1 - esphome/components/modem/modem_component.cpp | 22 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/esphome/components/modem/__init__.py b/esphome/components/modem/__init__.py index 9936dcc7eb..3fe3fda6df 100644 --- a/esphome/components/modem/__init__.py +++ b/esphome/components/modem/__init__.py @@ -74,7 +74,6 @@ async def to_code(config): ) add_idf_sdkconfig_option("CONFIG_LWIP_DHCPS", False) - add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_TIMEOUT_S", 60) add_idf_sdkconfig_option("CONFIG_PPP", True) add_idf_sdkconfig_option("CONFIG_LWIP_PPP_SUPPORT", True) add_idf_sdkconfig_option("CONFIG_PPP_PAP_SUPPORT", True) diff --git a/esphome/components/modem/modem_component.cpp b/esphome/components/modem/modem_component.cpp index c86698669c..1cfa198fea 100644 --- a/esphome/components/modem/modem_component.cpp +++ b/esphome/components/modem/modem_component.cpp @@ -14,6 +14,8 @@ #include #include #include +#include "esp_idf_version.h" +#include "esp_task_wdt.h" static const size_t CONFIG_MODEM_UART_RX_BUFFER_SIZE = 2048; static const size_t CONFIG_MODEM_UART_TX_BUFFER_SIZE = 1024; @@ -50,6 +52,19 @@ std::string command_result_to_string(command_result err) { return res; } +void set_wdt(uint32_t timeout_s) { +#if ESP_IDF_VERSION_MAJOR >= 5 + esp_task_wdt_config_t wdt_config = { + .timeout_ms = timeout_s * 1000, + .idle_core_mask = 0x03, + .trigger_panic = true, + }; + esp_task_wdt_reconfigure(&wdt_config); +#else + esp_task_wdt_init(timeout_s, true); +#endif // ESP_IDF_VERSION_MAJOR +} + ModemComponent::ModemComponent() { global_modem_component = this; } void ModemComponent::dump_config() { ESP_LOGCONFIG(TAG, "Config Modem:"); } @@ -86,6 +101,8 @@ bool ModemComponent::is_connected() { return this->state_ == ModemComponentState void ModemComponent::setup() { ESP_LOGI(TAG, "Setting up Modem..."); + // increase WDT, because setup and start_connect take some time. + set_wdt(60); ESP_LOGV(TAG, "DTE setup"); esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG(); @@ -162,10 +179,13 @@ void ModemComponent::setup() { assert(this->dce); this->started_ = true; + + set_wdt(CONFIG_ESP_TASK_WDT_TIMEOUT_S); ESP_LOGV(TAG, "Setup finished"); } void ModemComponent::start_connect_() { + set_wdt(60); this->connect_begin_ = millis(); this->status_set_warning("Starting connection"); @@ -217,6 +237,8 @@ void ModemComponent::start_connect_() { ESP_LOGI(TAG, "'init_at' '%s' result: %s", cmd.c_str(), result.c_str()); } } + // restore WDT + set_wdt(CONFIG_ESP_TASK_WDT_TIMEOUT_S); } void ModemComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {