File tree 6 files changed +33
-13
lines changed
6 files changed +33
-13
lines changed Original file line number Diff line number Diff line change @@ -311,9 +311,16 @@ async def to_code(config):
311
311
)
312
312
add_idf_sdkconfig_option ("CONFIG_COMPILER_OPTIMIZATION_DEFAULT" , False )
313
313
add_idf_sdkconfig_option ("CONFIG_COMPILER_OPTIMIZATION_SIZE" , True )
314
+
314
315
# Increase freertos tick speed from 100Hz to 1kHz so that delay() resolution is 1ms
315
316
add_idf_sdkconfig_option ("CONFIG_FREERTOS_HZ" , 1000 )
316
317
318
+ # Setup watchdog
319
+ add_idf_sdkconfig_option ("CONFIG_ESP_TASK_WDT" , True )
320
+ add_idf_sdkconfig_option ("CONFIG_ESP_TASK_WDT_PANIC" , True )
321
+ add_idf_sdkconfig_option ("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0" , False )
322
+ add_idf_sdkconfig_option ("CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1" , False )
323
+
317
324
cg .add_platformio_option ("board_build.partitions" , "partitions.csv" )
318
325
319
326
for name , value in conf [CONF_SDKCONFIG_OPTIONS ].items ():
Original file line number Diff line number Diff line change 6
6
#include < freertos/FreeRTOS.h>
7
7
#include < freertos/task.h>
8
8
#include < esp_idf_version.h>
9
+ #include < esp_task_wdt.h>
9
10
#include < soc/rtc.h>
10
11
11
12
#if ESP_IDF_VERSION_MAJOR >= 4
12
13
#include < hal/cpu_hal.h>
13
14
#endif
14
15
16
+ #ifdef USE_ARDUINO
17
+ #include < esp32-hal.h>
18
+ #endif
19
+
15
20
void setup ();
16
21
void loop ();
17
22
@@ -29,24 +34,24 @@ void arch_restart() {
29
34
yield ();
30
35
}
31
36
}
32
- void IRAM_ATTR HOT arch_feed_wdt () {
33
- #ifdef USE_ARDUINO
37
+
38
+ void arch_init () {
39
+ // Enable the task watchdog only on the loop task (from which we're currently running)
40
+ #if defined(USE_ESP_IDF)
41
+ esp_task_wdt_add (nullptr );
42
+ // Idle task watchdog is disabled on ESP-IDF
43
+ #elif defined(USE_ARDUINO)
44
+ enableLoopWDT ();
45
+ // Disable idle task watchdog on the core we're using (Arduino pins the process to a core)
34
46
#if CONFIG_ARDUINO_RUNNING_CORE == 0
35
- #ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0
36
- // ESP32 uses "Task Watchdog" which is hooked to the FreeRTOS idle task.
37
- // To cause the Watchdog to be triggered we need to put the current task
38
- // to sleep to get the idle task scheduled.
39
- delay (1 );
47
+ disableCore0WDT ();
40
48
#endif
49
+ #if CONFIG_ARDUINO_RUNNING_CORE == 1
50
+ disableCore1WDT ();
41
51
#endif
42
- #endif // USE_ARDUINO
43
-
44
- #ifdef USE_ESP_IDF
45
- #ifdef CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0
46
- delay (1 );
47
52
#endif
48
- #endif // USE_ESP_IDF
49
53
}
54
+ void IRAM_ATTR HOT arch_feed_wdt () { esp_task_wdt_reset (); }
50
55
51
56
uint8_t progmem_read_byte (const uint8_t *addr) { return *addr; }
52
57
uint32_t arch_get_cpu_cycle_count () {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ void arch_restart() {
20
20
yield ();
21
21
}
22
22
}
23
+ void arch_init () {}
23
24
void IRAM_ATTR HOT arch_feed_wdt () {
24
25
ESP.wdtFeed (); // NOLINT(readability-static-accessed-through-instance)
25
26
}
Original file line number Diff line number Diff line change 5
5
#include " esphome/core/defines.h"
6
6
#include " esphome/core/preferences.h"
7
7
#include " esphome/core/component.h"
8
+ #include " esphome/core/hal.h"
8
9
#include " esphome/core/helpers.h"
9
10
#include " esphome/core/scheduler.h"
10
11
@@ -47,6 +48,7 @@ namespace esphome {
47
48
class Application {
48
49
public:
49
50
void pre_setup (const std::string &name, const char *compilation_time, bool name_add_mac_suffix) {
51
+ arch_init ();
50
52
this ->name_add_mac_suffix_ = name_add_mac_suffix;
51
53
if (name_add_mac_suffix) {
52
54
this ->name_ = name + " -" + get_mac_address ().substr (6 );
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ uint32_t micros();
39
39
void delay (uint32_t ms);
40
40
void delayMicroseconds (uint32_t us); // NOLINT(readability-identifier-naming)
41
41
void __attribute__ ((noreturn)) arch_restart();
42
+ void arch_init ();
42
43
void arch_feed_wdt ();
43
44
uint32_t arch_get_cpu_cycle_count ();
44
45
uint32_t arch_get_cpu_freq_hz ();
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ CONFIG_PARTITION_TABLE_CUSTOM=y
9
9
#CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
10
10
CONFIG_PARTITION_TABLE_SINGLE_APP=n
11
11
CONFIG_FREERTOS_HZ=1000
12
+ CONFIG_ESP_TASK_WDT=y
13
+ CONFIG_ESP_TASK_WDT_PANIC=y
14
+ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0=n
15
+ CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
12
16
13
17
# esp32_ble
14
18
CONFIG_BT_ENABLED=y
You can’t perform that action at this time.
0 commit comments