From f94c221a9ac8b81bd801071203f1a5bf06c5c9ab Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 10 Aug 2021 11:10:52 +0200 Subject: [PATCH] Increase task wdt timeout for ESP32/ESP32-C3 (#2096) --- esphome/core/application.cpp | 8 ++------ esphome/core/application.h | 2 ++ esphome/core/application_esp32.cpp | 21 +++++++++++++++++++++ esphome/core/application_esp8266.cpp | 12 ++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 esphome/core/application_esp32.cpp create mode 100644 esphome/core/application_esp8266.cpp diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index 17a2725de5..1a3158e4ce 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -53,6 +53,7 @@ void Application::setup() { } this->app_state_ = new_app_state; yield(); + this->feed_wdt(); } while (!component->can_proceed()); } @@ -117,12 +118,7 @@ void ICACHE_RAM_ATTR HOT Application::feed_wdt() { static uint32_t LAST_FEED = 0; uint32_t now = millis(); if (now - LAST_FEED > 3) { -#ifdef ARDUINO_ARCH_ESP8266 - ESP.wdtFeed(); -#endif -#ifdef ARDUINO_ARCH_ESP32 - yield(); -#endif + this->feed_wdt_arch_(); LAST_FEED = now; #ifdef USE_STATUS_LED if (status_led::global_status_led != nullptr) { diff --git a/esphome/core/application.h b/esphome/core/application.h index edbfbd130b..e5f686a320 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -250,6 +250,8 @@ class Application { void calculate_looping_components_(); + void feed_wdt_arch_(); + std::vector components_{}; std::vector looping_components_{}; diff --git a/esphome/core/application_esp32.cpp b/esphome/core/application_esp32.cpp new file mode 100644 index 0000000000..9f084428bb --- /dev/null +++ b/esphome/core/application_esp32.cpp @@ -0,0 +1,21 @@ +#include "esphome/core/application.h" + +#ifdef ARDUINO_ARCH_ESP32 + +namespace esphome { + +static const char *const TAG = "app_esp32"; + +void ICACHE_RAM_ATTR HOT Application::feed_wdt_arch_() { +#if CONFIG_ARDUINO_RUNNING_CORE == 0 +#ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 + // ESP32 uses "Task Watchdog" which is hooked to the FreeRTOS idle task. + // To cause the Watchdog to be triggered we need to put the current task + // to sleep to get the idle task scheduled. + delay(1); +#endif +#endif +} + +} // namespace esphome +#endif diff --git a/esphome/core/application_esp8266.cpp b/esphome/core/application_esp8266.cpp new file mode 100644 index 0000000000..95139ca112 --- /dev/null +++ b/esphome/core/application_esp8266.cpp @@ -0,0 +1,12 @@ +#include "esphome/core/application.h" + +#ifdef ARDUINO_ARCH_ESP8266 + +namespace esphome { + +static const char *const TAG = "app_esp8266"; + +void ICACHE_RAM_ATTR HOT Application::feed_wdt_arch_() { ESP.wdtFeed(); } + +} // namespace esphome +#endif