← index #18613PR #11981
Related · high · value 0.472
QUERY · ISSUE

Feature Request: Enable WDT Cancel

openby daniel-theiaopened 2025-12-28updated 2025-12-31
enhancement

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

CANDIDATE · PULL REQUEST

docs/ESP32: Reinitialize watchdog timer with longer timeout.

openby IhorNehrutsaopened 2023-07-10updated 2023-10-06
port-esp32

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied