esp-idf/examples/system/task_watchdog
2023-10-19 10:10:37 +08:00
..
main WDT: implement interrupt wdt and task wdt for ESP32-C2 2022-09-15 14:37:59 +08:00
CMakeLists.txt tools: Increase the minimal supported CMake version to 3.16 2022-06-01 06:35:02 +00:00
pytest_task_watchdog.py ci(system): restrict number of system examples built in regular pipelines 2023-10-19 10:10:37 +08:00
README.md feat(ci): Enable p4 example, test_apps and unit tests CI build 2023-08-24 12:51:19 +08:00
sdkconfig.ci example_tests: Deletes usage esp32c3 ECO0 in CI (by default ECO3) 2021-09-24 13:55:07 +08:00

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-C6 ESP32-H2 ESP32-P4 ESP32-S2 ESP32-S3

Task Watchdog Example

The following example demonstrates how to use the following features of the task watchdog timer (TWDT):

  • How to initialize and deinitialize the TWDT
  • How to subscribe and unsubscribe tasks to the TWDT
  • How to subscribe and unsubscribe users to the TWDT
  • How to tasks and users can reset (i.e., feed) the TWDT

How to use example

Before project configuration and build, be sure to set the correct chip target using idf.py set-target <chip_name>.

Hardware Required

  • A development board with ESP32-S or ESP32-C series chip
  • A USB cable for Power supply and programming

Configure the project

Program should run correctly without needing any special configuration. However, users can disable CONFIG_ESP_TASK_WDT_INIT which will prevent the TWDT from being automatically initialized on startup. If disabled, the example will manually initialize the TWDT.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

Run idf.py -p PORT flash monitor to build, flash and monitor the project.

(To exit the serial monitor, type Ctrl-].)

See the ESP-IDF Getting Started Guide for all the steps to configure and use the ESP-IDF to build projects.

Example Output

When the example runs normally, the following output will be observed:

I (316) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
TWDT initialized
Subscribed to TWDT
Delay for 10 seconds
Unsubscribed from TWDT
TWDT deinitialized
Example complete

Users can comment out any of the esp_task_wdt_reset() or esp_task_wdt_reset_user() calls to trigger the TWDT, which in turn will result in the following output:

I (316) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
TWDT initialized
Subscribed to TWDT
Delay for 10 seconds
E (6326) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (6326) task_wdt:  - task (CPU 0)
E (6326) task_wdt: Tasks currently running:
E (6326) task_wdt: CPU 0: IDLE
E (6326) task_wdt: CPU 1: IDLE
E (6326) task_wdt: Print CPU 0 (current core) backtrace

Troubleshooting

For any technical queries, please open an issue on GitHub. We will get back to you soon.