I disabled watchdogs but I still get a WDT timeout

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Wed Jul 08, 2020 8:37 pm

Hello! I'm trying to disable all watchdogs from one core. I'm using an ESP32 MH-ET LIVE on Arduino IDE. I'm trying the following in setup() and making a new max priority task (with IRAM_ATTR) on cpu0:

Code: Select all

rtc_wdt_protect_off(); 
rtc_wdt_disable();
disableCore0WDT();
disableLoopWDT();
However, when I try and use:

Code: Select all

 static portMUX_TYPE my_mutex; (below #includes)
 vPortCPUInitializeMutex(&my_mutex); (in setup)
 portENTER_CRITICAL(&my_mutex); (in task)
I get still get Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).

I'm looking to disable the watchdog so I can stay in portENTER_CRITICAL indefinitely on one core because I'm successfully bitbanging at decently fast speeds, but the FreeRTOS ticks and background stuff ends up throwing random 1-2us delays that wreck it. I realize this sacrifices the ability to use timers and extra tasks on that core, but I can accept that. I can't use interrupts in this case, as ESP32 takes +2us to handle the interrupt.

Here's some minimal example code, if I uncomment the portENTER/portEXIT code, it errors out.

Code: Select all

#include "soc/rtc_wdt.h"
#include "esp_int_wdt.h"
#include "esp_task_wdt.h"

static portMUX_TYPE my_mutex;

IRAM_ATTR void setup() {
  rtc_wdt_protect_off();
  rtc_wdt_disable();
  disableCore0WDT();
  disableLoopWDT();
  vPortCPUInitializeMutex(&my_mutex);
  
  Serial.begin(115200);

  TaskHandle_t Task2;
  xTaskCreatePinnedToCore(
      Select,   /* Function to implement the task */
      "Select", /* Name of the task */
      10000,           /* Stack size in words */
      NULL,            /* Task input parameter */
      configMAX_PRIORITIES,               /* Priority of the task */
      &Task2,          /* Task handle. */
      0);              /* Core where the task should run */

}

IRAM_ATTR void Select( void * parameter) {
  unsigned long sincePrint = millis();
  
  portENTER_CRITICAL(&my_mutex);
  for(int i = 0; i < 10000000; i++) {
    digitalWrite(22, 1);
    digitalWrite(22, 0);
    esp_task_wdt_reset();
  } 
  portEXIT_CRITICAL(&my_mutex);

  Serial.print(millis() - sincePrint);

  vTaskDelete(0);
}

void loop() {
  vTaskDelay(portMAX_DELAY);
}
Thanks for reading!

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby chegewara » Fri Jul 10, 2020 7:42 am

You disabled wdt on looper task only, not that new task. Another thing is why not use peripheral to do it, like ledc, spi or rmt?

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Sun Jul 12, 2020 1:52 am

chegewara wrote:
Fri Jul 10, 2020 7:42 am
You disabled wdt on looper task only, not that new task. Another thing is why not use peripheral to do it, like ledc, spi or rmt?
Hey chegewara! I keep running into you :)

How do I properly handle this? I copied (and tried cutting) the following into the top of the new task, and it still had the same issue.

rtc_wdt_protect_off();
rtc_wdt_disable();
disableCore0WDT();
disableLoopWDT();

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby chegewara » Mon Jul 13, 2020 3:04 am


Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Mon Jul 13, 2020 3:08 pm

Ah, I should have read that page more carefully. I thought you had to pass it a valid handle, I missed the part where you could pass it NULL.

I'll give this a try, thank you!

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Mon Jul 13, 2020 11:26 pm

chegewara wrote:
Mon Jul 13, 2020 3:04 am
https://docs.espressif.com/projects/esp ... skHandle_t
https://github.com/espressif/arduino-es ... misc.c#L72

From task that you want to disable WDT:

Code: Select all

esp_task_wdt_delete(NULL)
Ah, I didn't realize you could call that function with NULL, I see now. I went ahead and tried putting that function in the task itself and got the same exception (decoded here): https://pastebin.com/raw/E4yNT6bz

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby chegewara » Tue Jul 14, 2020 10:14 am

To me it looks like you are having problem with this code now, not wdt:
PC: 0x400d0d9c: Print::printNumber(unsigned long, unsigned char) at C:\Users\Derf\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\Print.cpp line 268
EXCVADDR: 0x00000000

Decoding stack results
0x400d0d9c: Print::printNumber(unsigned long, unsigned char) at C:\Users\Derf\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\Print.cpp line 268

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Tue Jul 14, 2020 1:39 pm

The stack trace is pointing to the first digitalWrite in the loop, but still throwing the same WDT error.

Derf Jagged
Posts: 16
Joined: Wed Jul 08, 2020 8:33 pm

Re: I disabled watchdogs but I still get a WDT timeout

Postby Derf Jagged » Sun Jul 26, 2020 6:53 pm

chegewara wrote:
Tue Jul 14, 2020 10:14 am
To me it looks like you are having problem with this code now, not wdt:
Any other ideas what might be going on? Really been stumped on this one. I'm essentially just trying to be able to stay in critical mode or some mode that disables FreeRTOS ticks on one core so that I don't have random 1000 clock delays breaking my code.

Who is online

Users browsing this forum: No registered users and 64 guests