stmhal: WDT hangs after programming
I discovered an interesting quirk related to the IWDG.
If I program my pyboard using pydfu, then trying this in the REPL immediately afterwards hangs:
>>> wdt = machine.WDT(0, 5000)
By hangs, I mean it never returns the REPL. I added some debug prints and it seems to stuck in the IWDG->SR & 1 loop and the value of SR is 3.
If I hit the RESET button, then the wdt = machine.WDT(0, 5000) works exactly as expected.
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