mirror of
https://github.com/esphome/esphome.git
synced 2024-11-09 16:57:47 +01:00
Set ESP32 watchdog to loop task (#2846)
This commit is contained in:
parent
607601b3a4
commit
54106179a1
6 changed files with 35 additions and 15 deletions
|
@ -311,9 +311,16 @@ async def to_code(config):
|
||||||
)
|
)
|
||||||
add_idf_sdkconfig_option("CONFIG_COMPILER_OPTIMIZATION_DEFAULT", False)
|
add_idf_sdkconfig_option("CONFIG_COMPILER_OPTIMIZATION_DEFAULT", False)
|
||||||
add_idf_sdkconfig_option("CONFIG_COMPILER_OPTIMIZATION_SIZE", True)
|
add_idf_sdkconfig_option("CONFIG_COMPILER_OPTIMIZATION_SIZE", True)
|
||||||
|
|
||||||
# Increase freertos tick speed from 100Hz to 1kHz so that delay() resolution is 1ms
|
# Increase freertos tick speed from 100Hz to 1kHz so that delay() resolution is 1ms
|
||||||
add_idf_sdkconfig_option("CONFIG_FREERTOS_HZ", 1000)
|
add_idf_sdkconfig_option("CONFIG_FREERTOS_HZ", 1000)
|
||||||
|
|
||||||
|
# Setup watchdog
|
||||||
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT", True)
|
||||||
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_PANIC", True)
|
||||||
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0", False)
|
||||||
|
add_idf_sdkconfig_option("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1", False)
|
||||||
|
|
||||||
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
cg.add_platformio_option("board_build.partitions", "partitions.csv")
|
||||||
|
|
||||||
for name, value in conf[CONF_SDKCONFIG_OPTIONS].items():
|
for name, value in conf[CONF_SDKCONFIG_OPTIONS].items():
|
||||||
|
|
|
@ -6,12 +6,17 @@
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
#include <esp_idf_version.h>
|
#include <esp_idf_version.h>
|
||||||
|
#include <esp_task_wdt.h>
|
||||||
#include <soc/rtc.h>
|
#include <soc/rtc.h>
|
||||||
|
|
||||||
#if ESP_IDF_VERSION_MAJOR >= 4
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
||||||
#include <hal/cpu_hal.h>
|
#include <hal/cpu_hal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USE_ARDUINO
|
||||||
|
#include <esp32-hal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
|
@ -29,24 +34,24 @@ void arch_restart() {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void IRAM_ATTR HOT arch_feed_wdt() {
|
|
||||||
#ifdef USE_ARDUINO
|
|
||||||
#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
|
|
||||||
#endif // USE_ARDUINO
|
|
||||||
|
|
||||||
#ifdef USE_ESP_IDF
|
void arch_init() {
|
||||||
#ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0
|
// Enable the task watchdog only on the loop task (from which we're currently running)
|
||||||
delay(1);
|
#if defined(USE_ESP_IDF)
|
||||||
|
esp_task_wdt_add(nullptr);
|
||||||
|
// Idle task watchdog is disabled on ESP-IDF
|
||||||
|
#elif defined(USE_ARDUINO)
|
||||||
|
enableLoopWDT();
|
||||||
|
// Disable idle task watchdog on the core we're using (Arduino pins the process to a core)
|
||||||
|
#if CONFIG_ARDUINO_RUNNING_CORE == 0
|
||||||
|
disableCore0WDT();
|
||||||
|
#endif
|
||||||
|
#if CONFIG_ARDUINO_RUNNING_CORE == 1
|
||||||
|
disableCore1WDT();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif // USE_ESP_IDF
|
|
||||||
}
|
}
|
||||||
|
void IRAM_ATTR HOT arch_feed_wdt() { esp_task_wdt_reset(); }
|
||||||
|
|
||||||
uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
|
uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
|
||||||
uint32_t arch_get_cpu_cycle_count() {
|
uint32_t arch_get_cpu_cycle_count() {
|
||||||
|
|
|
@ -20,6 +20,7 @@ void arch_restart() {
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void arch_init() {}
|
||||||
void IRAM_ATTR HOT arch_feed_wdt() {
|
void IRAM_ATTR HOT arch_feed_wdt() {
|
||||||
ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance)
|
ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "esphome/core/defines.h"
|
#include "esphome/core/defines.h"
|
||||||
#include "esphome/core/preferences.h"
|
#include "esphome/core/preferences.h"
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/hal.h"
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/scheduler.h"
|
#include "esphome/core/scheduler.h"
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ namespace esphome {
|
||||||
class Application {
|
class Application {
|
||||||
public:
|
public:
|
||||||
void pre_setup(const std::string &name, const char *compilation_time, bool name_add_mac_suffix) {
|
void pre_setup(const std::string &name, const char *compilation_time, bool name_add_mac_suffix) {
|
||||||
|
arch_init();
|
||||||
this->name_add_mac_suffix_ = name_add_mac_suffix;
|
this->name_add_mac_suffix_ = name_add_mac_suffix;
|
||||||
if (name_add_mac_suffix) {
|
if (name_add_mac_suffix) {
|
||||||
this->name_ = name + "-" + get_mac_address().substr(6);
|
this->name_ = name + "-" + get_mac_address().substr(6);
|
||||||
|
|
|
@ -39,6 +39,7 @@ uint32_t micros();
|
||||||
void delay(uint32_t ms);
|
void delay(uint32_t ms);
|
||||||
void delayMicroseconds(uint32_t us); // NOLINT(readability-identifier-naming)
|
void delayMicroseconds(uint32_t us); // NOLINT(readability-identifier-naming)
|
||||||
void __attribute__((noreturn)) arch_restart();
|
void __attribute__((noreturn)) arch_restart();
|
||||||
|
void arch_init();
|
||||||
void arch_feed_wdt();
|
void arch_feed_wdt();
|
||||||
uint32_t arch_get_cpu_cycle_count();
|
uint32_t arch_get_cpu_cycle_count();
|
||||||
uint32_t arch_get_cpu_freq_hz();
|
uint32_t arch_get_cpu_freq_hz();
|
||||||
|
|
|
@ -9,6 +9,10 @@ CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
#CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
#CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
|
||||||
CONFIG_PARTITION_TABLE_SINGLE_APP=n
|
CONFIG_PARTITION_TABLE_SINGLE_APP=n
|
||||||
CONFIG_FREERTOS_HZ=1000
|
CONFIG_FREERTOS_HZ=1000
|
||||||
|
CONFIG_ESP_TASK_WDT=y
|
||||||
|
CONFIG_ESP_TASK_WDT_PANIC=y
|
||||||
|
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
|
||||||
|
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
|
||||||
|
|
||||||
# esp32_ble
|
# esp32_ble
|
||||||
CONFIG_BT_ENABLED=y
|
CONFIG_BT_ENABLED=y
|
||||||
|
|
Loading…
Reference in a new issue