The previous commit asserted "the chip is wedged before either interface comes
up, not gone from USB", reasoning that the absence of enumeration errors ruled
out a host-side problem. That reasoning was wrong and the conclusion is
withdrawn.
The control that broke it: the identical signature -- disconnect, then nothing,
no errors, port reporting `state=not attached` -- was reproduced on a KNOWN GOOD
board by writing 1 then 0 to that root-hub port's `disable` from the host. The
board was healthy and doing nothing unusual; it went to `not attached` and
stayed there until physically replugged. So the log proves the host stopped
seeing a device and nothing more. A missing error message is not evidence of
absence.
That also kills the port-toggle as a recovery mechanism -- it takes healthy
boards off the bus with no way back. Recorded so nobody tries it again.
What survives measurement:
- resets through the RESET pin (double tap) have never failed: 5/5
- software resets fail in both directions, ~5/10 for `dfu` before the
USBPULLUP change, and several times for the bootloader's own reset back
into the application -- a path our firmware cannot reach at all
- so USBPULLUP is aimed at a transition, not at a diagnosed chip fault, and
n=1 since does not demonstrate anything yet
The operational rules that follow (one board at a time, never loop flashes, ask
for hands immediately, and get a hub with real per-port power switching if this
bench is to be recoverable remotely) are in tools/README.md.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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>
bench-board died 29. 7. 2026 to a breadboard short that put GND on D1 (= DIO1)
and 5 V on D0. Signature: `sent 0` with tx_timeout climbing WHILE A WITNESS
HEARD THE FRAMES, plus `recv 0` at strong signal -- the radio works, the
interrupt line does not. setPacketReceivedAction() is the only thing that
ever sets STATE_INT_READY, so a dead line means nothing is ever picked up.
LORA_POLL_IRQ reads completion from the chip's IRQ status register over SPI
instead. The chip latches those events regardless of whether they are mapped
out to a DIO pin, so this bypasses the whole line and therefore works no
matter WHICH end of it broke. Rewiring DIO1 to a spare GPIO only helps if the
broken end is the MCU's input pad -- and that is the less likely end, because
grounding an input cannot damage the input, it stresses whatever drives the
net. Polling is strictly stronger: if it does not revive the node, no wire
will either. Cost is one extra SPI read per Dispatcher pass, next to the
isReceivingPacket() read already in that path.
getIrqFlags() returns the RAW chip register (SX126x bits, not RadioLib's
generic RADIOLIB_IRQ_* indices), so the mask comes from a new virtual
irqDoneMask() that only the chip-specific wrapper can fill in.
PIN_DIAG answers "which end?" without a multimeter:
- boot-time pull-up/pull-down sweep of every header pin, placed BEFORE
radio_init() because that halt()s when the radio does not answer -- so it
is the only diagnostic that still runs with the module unplugged, which is
also the only state where D1's result means anything (attached, the SX1262
drives DIO1 low and a healthy board reads 0 too). The internal pull is the
ohmmeter. It cannot see a lifted pad -- the resistor is on the die -- hence
the optional PIN_DIAG_LOOP_A/B jumper loopback, which drives from outside
and reads while pulling AGAINST the driver.
- `dio1` has the radio assert DIO1 via a 1-byte transmit and compares the
IRQ status register against the actual pin level. Where they disagree is
where the break is.
All of it is behind #ifdef; a build without the flags is unchanged.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
BLE name: Bluefruit.setName() was given BLE_DEVICE_NAME, which defaults to the
build-time ADVERT_NAME. That only ever seeds a fresh install, so once the whole
test fleet runs one image every board advertises the same string regardless of
`set name`, and a BLE scan cannot tell them apart. Four boards were advertising
"bench-board" simultaneously here -- including the one with the dead radio, which
is precisely the board you least want to mistake for a working one. Now it
advertises the prefs name, with the build constant as the fallback for a node
that has never been named. Prefs are loaded by the_mesh.begin() well before
Bluefruit.begin(), so the name is available.
xiao_uf2_flash.sh, after four rounds of it being not quite foolproof enough:
- takes an explicit target (serial or fleet number 0..4) and refuses to write
to any other board; the earlier version reported x4's port after flashing
x3, which reads exactly like a successful flash of the wrong board
- rejects a file that is not a UF2 (a .hex or .zip dropped on the drive is
ignored by the bootloader and looks like success)
- refuses an image older than firmware.elf, and demands the version stamp
- resolves drives through sysfs by USB serial, never by label -- every drive
is XIAO-SENSE, numbered in plug order
- retries the mount (the automounter loses the race with a fresh drive) and
the version read-back (the port enumerates seconds before the firmware
answers on it). A check that cries wolf is worse than no check.
- proves the flash by reading `ver` off the board and comparing it to the
image, instead of trusting that some XIAO came back on USB
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The 1200-baud touch was the wrong mechanism, not an unreliable one. The
Adafruit bootloader chooses its mode from GPREGRET at boot, and the core
already exposes exactly that (cores/nRF5/wiring.c):
enterUf2Dfu() 0x57 DFU_MAGIC_UF2_RESET -> mass-storage drive
enterSerialDfu() 0x4e DFU_MAGIC_SERIAL_ONLY_RESET -> CDC only, no drive
enterOTADfu() 0xA8 DFU_MAGIC_OTA_RESET -> BLE DFU
The touch only ever requests the *serial* one. That is why no UF2 drive ever
appeared however long we waited for it, and it is the real reason today's
flashes kept going sideways -- I read "coin flip" into what was simply a
request for a different mode, and then wedged two boards proving it.
`dfu` writes the magic and resets, so the board lands in the mode you asked
for, every time. The reply goes out first and the reset happens ~700 ms later
from loop(), since reset_mcu() never returns and over BLE the notification
still has to be pumped out of the TX ring.
LOCAL ONLY (sender_timestamp == 0, the same physical-presence test CommonCLI
uses for `erase` and `set freq`). Over the mesh this would park a node in a
bootloader that waits forever, on a mast, with no way back but a visit.
Builds clean; NOT yet exercised on hardware -- the boards that could test it
are the ones still running firmware without the command.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
blink: a fixed burst is a race against walking to the bench -- 30 blinks
(~7 s) was not enough to find the board in time. `blink on` now runs until
`blink off`, with a 10-minute backstop so a node left blinking does not
quietly eat a battery. Cap on the counted form raised to 999.
txpwr: `set tx` cannot tell you whether the radio took the value. It clamps
to -9..30, saves the pref and replies "OK", but SX1262 accepts only -9..+22
and rejects the rest WITHOUT touching the PA -- so `get tx` can report a
power the radio never had. An earlier sweep here measured +2 dBm and -9 dBm
as RSSI -44.1 and -44.0 at a witness and concluded runtime tx power "does
not work"; that conclusion rested on an instrument that could not
distinguish a refused request from a link that does not care.
RadioLibWrapper::setTxPower keeps the status now (the signature stays void,
it implements an upstream callback), and `txpwr [dBm]` reports it. It
deliberately does not write the pref, so a sweep cannot leave a node booting
at some experimental power.
xiao_uf2_flash.sh: the 1200-baud touch is roughly a coin flip on this build.
Today it worked twice, then wedged x4, then wedged x1 -- and a wedged board
is gone from USB *and* BLE, does not recover on its own (waited 400 s) and
needs a physical replug. Not a "too soon after boot" effect: x1 had been up
23 minutes. Double-tap RESET into UF2 is reliable and takes seconds, so this
makes that the easy path. It refuses to act when several UF2 drives are
present rather than guessing, since they are all labelled XIAO-SENSE.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
A bench of identical XIAOs cannot be told apart. The USB serial number
needs a data cable, and boards sharing power rails have none; the BLE MAC
is printed nowhere; and ADVERT_NAME is only as trustworthy as the last
flash, which is usually the thing being checked. Today two boards in the
same breadboard were both advertising "bench-board" -- one of them the
board with the burned DIO1, still happily running BLE.
`blink 10` flashes an LED ten times (default 6, clamped 1..30), and works
from serial, the BLE console and the mesh admin CLI, so it also reaches a
node that is already mounted somewhere.
Deliberately not the status LED. On XIAO that is LED_BLUE, which Bluefruit
drives as its connection indicator -- every BLE node blinks blue the same
way, which is why the LED was useless for identification in the first
place. Preference order LED_GREEN (XIAO, free) -> LED_WHITE (SenseCap, only
ever touched at boot and powerOff) -> LED_BUILTIN, which is last because on
SenseCap it is pin 12, the LoRa TX indicator. Variants may define a colour
they do not physically have by pointing it at PINS_COUNT (SenseCap does
that with LED_RED), so the chain range-checks rather than trusting #ifdef.
Driven from loop(), not inline: a blocking burst would stall the mesh for
up to ~7 s at the cap and disturb the very LoRa timing this fleet measures.
Always finishes dark. Goes through LED_STATE_ON, which is 0 on XIAO and 1
on SenseCap -- hard-coding HIGH would leave half the fleet unlit.
Verified on bench-board over the USB console: "blink 10" ->
"OK - blinking 10 times", and the build stamps v1.16.0-ttha12965f+.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Two diagnostic levers for the BLE/LoRa coexistence work, plus a correction to
what the existing tx power call actually does.
Bluefruit.setTxPower(8) is ADVERTISING power only. Bluefruit stores the value
and BLEAdvertising::start() hands it to sd_ble_gap_tx_power_set() with
BLE_GAP_TX_POWER_ROLE_ADV; nothing in the library ever sets the CONN role, so an
established link runs at the SoftDevice default of 0 dBm. The +8 buys discovery
range and nothing else. Confirmed on hardware: `blepwr` reports
"conn tx: 0 dBm, adv tx: 8 dBm".
- RPT_BLE_CONN_TX_POWER (default 0 = unchanged behaviour), applied per
connection on every 'secured' since the handle is new each time.
- `blepwr [dBm]` sets it at runtime over serial, the BLE console or the mesh
admin CLI. Runtime rather than a build flag because a dose-response sweep
needs many points and reflashing the XIAO costs a physical UF2 dance.
- Auto-revert after 5 min (`blepwr <p> hold` opts out). Without it the command
locks you out of the console you would need to undo it: the value is
re-applied on every 'secured', at -20 dBm the node's replies stop arriving and
at -40 dBm a connection cannot be established at all. Hit this on the bench;
recovery was over USB, and on the mast the only way back would be `reboot`
over the mesh admin CLI.
- `bleconn` reports the connection parameters actually in force. bleOnSecured()
only REQUESTS 15-30/60-80 ms and the central may refuse, so without reading
them back "the pre-fix interval showed no loss either" cannot be told apart
from "the pre-fix interval was never in force". Latched once a second from
loop() so it can be read over USB after the central is gone -- reading it over
the BLE console while connected would collide on the shared command[160].
Measured with these: at a verified 22.50 ms interval, sweeping the connection
tx power from 0 to -20 dBm (RSSI -67..-87 at the central, covering the whole
-75..-90 window the mast sits in) produced zero lost DIRECT forwards, with
tx_timeout and tx_start_fail at zero in every cell.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bleWriteAll used to spin-retry with delay(3) when the SoftDevice
notification queue was full, stalling loop() up to ~0.9 s per call
while a client streamed the console (rxlog/pktlog drains). That is
long enough to disturb LoRa RX/TX timing on the relay path.
Replace with a 4 KB ring buffer: bleWriteAll only enqueues, and
bleTxPump() (each loop pass) hands the SoftDevice as much as it will
take right now — zero waiting. Overflow truncates the newest bytes;
a torn page loses its 'E,' trailer so the bridge re-requests the
same cursor.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fewer SoftDevice connection events = fewer LoRa TX collisions (the
measured driver of the direct-forward loss); the Dispatcher TX retry
covers the residue. Bigger pktfeed ring buys margin for the bridge's
new connect->drain->disconnect duty cycle (~3-4 min between drains).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The BLE bridge drain was throttled by three multiplied costs: 150 B pages
(~3 rxlog records), 20 B NUS notification chunks, and the bridge waiting for
line silence per page. This fixes the firmware half:
- handleCommand() takes an explicit reply_max (default 150). The local console
(USB/BLE) passes ~1000 B -> ~20 rxlog records / ~7 nodes lines per round
trip; the mesh admin CLI keeps 150 so its reply still fits one LoRa packet.
Explicit parameter on purpose: a forged sender_timestamp==0 from the mesh
path must never be able to grow the reply past its 166 B buffer.
- bleWriteAll() chunks by negotiated MTU (247 -> 244 B) instead of fixed 20 B.
- Tables sized from channel physics instead of last week's traffic:
RXLOG_SIZE 512 = ~2 min of a saturated SF8/62.5k channel (~2-4 frames/s),
MAX_HEARD_NODES 128 > distinct nodes heard per neighbour advert period
(48 filled in <2 h and churned out real 0-hop neighbours).
- Page-sort scratch arrays moved off the loop-task stack into BSS.
RAM 17.7% -> 25.3% (59.6 KB / 235 KB). Flashed via BLE DFU 2026-07-15.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
btmon shows the disconnects are HCI reason 0x3E (Connection Failed to be
Established / lost sync), not supervision timeout -- so widening the timeout
didn't help. The mast link is weak (RSSI -75..-90) and the node is busy with
LoRa; with slave latency 4 the peripheral may skip connection events, so the
central loses sync and reports 0x3E. Respond on every event (latency 0) to
maximise sync on a weak/busy link.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
6 s cut the reconnect churn from every 15-30 s to every ~60 s but didn't
eliminate it: under the bridge's real polling load the node shows a
periodic multi-second stall (advert TX airtime / SoftDevice-LoRa
coexistence) that occasionally exceeds 6 s. Widen the supervision timeout
to 16 s so those stalls are tolerated; a genuine freeze is still caught by
the 20 s hardware watchdog (16 s < 20 s).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The BLE console link dropped every ~15-30 s and the bridge kept
reconnecting. Root cause: Bluefruit's default supervision timeout is only
2 s, and this repeater relays heavy LoRa flood traffic, so main-loop /
radio coexistence stalls past 2 s and the central tears down the link.
Mirror the companion's proven approach (explicit sd_ble_gap_conn_param_update
on 'secured', since some centrals ignore the advertised PPCP) but widen the
supervision timeout to 6 s (a repeater is far busier than a client), with a
15-30 ms interval and slave latency 4. PPCP is also set before advertising.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Repeater can be queried over BLE Nordic-UART (advert/neighbours/stats) without USB. Fix SoftDevice-protected TEMP peripheral access (sd_temp_get) that crashed BLE repeater telemetry, add USB-connected detection to ArduinoSerialInterface, and adjust the nRF52 ldscript/extra FS.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Framework for upcoming variant-specific PRs that add LED feedback during boot. The hook gives users visual cues that the device is busy and
shouldn't be interacted with until startup completes.
This commit refactors the serial bridge functionality out of the `simple_repeater` example and into a more reusable, object-oriented structure.
An `AbstractBridge` interface has been introduced, along with a concrete `SerialBridge` implementation. This encapsulates all the logic for packet framing, checksum calculation, and serial communication, cleaning up the main example file significantly.
The `simple_repeater` example now instantiates and uses the `SerialBridge` class, resulting in better separation of concerns and improved code organization.