[Bug]: nRF52 device freeze/lockup after Factory Reset (SoftDevice reboot regression)
Category
Hardware Compatibility
Hardware
DIY
Is this bug report about any UI (https://meshtastic.org/docs/configuration/device-uis/) component firmware?
- [ ] Meshtastic UI aka MUI
- [ ] InkHUD
- [ ] BaseUI
Firmware Version
2.7.26 BETA
Description
Description When triggering a factory reset (either configuration reset or full device reset) or performing operations that disable Bluetooth and trigger a scheduled reboot, nRF52-based devices (e.g., nRF52840 Pro Micro DIY and others) completely freeze/lock up into a dead state. The device remains unresponsive until a manual hardware power cycle is performed.
This issue was introduced as a regression between firmware versions v2.7.22 (where it resets correctly) and v2.7.26.
Root Cause Analysis The freeze occurs due to a mismatch between the Bluetooth stack shutdown state and the system reset method:
Change in reboot mechanism:
In v2.7.22, Power::reboot() restarted nRF52 nodes using a direct hardware reset: cpp
NVIC_SystemReset(); In v2.7.26, SoftDevice-aware reboot logic was introduced: cpp
extern bool useSoftDevice; if (useSoftDevice) { sd_nvic_SystemReset(); } else { NVIC_SystemReset(); } The Race/Shutdown Condition: When a factory reset is initiated (e.g., via AdminModule or input broker), the code calls disableBluetooth() before scheduling the reboot.
disableBluetooth() calls nrf52Bluetooth->shutdown(), which stops advertising, disconnects active peers, and alters the SoftDevice state. The reboot is scheduled to execute after a 2-second delay (DEFAULT_REBOOT_SECONDS). When the timer expires, Power::reboot() is called. Because the global variable useSoftDevice remains statically set to true, the code tries to restart the CPU by calling the SoftDevice Supervisor Call: cpp
sd_nvic_SystemReset(); However, because the SoftDevice stack has been partially/fully shutdown or put into an inactive state by disableBluetooth(), executing sd_nvic_SystemReset() triggers an unhandled SVC (Supervisor Call) exception or a HardFault. Instead of resetting, the CPU locks up immediately, leaving the node frozen. Proposed Resolution To fix the crash, Power::reboot() should only call sd_nvic_SystemReset() if the SoftDevice handler is actually enabled and active. Otherwise, it must fall back to the raw hardware reset (NVIC_SystemReset()).
Option A: Check SoftDevice Status (Recommended) Include <nrf_sdh.h> (Nordic SoftDevice Handler) and verify if the SoftDevice is active before using its reset function:
cpp
#elif defined(ARCH_NRF52) #include "nrf_sdh.h"
// Only use SoftDevice reset if the stack is active and enabled
if (nrf_sdh_is_enabled()) {
sd_nvic_SystemReset();
} else {
NVIC_SystemReset();
}
Option B: Conditional Fallback on Bluetooth Shutdown Alternatively, if useSoftDevice is set to false during disableBluetooth(), or if the code falls back to NVIC_SystemReset() when Bluetooth is not running:
cpp
#elif defined(ARCH_NRF52) extern bool useSoftDevice; // Fall back to raw reset if Bluetooth is not active/shut down if (useSoftDevice && nrf52Bluetooth && !nrf52Bluetooth->isShutdown()) { sd_nvic_SystemReset(); } else { NVIC_SystemReset(); } Steps to Reproduce Flash official Meshtastic v2.7.26 firmware on an nRF52840 DIY TCXO target. Connect to the node via Python CLI or the mobile app. Send a factory reset command (e.g., meshtastic --factory-reset). The node will print Initiate full factory reset / Factory config reset finished, rebooting soon over serial console, show Rebooting... on the screen, and then freeze forever instead of booting back up.
Relevant log output
This issue describes a device/firmware bug involving an nRF52 device lockup after a factory reset, but no device logs have been attached. Please provide logs to help diagnose the issue. Use the Web Flasher or Meshtastic CLI to get the logs. Additionally, it would be helpful to confirm the region and any further expected vs actual behavior details.
I reproduced the factory-reset lockup on a bench nRF52840 Muzi Base and opened a fix PR: https://github.com/meshtastic/firmware/pull/10873
Bench details:
- Target: Muzi Base nRF52840 (
MUZI_BASE) on/dev/cu.usbmodem31201 - Current
developfirmware:2.8.0.84b1af0 bluetooth.enabled=false+ admin reboot: passed, metadata came back immediately.meshtastic --factory-reset: reproduced the bug. Serial API timed out repeatedly for more than two minutes; USB stayed enumerated but Meshtastic metadata did not return until bootloader/PlatformIO recovery.
One correction to the proposed cause: I checked Power::reboot() in v2.7.22.96dd647, v2.7.26.54e0d8d, and current develop; all use NVIC_SystemReset() for nRF52. I did not find an sd_nvic_SystemReset() change in that path.
The fix in #10873 keeps BLE/SoftDevice active while factory reset / NodeDB reset cleanup performs flash-backed work, then stops BLE just before scheduling reboot. With that patch flashed to the same Muzi Base, meshtastic --factory-reset returned successfully: first poll saw the expected USB disconnect during reboot, second poll returned metadata without recovery.