Is it possible to deinit the watchdog (WDT)?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Is it possible to deinit the watchdog (WDT)?

Post by BetterAutomations » Wed May 19, 2021 4:24 pm

I tried setting to both None and deinit(), neither worked for me. Is this possible or am I doing it wrong?

Code: Select all

load:0x40080400,len:3496
entry 0x4008063c
MicroPython v1.15-dirty on 2021-05-18; 4MB/OTA module with ESP32
Type "help()" for more information.
>>> from machine import WDT
>>> wdt = WDT(timeout=10*1000)
>>> wdt.feed()
>>> wdt = None
>>> E (36107) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (36107) task_wdt:  - mp_task (CPU 0)
E (36107) task_wdt: Tasks currently running:
E (36107) task_wdt: CPU 0: IDLE0
E (36107) task_wdt: CPU 1: IDLE1
E (36107) task_wdt: Aborting.
abort() was called at PC 0x400d3c68 on core 0

ELF file SHA256: 1e36f9167fb5f49f

Backtrace: 0x4008fb48:0x3ffbe500 0x4008ff21:0x3ffbe520 0x400d3c68:0x3ffbe540 0x400832d9:0x3ffbe560 0x401c746f:0x3ffbbc90 0x400d4583:0x3ffbbcb0 0x40092a1c:0x3ffbbcd0

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5064
load:0x40078000,len:12240
ho 0 tail 12 room 4
load:0x40080400,len:3496
entry 0x4008063c
MicroPython v1.15-dirty on 2021-05-18; 4MB/OTA module with ESP32
Type "help()" for more information.
>>> from machine import WDT
>>> wdt = WDT(timeout=3*1000)
>>> wdt.feed()
>>> wdt.deinit()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'WDT' object has no attribute 'deinit'
>>> E (91020) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (91020) task_wdt:  - mp_task (CPU 0)
E (91020) task_wdt: Tasks currently running:
E (91020) task_wdt: CPU 0: IDLE0
E (91020) task_wdt: CPU 1: IDLE1
E (91020) task_wdt: Aborting.
abort() was called at PC 0x400d3c68 on core 0

ELF file SHA256: 1e36f9167fb5f49f

Backtrace: 0x4008fb48:0x3ffbe500 0x4008ff21:0x3ffbe520 0x400d3c68:0x3ffbe540 0x400832d9:0x3ffbe560 0x401c746f:0x3ffbbc90 0x400d4583:0x3ffbbcb0 0x40092a1c:0x3ffbbcd0

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5064
load:0x40078000,len:12240
ho 0 tail 12 room 4
load:0x40080400,len:3496
entry 0x4008063c
MicroPython v1.15-dirty on 2021-05-18; 4MB/OTA module with ESP32
Type "help()" for more information.
>>>

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is it possible to deinit the watchdog (WDT)?

Post by pythoncoder » Wed May 19, 2021 5:04 pm

I think the answer is "no" and that this is by design. A WDT is intended to catch cases where code crashes or "runs wild". If you had a function that disabled the WDT this might run unexpectedly and permanently defeat the WDT. Normally a WDT is initialised after boot and runs forever.
Peter Hinch
Index to my micropython libraries.

smurf
Posts: 7
Joined: Wed Feb 27, 2019 11:25 am

Re: Is it possible to deinit the watchdog (WDT)?

Post by smurf » Wed Jun 02, 2021 1:47 pm

You could, however, start a periodic timer that schedules a procedure that feeds your WDT.

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Re: Is it possible to deinit the watchdog (WDT)?

Post by BetterAutomations » Wed Jun 02, 2021 1:59 pm

Yeah, I thought about that but didn’t want a hardware timer to keep ticking if the software crashed.

What I finally ended up doing is create a _thread with an internal timeout variable. It feeds the watchdog until the timeout. Then the feed() function my other code calls simply resets the timeout further in the future each time. That way it’s very dependent upon solid working code. If the other functions stop feeding, CHOMP!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is it possible to deinit the watchdog (WDT)?

Post by pythoncoder » Thu Jun 03, 2021 8:50 am

Your reasoning about avoiding a hardware timer is correct. But what do you gain by feeding the thread rather than feeding the actual WDT?
Peter Hinch
Index to my micropython libraries.

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Re: Is it possible to deinit the watchdog (WDT)?

Post by BetterAutomations » Thu Jun 03, 2021 12:51 pm

Oh. Forgot to mention a crucial detail. Also adding an external watchdog circuit. The supervisor chip resets after one second, but sometimes I need more time such as when computing a JWT. I can deinit that one as needed, or when computing a JWT I just have the thread feed it in the background. I was asking about deinit on the internal as well, but I just use a longer timeout for the internal. (5 minutes.)

It’s working well, even if it is more complicated. But I’ve given my customers a guarantee and this will help me keep it.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is it possible to deinit the watchdog (WDT)?

Post by pythoncoder » Thu Jun 03, 2021 1:18 pm

That sounds good :)
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Is it possible to deinit the watchdog (WDT)?

Post by Roberthh » Thu Jun 03, 2021 4:01 pm

I have made some code for an ATTINY85 to act as watchdog. It can be set on-the-fly to longer or shorter watch times. It is meant more for the slow response.
See: https://github.com/robert-hh/ATTiny-Wat ... icroPython

BetterAutomations
Posts: 83
Joined: Mon Mar 20, 2017 10:22 pm

Re: Is it possible to deinit the watchdog (WDT)?

Post by BetterAutomations » Thu Jun 03, 2021 6:22 pm

Roberthh wrote:
Thu Jun 03, 2021 4:01 pm
I have made some code for an ATTINY85 to act as watchdog. It can be set on-the-fly to longer or shorter watch times. It is meant more for the slow response.
See: https://github.com/robert-hh/ATTiny-Wat ... icroPython
Wonderful! I was going to build exactly this, but only as a backup in case sources of the watchdog chip (On Semiconductor CAT823STDI-GT3) dry up.

What is the license on this?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Is it possible to deinit the watchdog (WDT)?

Post by Roberthh » Thu Jun 03, 2021 6:31 pm

The License is as usually here MIT. I should add the to the files.

Post Reply