Feature Request: Enable WDT Cancel
Description
Previous discussions:
- https://github.com/micropython/micropython/issues/8600
- https://github.com/micropython/micropython/issues/8597
In the ESP32 documentation [1] it is possible to enable and disable the WDTs, but not in micropython.
The problem (for me) occurs when you have enabled the WDT and go for a long light sleep - it is possible to wake up to an immediate WDT timeout. For example:
# main.py
import machine
# Setup WDT for normal operation
wdt = machine.WDT(timeout=2000)
while True :
# Feed the WDT as you should
wdt.feed()
# TODO: Do normal stuff
# Should we go into a light sleep?
if light_sleep_required() :
# Should be okay to sleep for 5 seconds or maybe be woken by a pin
machine.lightsleep(5000)
What's worse is, that the WDT reset doesn't seem to clear the WDT timeout on machine.reset(), and I have witnessed micropython completely stuck in some boot-like loop. This is the opposite of what you want your WDT doing.
In the previous discussions [2] @dpgeorge said:
The watchdog is not intended to be stopped. That is a feature.
There are clear reasons why you may want to stop it:
- The acceptable timeout depends on what code is being run.
- Going to sleep and re-waking should not trigger a timeout.
- Only one section of code is considered "risky".
- The device is put into some form of OTA mode where all code is stopped and just the download routine runs.
[1] https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/wdts.html
[2] https://github.com/micropython/micropython/issues/8600#issuecomment-1116773752
Code Size
The previous implementation WDT.deinit() should be brought back: https://docs.micropython.org/en/latest/library/machine.WDT.html
It would require a deinit() implementation per port. deinit() could return a bool to indicate if the WDT cancellation was respected, which could allow a transition period too.
Implementation
I hope the MicroPython maintainers or community will implement this feature
Code of Conduct
Yes, I agree
docs/ESP32: Reinitialize watchdog timer with longer timeout.
If the WDT timeout is short(several seconds), a problem occurs when updating the software:
you don't have enough time to copy updates to the device.
ESP32 allows reinitializing the watchdog with a longer timeout - like an hour.
Discussion in
ESP32/machine_wdt.c: Add WDT.deinit() method. https://github.com/micropython/micropython/pull/6631
The best explanation at comment
This PR is a copy of #10901 which was damaged due to rebase.