kopia lustrzana https://github.com/micropython/micropython
docs/ESP32: Reinit watchdog with longer timeout.
docs/ESP32: Reinitialize watchdog timer with longer timeout. Signed-off-by: Ihor Nehrutsa <IhorNehrutsa@gmail.com>pull/11981/head
rodzic
5232847771
commit
77a5199682
|
@ -564,7 +564,7 @@ See :ref:`machine.WDT <machine.WDT>`. ::
|
||||||
from machine import WDT
|
from machine import WDT
|
||||||
|
|
||||||
# enable the WDT with a timeout of 5s (1s is the minimum)
|
# enable the WDT with a timeout of 5s (1s is the minimum)
|
||||||
wdt = WDT(timeout=5000)
|
wdt = WDT(timeout=5000) # timeout in milliseconds
|
||||||
wdt.feed()
|
wdt.feed()
|
||||||
|
|
||||||
.. _Deep_sleep_mode:
|
.. _Deep_sleep_mode:
|
||||||
|
|
|
@ -20,4 +20,5 @@ to `<https://www.python.org>`__.
|
||||||
|
|
||||||
intro.rst
|
intro.rst
|
||||||
pwm.rst
|
pwm.rst
|
||||||
|
wdt.rst
|
||||||
peripheral_access.rst
|
peripheral_access.rst
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
.. _esp32_wdt:
|
||||||
|
|
||||||
|
WDT
|
||||||
|
===
|
||||||
|
|
||||||
|
When the WDT timeout is short, a problem occurs when updating the software:
|
||||||
|
you don't have enough time to copy the updates to the device.
|
||||||
|
ESP32 allows reinitialise the watchdog with a longer timeout - like an hour.
|
||||||
|
|
||||||
|
More comprehansive example usage::
|
||||||
|
|
||||||
|
# Save as 'main.py' and it will run automatically after 'boot.py'
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from time import sleep
|
||||||
|
from machine import WDT, reset
|
||||||
|
|
||||||
|
try:
|
||||||
|
print('Press Ctrl-C to break the program.')
|
||||||
|
sleep(5)
|
||||||
|
print('Enable the WDT with a timeout of 5s.')
|
||||||
|
wdt = WDT(timeout=5000)
|
||||||
|
|
||||||
|
seconds = 1
|
||||||
|
while True: # infinite work loop
|
||||||
|
print('Do something useful in less than 5 seconds.')
|
||||||
|
print(f'Sleep {seconds} seconds.')
|
||||||
|
if seconds >= 5:
|
||||||
|
print(f'WDT will reboot the board.')
|
||||||
|
sleep(seconds)
|
||||||
|
seconds += 1
|
||||||
|
wdt.feed()
|
||||||
|
|
||||||
|
# 1/0 # uncomment this line to raise an runtime exception, then WDT reboot
|
||||||
|
|
||||||
|
# sys.exit() # uncomment this line for planned program exit
|
||||||
|
|
||||||
|
except SystemExit:
|
||||||
|
wdt = WDT(timeout=1000 * 60 * 60) # 1 hour before WDT reboot
|
||||||
|
print('Now you have 1 hour to update program on the board.')
|
||||||
|
print('When ready, type reset() on the REPL/WebREPL command line to reboot.')
|
||||||
|
|
|
@ -5,14 +5,16 @@ class WDT -- watchdog timer
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
The WDT is used to restart the system when the application crashes and ends
|
The WDT is used to restart the system when the application crashes and ends
|
||||||
up into a non recoverable state. Once started it cannot be stopped or
|
up into a non recoverable state. Once started it cannot be stopped
|
||||||
reconfigured in any way. After enabling, the application must "feed" the
|
in any way. After enabling, the application must "feed" the
|
||||||
watchdog periodically to prevent it from expiring and resetting the system.
|
watchdog periodically to prevent it from expiring and resetting the system.
|
||||||
|
|
||||||
Example usage::
|
Example usage::
|
||||||
|
|
||||||
from machine import WDT
|
from machine import WDT
|
||||||
wdt = WDT(timeout=2000) # enable it with a timeout of 2s
|
wdt = WDT(timeout=2000) # enable it with a timeout of 2s
|
||||||
|
while True:
|
||||||
|
# do something useful in less than 2 seconds
|
||||||
wdt.feed()
|
wdt.feed()
|
||||||
|
|
||||||
Availability of this class: pyboard, WiPy, esp8266, esp32, rp2040, mimxrt.
|
Availability of this class: pyboard, WiPy, esp8266, esp32, rp2040, mimxrt.
|
||||||
|
|
Ładowanie…
Reference in New Issue