How to reset the wdt

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

How to reset the wdt

Postby HEckardt » Mon Jun 02, 2025 4:15 pm

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

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to reset the wdt

Postby MicroController » Mon Jun 02, 2025 7:30 pm

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.

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

Re: How to reset the wdt

Postby HEckardt » Mon Jun 02, 2025 8:45 pm

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

nopnop2002
Posts: 362
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: How to reset the wdt

Postby nopnop2002 » Mon Jun 02, 2025 9:07 pm

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();

}

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to reset the wdt

Postby MicroController » Mon Jun 02, 2025 10:01 pm

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.

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

Re: How to reset the wdt

Postby HEckardt » Tue Jun 03, 2025 8:52 am

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

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to reset the wdt

Postby MicroController » Tue Jun 03, 2025 9:27 am

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".

MicroController
Posts: 2705
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to reset the wdt

Postby MicroController » Tue Jun 03, 2025 11:24 am

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.
Last edited by MicroController on Tue Jun 03, 2025 12:01 pm, edited 1 time in total.

ves011
Posts: 59
Joined: Fri Oct 07, 2022 2:31 pm
Location: romania
Contact:

Re: How to reset the wdt

Postby ves011 » Tue Jun 03, 2025 11:38 am

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);

HEckardt
Posts: 31
Joined: Wed Aug 16, 2023 3:13 pm

Re: How to reset the wdt

Postby HEckardt » Tue Jun 03, 2025 12:44 pm

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

Who is online

Users browsing this forum: Bing [Bot], meta-externalagent and 3 guests