Managing Watchdog Timers on esp8266

Hi guys, I am working on an algorithm to run on esp8266 but encounter the following problem:

 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 3424, room 16 
tail 0
chksum 0x2e
load 0x3fff20b8, len 40, room 8 
tail 0
chksum 0x2b
csum 0x2b
v00046e70
~ld

I understand that it is a problem related to a hardware wdt but I do not know how to identify where the problem occurs.
Using occasional serial printing (although it should not be done in such cases) I realized that the reset is triggered in this part of the code:

    //Serial.println("Start karatsuba");
    karatsuba_simple(aw1, bw1, w1);
    karatsuba_simple(aw2, bw2, w2);
    karatsuba_simple(aw3, bw3, w3);
    karatsuba_simple(aw4, bw4, w4);
    karatsuba_simple(aw5, bw5, w5);
    karatsuba_simple(aw6, bw6, w6);
    karatsuba_simple(aw7, bw7, w7);
    karatsuba_simple(aw7, bw7, w7);
    //Serial.println("End karatsuba");

The result is:

Start karatsuba
End karatsuba
Start karatsuba
End karatsuba
Start karatsuba
//wtd reset in this point

Here is my karatsuba function: karatsuba - Pastebin.com

Do you know of a working debuger for esp8266 or some other technique that might be useful to me in handling wdt?
Does esp32 have the same system or are wdt’s “softer”?

Thank you all for your attention.

Can you share a complete minimal project to reproduce the error?

The code on Pastebin is unfortunately not complete:

src\main.cpp: In function 'void karatsuba_simple(const uint16_t*, const uint16_t*, uint16_t*)':
src\main.cpp:5:18: error: 'KARATSUBA_N' was not declared in this scope
    5 |     uint16_t d01[KARATSUBA_N / 2 - 1];
      |                  ^~~~~~~~~~~
src\main.cpp:11:12: error: 'result_d01' was not declared in this scope
   11 |     memset(result_d01, 0, sizeof(result_d01));
      |            ^~~~~~~~~~
src\main.cpp:12:12: error: 'd01' was not declared in this scope; did you mean 'B01'?
   12 |     memset(d01, 0, sizeof(d01));
      |            ^~~
      |            B01
src\main.cpp:13:12: error: 'd0123' was not declared in this scope
   13 |     memset(d0123, 0, sizeof(d0123));
      |            ^~~~~
src\main.cpp:14:12: error: 'd23' was not declared in this scope
   14 |     memset(d23, 0, sizeof(d23));
      |            ^~~
src\main.cpp:32:29: error: 'OVERFLOWING_MUL' was not declared in this scope
   32 |             uint16_t mul1 = OVERFLOWING_MUL(acc1, acc5);
      |                             ^~~~~~~~~~~~~~~
src\main.cpp: At global scope:
src\main.cpp:3:13: warning: 'void karatsuba_simple(const uint16_t*, const uint16_t*, uint16_t*)' defined but not used [-Wunused-function]
    3 | static void karatsuba_simple(const uint16_t *a_1, const uint16_t *b_1, uint16_t *result_final) {
      |             ^~~~~~~~~~~~~~~~
*** [.pio\build\esp12e\src\main.cpp.o] Error 1

Here should be everything you need to fill out the project:

Reset the watchdog periodically by inserting small delays into the code (delay(1), possibly even delay(0), or directly call ESP.wdtFeed();.

If you don’t want to bother with the watchdog, ESP.wdtDisable(); it, and at a later time ESP.wdtEnable(<max milliseconds>); it again. (source)

1 Like

I tried these techniques (except “delay(0)”) thoughtfully but they were not effective.
In fact, I have noticed that overdoing these instructions leads to preemptive activation of the wdt.
The top would be to have a way to figure out exactly where the wdt starts so as to best optimize these calls.

Anyway I thank you, I will test using “delay(0)”.

For me, the solution was to run the programme on an esp32 by reformatting the code to increase the stack size at certain points.

Probably the esp8266 because of its small memory cannot allocate the whole stack.