2022-10-27 06:55:07 -04:00
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- |
2022-07-12 22:41:36 -04:00
2021-02-05 12:49:28 -05:00
# Task Watchdog Example
2017-10-09 06:07:30 -04:00
2022-04-14 06:56:02 -04:00
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
2017-10-09 06:07:30 -04:00
2021-02-05 12:49:28 -05:00
## How to use example
2017-10-09 06:07:30 -04:00
2021-02-05 12:49:28 -05:00
Before project configuration and build, be sure to set the correct chip target using `idf.py set-target <chip_name>` .
2017-10-09 06:07:30 -04:00
2021-02-05 12:49:28 -05:00
### Hardware Required
2017-10-09 06:07:30 -04:00
2021-06-14 23:51:31 -04:00
* A development board with ESP32-S or ESP32-C series chip
2021-02-05 12:49:28 -05:00
* A USB cable for Power supply and programming
### Configure the project
2022-08-23 05:58:14 -04:00
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.
2021-02-05 12:49:28 -05:00
### 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-]``.)
2021-06-14 23:51:31 -04:00
See the [ESP-IDF Getting Started Guide ](https://idf.espressif.com/ ) for all the steps to configure and use the ESP-IDF to build projects.
2021-02-05 12:49:28 -05:00
## Example Output
2022-04-14 06:56:02 -04:00
When the example runs normally, the following output will be observed:
2021-02-05 12:49:28 -05:00
```
2022-04-14 06:56:02 -04:00
I (316) cpu_start: Starting scheduler on PRO CPU.
2021-02-05 12:49:28 -05:00
I (0) cpu_start: Starting scheduler on APP CPU.
2022-04-14 06:56:02 -04:00
TWDT initialized
Subscribed to TWDT
2021-02-05 12:49:28 -05:00
Delay for 10 seconds
2022-04-14 06:56:02 -04:00
Unsubscribed from TWDT
TWDT deinitialized
Example complete
2021-02-05 12:49:28 -05:00
```
2022-04-14 06:56:02 -04:00
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:
2021-02-05 12:49:28 -05:00
```
2022-04-14 06:56:02 -04:00
I (316) cpu_start: Starting scheduler on PRO CPU.
2021-02-05 12:49:28 -05:00
I (0) cpu_start: Starting scheduler on APP CPU.
2022-04-14 06:56:02 -04:00
TWDT initialized
Subscribed to TWDT
2021-02-05 12:49:28 -05:00
Delay for 10 seconds
2022-04-14 06:56:02 -04:00
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
2021-02-05 12:49:28 -05:00
```
## Troubleshooting
For any technical queries, please open an [issue ](https://github.com/espressif/esp-idf/issues ) on GitHub. We will get back to you soon.