Skip to content

Commit 77a5199

Browse files
committed
docs/ESP32: Reinit watchdog with longer timeout.
docs/ESP32: Reinitialize watchdog timer with longer timeout. Signed-off-by: Ihor Nehrutsa <IhorNehrutsa@gmail.com>
1 parent 5232847 commit 77a5199

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

docs/esp32/quickref.rst

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ These are working configurations for LAN interfaces of popular boards::
141141
# Olimex ESP32-GATEWAY: power controlled by Pin(5)
142142
# Olimex ESP32 PoE and ESP32-PoE ISO: power controlled by Pin(12)
143143

144-
lan = network.LAN(mdc=machine.Pin(23), mdio=machine.Pin(18), power=machine.Pin(5),
144+
lan = network.LAN(mdc=machine.Pin(23), mdio=machine.Pin(18), power=machine.Pin(5),
145145
phy_type=network.PHY_LAN8720, phy_addr=0,
146146
ref_clk=machine.Pin(17), ref_clk_mode=machine.Pin.OUT)
147147

@@ -564,7 +564,7 @@ See :ref:`machine.WDT <machine.WDT>`. ::
564564
from machine import WDT
565565

566566
# enable the WDT with a timeout of 5s (1s is the minimum)
567-
wdt = WDT(timeout=5000)
567+
wdt = WDT(timeout=5000) # timeout in milliseconds
568568
wdt.feed()
569569

570570
.. _Deep_sleep_mode:

docs/esp32/tutorial/index.rst

100644100755
+1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ to `<https://www.python.org>`__.
2020

2121
intro.rst
2222
pwm.rst
23+
wdt.rst
2324
peripheral_access.rst

docs/esp32/tutorial/wdt.rst

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
.. _esp32_wdt:
3+
4+
WDT
5+
===
6+
7+
When the WDT timeout is short, a problem occurs when updating the software:
8+
you don't have enough time to copy the updates to the device.
9+
ESP32 allows reinitialise the watchdog with a longer timeout - like an hour.
10+
11+
More comprehansive example usage::
12+
13+
# Save as 'main.py' and it will run automatically after 'boot.py'
14+
15+
import sys
16+
from time import sleep
17+
from machine import WDT, reset
18+
19+
try:
20+
print('Press Ctrl-C to break the program.')
21+
sleep(5)
22+
print('Enable the WDT with a timeout of 5s.')
23+
wdt = WDT(timeout=5000)
24+
25+
seconds = 1
26+
while True: # infinite work loop
27+
print('Do something useful in less than 5 seconds.')
28+
print(f'Sleep {seconds} seconds.')
29+
if seconds >= 5:
30+
print(f'WDT will reboot the board.')
31+
sleep(seconds)
32+
seconds += 1
33+
wdt.feed()
34+
35+
# 1/0 # uncomment this line to raise an runtime exception, then WDT reboot
36+
37+
# sys.exit() # uncomment this line for planned program exit
38+
39+
except SystemExit:
40+
wdt = WDT(timeout=1000 * 60 * 60) # 1 hour before WDT reboot
41+
print('Now you have 1 hour to update program on the board.')
42+
print('When ready, type reset() on the REPL/WebREPL command line to reboot.')
43+

docs/library/machine.WDT.rst

100644100755
+5-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ class WDT -- watchdog timer
55
===========================
66

77
The WDT is used to restart the system when the application crashes and ends
8-
up into a non recoverable state. Once started it cannot be stopped or
9-
reconfigured in any way. After enabling, the application must "feed" the
8+
up into a non recoverable state. Once started it cannot be stopped
9+
in any way. After enabling, the application must "feed" the
1010
watchdog periodically to prevent it from expiring and resetting the system.
1111

1212
Example usage::
1313

1414
from machine import WDT
1515
wdt = WDT(timeout=2000) # enable it with a timeout of 2s
16-
wdt.feed()
16+
while True:
17+
# do something useful in less than 2 seconds
18+
wdt.feed()
1719

1820
Availability of this class: pyboard, WiPy, esp8266, esp32, rp2040, mimxrt.
1921

0 commit comments

Comments
 (0)