You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- NRF52Board: Add initWatchdog() to initialise WDT, set timer to 30 seconds and pause WDT if board enters sleep state
- NRF52Board: Add feedWatchdog() to bump the watchdog timer during normal operations
- NRF52Board: Add isWatchdogRunning() to query current run state of WDT
- NRF52Board: add tick() to be called from each example firmware to bump timer and allow a place for future tasks to be added centrally
- CommonCLI: Add "set wdt (on/off)" to enable or disable WDT (requires reboot)
- CommonCLI: Add "get wdt" to query enabled status and if wdt is running
- Repeater firmware: Add init and tick calls for WDT
- Added Heltec T114, RAK4631, Xiao nRF52840 build flag to include WDT
The nRF52 hardware watchdog timer (WDT) provides automatic recovery from firmware hangs or crashes. When enabled, if the firmware fails to "feed" the watchdog within the timeout period, the device will automatically reset.
4
+
5
+
## Parameters
6
+
7
+
| Parameter | Value |
8
+
|-----------|-------|
9
+
| Timeout | 30 seconds |
10
+
| Sleep behavior | Pauses during sleep mode |
11
+
| Halt behavior | Pauses during halt state |
12
+
| Control | Compile-time via `NRF52_WATCHDOG` build flag + runtime pref `wdt_enabled` (CLI `set wdt on/off`) |
13
+
14
+
The implementation uses the nRF52840 WDT peripheral with the following configuration:
15
+
16
+
| Register | Value | Description |
17
+
|----------|-------|-------------|
18
+
|`CONFIG.SLEEP`| Pause | WDT pauses when CPU enters sleep |
19
+
|`CONFIG.HALT`| Pause | WDT pauses during debug halt |
|`RR[0]`| 0x6E524635 | Magic value to feed watchdog |
23
+
24
+
## Usage
25
+
26
+
1. Watchdog is **disabled by default** - enable via `set wdt on` (reboot required to turn on/off)
27
+
2. Application code checks `prefs.wdt_enabled` after loading prefs and calls `board.initWatchdog()` if enabled
28
+
3. The main loop must call `board.tick()` regularly to feed the watchdog
29
+
4. If `board.tick()` is not called within 30 seconds, the device resets
30
+
5. The watchdog pauses during low-power sleep modes (won't reset during intended sleep)
31
+
32
+
**Important**: Once the watchdog is started, it cannot be stopped during runtime. A power cycle is required to apply changes made via `set wdt on/off`.
33
+
34
+
## Enabling Watchdog for a Board Variant
35
+
36
+
Watchdog is not compiled by default. To enable it for a board variant, add the `NRF52_WATCHDOG` flag to the variant's `platformio.ini`. The `wdt_enabled` preference (set via `set wdt on/off`) controls whether it starts on boot (disabled by default):
37
+
38
+
```ini
39
+
[env:your_variant]
40
+
extends = nrf52_base
41
+
build_flags = ${nrf52_base.build_flags}
42
+
-D NRF52_WATCHDOG
43
+
# ... other flags
44
+
```
45
+
46
+
## Firmware Integration
47
+
48
+
Currently, Watchdog is only implemented in the Repeater firmware. To add to other firmware types, perform the below steps.
49
+
50
+
After loading prefs in the `begin()` method, start the watchdog if enabled:
51
+
52
+
```cpp
53
+
_cli.loadPrefs(_fs);
54
+
55
+
#ifdef NRF52_WATCHDOG
56
+
if (_prefs.wdt_enabled) {
57
+
board.initWatchdog();
58
+
}
59
+
#endif
60
+
```
61
+
62
+
Ensure the main `loop()` function calls `board.tick()` to feed the watchdog:
63
+
64
+
```cpp
65
+
voidloop() {
66
+
the_mesh.loop();
67
+
sensors.loop();
68
+
#ifdef DISPLAY_CLASS
69
+
ui_task.loop();
70
+
#endif
71
+
rtc_clock.tick();
72
+
board.tick(); // Feed the watchdog
73
+
}
74
+
```
75
+
76
+
## CLI Commands
77
+
78
+
When `NRF52_WATCHDOG` is defined, the following CLI commands are available:
0 commit comments