Three of eight `dfu` commands tonight left the board dead on USB *and* BLE,
recoverable only by a physical replug. I had been calling that "the board fell
off USB" and asking for a replug -- which is a description, not a diagnosis.
The kernel log says exactly what it is and is not:
good: usb 7-9: USB disconnect -> 3 s later idProduct=0045 (bootloader)
bad: usb 7-6: USB disconnect -> nothing, ever
No failed-enumeration errors, so the host was not racing the device; the board
simply never drove D+ again. Nor was it sitting in the bootloader: a bootloader
in DFU mode advertises `AdaDFU`, and a BLE scan during the wedge found the other
two boards advertising normally and this one absent from both interfaces. So the
chip is wedged before either interface comes up, not "gone from USB".
Two changes, one a fix and one an instrument:
- reset_mcu() (core wiring.c) disables the SoftDevice and resets with USBD still
enabled and possibly mid-transfer. Clearing USBPULLUP first drops D+ while the
application is still alive and in control, giving the host an unambiguous
disconnect and leaving USBD in a defined state at reset. One register write --
that is all TinyUSBDevice.detach() does on this chip.
- readResetReason() is latched by the core in init() before RESETREAS is
cleared, and it is the only thing that can distinguish "somebody typed `dfu`"
from a lockup or a power cut after the fact. Printed in the boot diag window
next to the hardfault record.
Scope, honestly: the first change removes a class of race but is NOT yet proven
to be the cause -- the failure is intermittent (~37 %), so only a run of trials
can say. The RESETREAS line is the other half of that instrument.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>