Page 1 of 1
How to reset the wdt
Posted: Mon Jun 02, 2025 4:15 pm
by HEckardt
Dear Community,
I'm using a ESP32-WROOM-32D together with a Microchip PIC-MCU. ESP32 should work as a SPI-Slave and must wait until the PIC is ready for SPI communication. Therefor I configure the CS-line as a GPIO-Input and wait till the PIC is pulling down this line:
Code: Select all
//code before main loop in "main.c"
while(gpio_get_level(GPIO_CS) == 1)
{
}
//main loop
while(1)
{
}
But when the program is in the "wait loop", I get this output in the Monitor:
E (5307) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (5307) task_wdt: - IDLE (CPU 0)
E (5307) task_wdt: Tasks currently running:
E (5307) task_wdt: CPU 0: main
E (5307) task_wdt: CPU 1: IDLE
E (5307) task_wdt: Print CPU 0 (current core) backtrace
This seems clear, because the wdt is claered in the main loop (I guess). So, I was looking for a solution to reset the wdt and found the function:
"rtc_wdt_feed()"
I add it into the wait_loop:
Code: Select all
while(gpio_get_level(GPIO_CS) == 1)
{
// just for test
if (!gpio_get_level(GPIO_CS))
{
ESP_LOGI(SPIS_Msg, "PIC is ready");
}
rtc_wdt_feed();
}
But it doesn't work.
What is to do to reset the wdt in this situation?
Thank you for your support
Henry
Re: How to reset the wdt
Posted: Mon Jun 02, 2025 7:30 pm
by MicroController
1) Can't you use the SPI peripheral? (
https://github.com/espressif/esp-idf/tr ... /spi_slave)
2) If not, consider using a GPIO interrupt to detect a falling edge on a pin asynchronously.
Btw,
The following tasks/users did not reset the watchdog in time:
E (5307) task_wdt: - IDLE (CPU 0)
means the IDLE task failed to reset its task watchdog, because your code is starving it of all CPU time.
Re: How to reset the wdt
Posted: Mon Jun 02, 2025 8:45 pm
by HEckardt
Hello MC,
yes, I'm able to configure and use the SPI module. But this is not my problem. Your second point could be a solution. I've been thinking about that too. But I want not to spend so much effort for the "Waiting".
I placed the WDT-reset within the "WaitLoop", thatswhy I would expect the reset during the current CPU time, as the reality shows me, this was an error. My assumption is now, that the function "rtc_wdt_feed()" will not reset the wdt in the current task (as you noticed too). But I cannot find another function in the
"esp-idf-en-v5.2-programmingGuide"
So, it would be nice, if you or someone of the community can give me a code-example for resetting the current wdt. Or point to a document, where it is described (for a simple guy like me).
Greetings
Henry
Re: How to reset the wdt
Posted: Mon Jun 02, 2025 9:07 pm
by nopnop2002
Code: Select all
//code before main loop in "main.c"
while(gpio_get_level(GPIO_CS) == 1)
{
vTaskDelay(1);
}
If your main task has priority 0, this is fine.
However, if the main task has a priority of 1 or higher, this will not work.
Code: Select all
//code before main loop in "main.c"
while(gpio_get_level(GPIO_CS) == 1)
{
taskYIELD();
}
Re: How to reset the wdt
Posted: Mon Jun 02, 2025 10:01 pm
by MicroController
yes, I'm able to configure and use the SPI module. But this is not my problem.
Then you may need to clarify what you mean by
ESP32 should work as a SPI-Slave and must wait until the PIC is ready for SPI communication
.
My question can be elaborated as "what additional requirements are there which make the SPI peripheral's slave mode not useable in this case?"
In general, busy-waiting/polling is bad practice and should be avoided, especially on a multi-tasking system like the ESP32's FreeRTOS.
Re: How to reset the wdt
Posted: Tue Jun 03, 2025 8:52 am
by HEckardt
Dear MC,
I don't know when exactly the MISO pin of the PIC is configured as an input. It could be, that it is an output in the beginning. So far I know, the MISO-Pin on ESP32 (which I want to use), is an input at/after reboot and the pullup resistor is not connected. And on the SPI interface are also TP-Controller as well as an external memory connected. To avoid a connectivity between two outputs, I'll wait until the PIC-SPI-Master is final configured and the SPI bus is stabile.
But these all is not my question. Forget the SPI issue. The only thing, what I want to know is: How it is possible to reset the ESP32-WDT in the user code for now and for doing in the future.
Who can help me to clarify this problem.
Greetings
Henry
Re: How to reset the wdt
Posted: Tue Jun 03, 2025 9:27 am
by MicroController
So far I know, the MISO-Pin on ESP32 (which I want to use), is an input at/after reboot and the pullup resistor is not connected. And on the SPI interface are also TP-Controller as well as an external memory connected. To avoid a connectivity between two outputs, I'll wait until the PIC-SPI-Master is final configured and the SPI bus is stabile.
The SPI hardware in slave mode should automatically tri-state MISO whenever /CS is high...
You can also manage task watchdogs at runtime if you have to:
https://docs.espressif.com/projects/esp ... timer-twdt
What I'm trying to convey is that the watchdog timer here is not actually the problem - it only
detects the problem which "can be an indicator of poorly written code that spinloops on a peripheral".
Re: How to reset the wdt
Posted: Tue Jun 03, 2025 11:24 am
by MicroController
The SPI hardware in slave mode should automatically tri-state MISO whenever /CS is high...
Hmm. Apparently it doesn't (see e.g.
viewtopic.php?t=6269).
Can't tell if that's a software issue or the hardware doesn't support this.
Re: How to reset the wdt
Posted: Tue Jun 03, 2025 11:38 am
by ves011
Here is an example for a WD handler on core 0.
You need first to get the handle for idle task running on core 0 (idle0_handle)
Code: Select all
// install current task as WD handler
esp_task_wdt_delete(idle0_handle);
esp_task_wdt_add(NULL);
while(some condition)
{
...
esp_task_wdt_reset();
...
}
//restore WD default handling
esp_task_wdt_add(idle0_handle);
Re: How to reset the wdt
Posted: Tue Jun 03, 2025 12:44 pm
by HEckardt
Hello MCF, hello ves11,
thank you for your support. I got an document with an explanation, which ponting to my wdt problem. And an example.
So, I think I'm satisfyed.
Greetings and bye
Henry