Fix UICR not updated during WebUSB partial flashing#113
Merged
Conversation
Partial flashing skips addresses >= 0x10000000, so UICR is never written. After an interrupted full flash (which chip-erases UICR), the fallback partial flash leaves UICR blank, bricking the device. Now ensureUicr() runs after every partial flash to compare device UICR against the hex file. Write-without-erase when only 1→0 bit changes are needed (both V1/V2). On V2, use NVMC.ERASEUICR when 0→1 changes are required. On V1 (no independent UICR erase), fall back to full flash. Also refactors hex parsing: toMemoryMap() + extractFlashAndUicr() replace the old convertDataToPaddedBytes chain, parsing the input once to produce both flash bytes and UICR entries. Fixes: microbit-foundation/python-editor-v3#1131
Use the log lines to make sure we triggered the UIRC scenario
Use waitFor() with timeout for NVMC ready polling instead of bare while loops. Add configurable delay parameter to waitFor() so NVMC polls can use 5ms instead of the default 100ms. Also add UICR_LIMIT to bound the UICR address range.
microbit-matt-hillsdon
added a commit
to microbit-foundation/python-editor-v3
that referenced
this pull request
Apr 29, 2026
This contains the pre-1.0 breaking API changes and USB serial re-work. We'll run this on Python beta for a bit to build confidence as the BLE code has had far more real use than the USB changes. This should improve serial issues after first physical connection + flash and extra serial from previous programs leaking into subsequent ones. Relevant fixes: - Workaround for the bad response issue - microbit-foundation/microbit-connection#72 - Use DAPLink vendor command for serial number - microbit-foundation/microbit-connection#103 - Inline CMSIS-DAP code, fix and test serial issues - microbit-foundation/microbit-connection#110 - Fix UICR not updated during WebUSB partial flashing - microbit-foundation/microbit-connection#113
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Partial flashing skips all addresses >=
0x10000000, which means UICR (User Information Configuration Registers) is never written. This is normally fine because UICR doesn't change between flashes — but after an interrupted full flash, the device is left with erased UICR and a "dead" micro:bit that won't boot.The sequence that triggers this:
flash_manager_initdoes a chip erase (wiping all flash and UICR)Future flashes may also be partial if most pages were written successfully leading to the situation described in #112.
Solution
After every partial flash,
ensureUicr()reads device UICR and compares it against the hex file:NVMC.ERASEUICR, then writeAlso refactors hex data parsing: the old
convertDataToPaddedByteschain is replaced bytoMemoryMap()+extractFlashAndUicr(), which parses the input once to produce both the flash byte array and UICR entries.Hardware test
Adds UICR recovery after interrupted full flash test to the hardware test suite. We re-flash the same hex and verify the device boots and produces serial output.
Fixes #112