adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.13k stars 1.22k forks source link

Watchdog timer on ESP32-S2 Feather #5890

Open billr12 opened 2 years ago

billr12 commented 2 years ago

CircuitPython version

CircuitPython 7.1.1

Code/REPL

https://forums.adafruit.com/viewtopic.php?f=60&t=187420#p907592

Behavior

If the code is run as shown, everything runs as expected - the program runs continually and the LED flashes indefinitely. If the time.sleep(15) line is uncommented, the program runs for 16 seconds then the board is reset and the program re-starts. Again, this is as expected. However, if the print(b) line is uncommented instead, the program terminates at the print(b) line with the error message NameError: name 'b' is not defined. The board then displays the >>> prompt in the repl and is never reset.

Description

No response

Additional information

Testing with the print line uncommented on a Feather M4 Express, the board displays the same error message and prompt, but at the 16 second mark, the board is reset and the program is again executed.

rdagger commented 1 year ago

I'm experiencing the same bug on Adafruit CircuitPython 8.1.0-beta.1-27-g3871501b5 with QT PY ESP32-S2.

It would be very helpful to get this fixed especially when working with Adafruit IO.

Here's my code:

from microcontroller import watchdog
from watchdog import WatchDogMode
from time import sleep

wdt = watchdog
wdt.timeout = 10
wdt.mode = WatchDogMode.RESET

counter = 0
while True:
    counter += 1
    if counter >= 5:
        raise Exception("Simulated Error.")
    print(counter)
    sleep(1)

After the raised exception crashes the program, the watchdog timer never resets the QT PY.

A similar MicroPython (v1.19.1) program on the QT PY ESP32-S2 works correctly:

from machine import WDT
from time import sleep

wdt = WDT(timeout=10000)  # 10 second watchdog timer

counter = 0 
while True:
    counter += 1
    if counter >= 5:
        raise Exception("Simulated Error")
    print(counter)
    sleep(1)  

5 seconds after the raised exception crashes the program, the watchdog timer resets the QT PY as expected.