Skip to content

Conversation

@entr0p1
Copy link

@entr0p1 entr0p1 commented Jan 18, 2026

Implement the nRF52840's built-in watchdog to reset the board if the firmware locks up for more than 30 seconds.

@entr0p1
Copy link
Author

entr0p1 commented Jan 18, 2026

Happy to report this has worked perfectly. No erroneous resets overnight, and I was able to force the board to lock up by adding the below into the CLI:
wdt-test

I then called set wdt.test from the CLI, which caused the board to lock up completely:
IMG_20260119_092533

I confirmed the board locked up completely, unable to log in over the mesh and the physical user button and UI stopped working:
IMG_20260119_092315

After the watchdog timed out, the board reset as expected and booted up normally. Happy to mark this ready for review once I've added in the supported boards.

@4np
Copy link

4np commented Jan 19, 2026

What will happen with the tick() calls when the CPU is sleeping after #1353 is merged? Or does the NRF watchdog account for sleeping internally?

@fschrempf
Copy link
Contributor

What will happen with the tick() calls when the CPU is sleeping after #1353 is merged? Or does the NRF watchdog account for sleeping internally?

I haven't checked, but I guess we will need to feed the watchdog in the wait for event loop.

@entr0p1
Copy link
Author

entr0p1 commented Jan 19, 2026

What will happen with the tick() calls when the CPU is sleeping after #1353 is merged? Or does the NRF watchdog account for sleeping internally?

It does - the watchdog gets paused during sleep and halt states:

// Configure WDT to pause during sleep and halt modes
NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos) |
(WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos);

- 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
@entr0p1
Copy link
Author

entr0p1 commented Jan 25, 2026

I've refactored this code and made it a lot tidier, plus rebased on dev (which I'll need to do again - meshcore moves fast!).

There's a compile flag to include WDT in the build, and a preference (disabled by default) with CLI command to enable WDT. The runtime code only exists in the repeater firmware but is simple to expand to others.

@entr0p1 entr0p1 marked this pull request as ready for review January 25, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants