simple_repeater: dfu, radio silence watchdog and boot diagnostics from NodeMaintenance
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7159a00f05
commit
2ced8502a0
3 files changed
+82
-275
No files matched your search
@@ -1,8 +1,7 @@
|
||||
#include "NodeMaintenance.h"
|
||||
|
||||
// CUSTOM (TeTeHacko): moved out of examples/simple_repeater/main.cpp, where the
|
||||
// long history of each piece still sits next to the repeater's own setup -- the
|
||||
// why of the dfu USB detach, of RESETREAS and of the hardfault record is there.
|
||||
// CUSTOM (TeTeHacko): moved out of examples/simple_repeater/main.cpp (4. 11. 2026),
|
||||
// history included.
|
||||
|
||||
#define RADIO_SILENCE_FILE "/rsilence"
|
||||
|
||||
@@ -15,12 +14,22 @@ extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Why did this board last restart? The core latches NRF_POWER->RESETREAS in
|
||||
// init() before clearing it, and it is the only thing that distinguishes
|
||||
// "somebody typed `dfu`" from "the CPU locked up" or "the power went away" after
|
||||
// the fact -- the hole hit while chasing boards that vanished from USB after `dfu`.
|
||||
// The hardfault record is saved by the patched HardFault_Handler (framework
|
||||
// debug.cpp) in g_hardfault_record, .noinit (NRF52Board.cpp) -- the old fixed
|
||||
// 0x2003FFF0 at the end of RAM was where the bootloader's stack lands on reset.
|
||||
void NodeMaintenance::printBootDiag() {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
uint32_t rr = readResetReason();
|
||||
_reset_reason = rr;
|
||||
// The build epoch belongs next to it: it is what the clock comes up at when
|
||||
// nothing else sets it.
|
||||
// nothing else sets it, so without it printed you cannot tell "fell back to
|
||||
// the build epoch" from "restored something" -- and comparing against the
|
||||
// epoch of a DIFFERENT build of the same tree invents discrepancies that are
|
||||
// not there. Cost one wrong conclusion here.
|
||||
Serial.printf("boot: FIRMWARE_BUILD_EPOCH=%lu\n", (unsigned long) FIRMWARE_BUILD_EPOCH);
|
||||
Serial.printf("boot: RESETREAS=0x%08lX%s%s%s%s%s\n", (unsigned long)rr,
|
||||
rr == 0 ? " (none set = power-on/brownout: power was removed)" : "",
|
||||
@@ -144,17 +153,64 @@ bool NodeMaintenance::silenceCommand(const char* command, char* reply) {
|
||||
}
|
||||
|
||||
// --- dfu [uf2|serial|ota] ------------------------------------------------------
|
||||
// The Adafruit bootloader picks its mode from GPREGRET at boot; the core's
|
||||
// enter*Dfu() write the magic and reset. LOCAL ONLY: over the mesh this would
|
||||
// strand a node in a bootloader that waits forever.
|
||||
// Reboot straight into the bootloader, deterministically.
|
||||
//
|
||||
// This is what the 1200-baud touch was a bad approximation of. The Adafruit
|
||||
// bootloader picks its mode from GPREGRET at boot, and the core exposes exactly
|
||||
// that (cores/nRF5/wiring.c): reset_mcu() writes the magic and calls
|
||||
// NVIC_SystemReset().
|
||||
// uf2 0x57 mass-storage drive, drop a .uf2 on it <- the usual one
|
||||
// serial 0x4e CDC only, for adafruit-nrfutil; no drive appears
|
||||
// ota 0xA8 BLE DFU
|
||||
// The touch only ever requested the *serial* mode, and on this build it worked
|
||||
// about half the time: twice it wedged a board out of USB and BLE entirely, with
|
||||
// no self-recovery (400 s) and no way back but a physical replug. This has no
|
||||
// such failure mode -- it is the same call the core makes, from a command.
|
||||
//
|
||||
// LOCAL ONLY. Over the mesh this would strand a node in a bootloader that waits
|
||||
// forever, on a mast, with no way back but a visit. sender_timestamp == 0 is the
|
||||
// same "physically present" test CommonCLI uses for `erase` and `set freq`.
|
||||
|
||||
// Deferred so the reply reaches the console first -- the reset never returns.
|
||||
void NodeMaintenance::dfuTick() {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
if (_dfu_at == 0 || (long)(millis() - _dfu_at) < 0) return;
|
||||
_dfu_at = 0;
|
||||
// Detach USB before the reset instead of letting the reset yank it out from
|
||||
// under the host (see simple_repeater/main.cpp for the measurements).
|
||||
// Detach USB before the reset instead of letting the reset
|
||||
// yank it out from under the host.
|
||||
//
|
||||
// Measured 4. 8. 2026: 3 of 8 `dfu` commands left the board dead on USB *and*
|
||||
// BLE, recoverable only by a physical replug. The kernel log is unambiguous
|
||||
// about what that is and is not:
|
||||
//
|
||||
// good: usb 7-9: USB disconnect -> 3 s later idProduct=0045 (bootloader)
|
||||
// bad: usb 7-6: USB disconnect -> nothing, ever
|
||||
//
|
||||
// CORRECTION, same evening: "no enumeration errors, therefore the board is
|
||||
// wedged" was WRONG, and worth leaving here as a warning. The identical
|
||||
// signature -- disconnect, then nothing, no errors, port reporting
|
||||
// `not attached` -- was later produced on a KNOWN GOOD board purely by
|
||||
// toggling the root-hub port's `disable` from the host. So the log tells you
|
||||
// the host stopped seeing a device; it does NOT tell you why, and a missing
|
||||
// error message is not evidence of a dead board.
|
||||
//
|
||||
// What is still true: the failure follows resets that happen with USB active,
|
||||
// in BOTH directions (app->bootloader and bootloader->app), and a reset via
|
||||
// the RESET pin -- the double tap -- has never failed. That is what this
|
||||
// change is aimed at, and it is a hypothesis about the transition, not a
|
||||
// diagnosis of the chip.
|
||||
//
|
||||
// reset_mcu() (core wiring.c) disables the SoftDevice and resets with USBD
|
||||
// still enabled and possibly mid-transfer. Detaching first drops D+ while the
|
||||
// application is still alive and in control, which gives the host an
|
||||
// unambiguous disconnect and leaves USBD in a defined state at reset.
|
||||
//
|
||||
// Honest scope: this removes a class of race, it is NOT yet proven to be the
|
||||
// cause -- the failure is intermittent, so only a run of trials can say. The
|
||||
// RESETREAS line printed at boot is the other half of the instrument.
|
||||
// Dropping the D+ pullup directly rather than through TinyUSBDevice.detach():
|
||||
// one register write, no dependency on the USB stack's headers being reachable
|
||||
// from here, and it is exactly what detach() does on this chip.
|
||||
NRF_USBD->USBPULLUP = 0;
|
||||
delay(150);
|
||||
if (_dfu_mode == 1) enterSerialDfu();
|
||||
|
||||
Reference in new issue
Block a user