fix: wipe nRF52 EEPROM before provisioning to initialize LittleFS#554
Conversation
Greptile SummaryThis PR fixes nRF52 EEPROM provisioning crashes by wiping (formatting) LittleFS before writing, matching Key changes:
Critical issue: RAK4631 boards use Nordic VID Device matching concern: The reconnection logic at lines 880 and 935 uses Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant F as RNodeFlasher
participant D as RNodeDetector
participant U as USBBridge
participant Dev as nRF52 Device
Note over F: nRF52 provisioning flow
F->>D: wipeEeprom()
D->>U: write(CMD_UNLOCK_ROM)
U->>Dev: CMD_UNLOCK_ROM + ROM_UNLOCK_BYTE
Dev-->>Dev: Format LittleFS<br/>(~18s)
Dev-->>Dev: Hard reset
F->>U: disconnect()
F->>F: delay(18s)
Note over F,Dev: Reconnection (5 retries)
loop 5 attempts
F->>U: connect(actualDeviceId)
alt Original ID works
U-->>F: Connected
else Scan for re-enumerated device
F->>U: getConnectedUsbDevices()
U-->>F: List of devices
F->>F: find { it.deviceId != actualDeviceId }
F->>U: connect(reEnumeratedDevice.deviceId)
U-->>F: Connected
end
end
F->>D: provisionAndSetFirmwareHash()
D->>U: write(EEPROM bytes)
U->>Dev: 168 EEPROM bytes
F->>D: resetDevice()
D->>U: write(CMD_RESET)
U->>Dev: CMD_RESET
Dev-->>Dev: Reboot
F->>U: disconnect()
F->>F: delay(3s)
Note over F,Dev: Verification (3 retries)
loop 3 attempts
F->>U: connect(actualDeviceId)
alt Can verify
U-->>F: Connected
F->>D: getDeviceInfo()
D-->>F: Verified info
else Cannot verify
Note over F: Complete anyway<br/>(provisioning likely succeeded)
end
end
Last reviewed commit: a9a0037 |
bb2e7d9 to
181b5a2
Compare
| } | ||
| // Scan for re-enumerated device (new ID after reset) | ||
| val devices = usbBridge.getConnectedUsbDevices() | ||
| val reEnumerated = devices.find { it.deviceId != actualDeviceId } |
There was a problem hiding this comment.
matches ANY USB device with different ID (mouse, keyboard, unrelated RNode) — could connect to wrong device during verification
| val reEnumerated = devices.find { it.deviceId != actualDeviceId } | |
| val reEnumerated = devices.find { it.deviceId != actualDeviceId && (it.vendorId == 0x239A || it.vendorId == 0x1915) } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: reticulum/src/main/java/com/lxmf/messenger/reticulum/flasher/RNodeFlasher.kt
Line: 938
Comment:
matches ANY USB device with different ID (mouse, keyboard, unrelated RNode) — could connect to wrong device during verification
```suggestion
val reEnumerated = devices.find { it.deviceId != actualDeviceId && (it.vendorId == 0x239A || it.vendorId == 0x1915) }
```
How can I resolve this? If you propose a fix, please make it concise.The nRF52 emulates EEPROM using LittleFS on internal flash. After DFU flashing, the filesystem may be uninitialized, causing individual byte writes to crash the device after ~40 writes. This matches rnodeconf's behavior of always calling wipe_eeprom() before provisioning nRF52 devices. Changes: - Add wipeEeprom() to RNodeDetector (sends CMD_UNLOCK_ROM/0x59) - Call wipe before nRF52 provisioning with 18s wait for LittleFS format + reboot, then reconnect with device scan - Make provisioning failure non-fatal (device works without it since Columba sends radio params at runtime) - Fix post-provisioning verify to use actualDeviceId and scan for re-enumerated devices instead of using stale original deviceId Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
181b5a2 to
a9a0037
Compare
Summary
rnodeconf's behaviorRoot Cause
After DFU flashing an nRF52 device, the LittleFS filesystem (used to emulate EEPROM) may be uninitialized. Individual
CMD_ROM_WRITEbyte writes crash the firmware after ~40 writes, disconnecting USB.rnodeconfavoids this by callingwipe_eeprom()(CMD_UNLOCK_ROM/ 0x59) first, which callsInternalFS.format()+hard_reset()in the firmware, initializing the filesystem.Changes
RNodeDetector.kt: AddwipeEeprom()method that sendsCMD_UNLOCK_ROMwithROM_UNLOCK_BYTERNodeFlasher.kt:FlashState.Error→FlashState.Completewhen provisioning fails but flash succeededactualDeviceIdand scan for re-enumerated devicesTest plan
🤖 Generated with Claude Code