23 November 2026 · Zephyr · MCUboot · OTA · STM32U5 · ESP32-C5 · BLE
Three designs to get firmware updates that never brick a watch
How phone-to-watch updates over BLE and a UART bridge went from 99.6% reliable to boringly reliable, and the four real bugs found on the way.
The wearable has two chips. An STM32U5 runs Zephyr, the display and the sensors. An ESP32-C5 handles Bluetooth and passes data to the U5 over a UART at 921,600 baud. A firmware update travels a long way:
phone → BLE → ESP32-C5 → UART → STM32U5 → flash → MCUboot
Every hop can drop a byte. The update path has to survive all of them, and a failed update must never leave the watch unbootable.
Attempt 1: a custom windowed protocol
The ESP32 sent firmware in windows of N chunks. The U5 collected a window, wrote it to flash and acknowledged it, with retransmission for lost frames.
It delivered 99.6% of frames. The other 0.4%, lost to noise on the wire, occasionally broke a window’s retransmission, and that cascaded into a failed transfer. The protocol was also hard to debug.
Attempt 2: Zephyr’s MCUmgr over the bridge
Switching to the standard MCUmgr/SMP protocol looked like the grown-up answer. Instead it uncovered a chain of problems:
- A parser bug of my own. MCUmgr leaves out the
rcfield on success. My client expected it, so every response looked like a failure. - A DMA erratum. On the STM32U5G9,
uart_tx()reported success but the bytes never reached the wire. The errata note covers related U5 parts; this one is affected too. - Lost responses. About 0.4% of SMP responses still vanished, and a 5-second retry timeout let the Bluetooth queue overflow.
- Writes that didn’t stick. With the update slot in the second flash bank, writes returned success but the flash read back as 0xFF. Moving both slots into bank 1 fixed it.
- The fatal one. MCUmgr’s buffered image writer only flushes its last 512 bytes when the final offset matches exactly. After any retry the offsets could drift, the final flush never happened, and the last ~147 bytes were lost. Those bytes hold the image hash and signature, so MCUboot rejected the image.
Writing the same signed file straight to the update slot over SWD booted perfectly. The image was fine; the upload path was corrupting it.
Attempt 3: direct flash writes, verified end to end
The working design removes the middleware:
- The ESP32 sends raw firmware in 112-byte chunks. That is 7 × 16 bytes, so every write is aligned to the U5’s 16-byte flash programming size.
- The U5 erases 8 KB sectors just ahead of the write offset, spreading roughly 2.4 s of erase time across the transfer instead of blocking up front.
- Each acknowledgement carries the U5’s current offset. If an ACK is lost and the ESP32 resends a chunk the U5 already wrote, the U5 answers with its offset and the ESP32 recognises the chunk as done.
- The phone computes a SHA-256 before the transfer. The U5 checks it over the whole slot after the last chunk.
- Only after the hash matches does the U5 ask MCUboot to upgrade. MCUboot then checks the image signature before copying it into place.
Why it can’t brick
- Power lost mid-transfer? The upgrade was never requested, so MCUboot boots the old firmware.
- Hash mismatch? The U5 reports failure and never reboots into the new image.
- Commit is a single flash write. Either the upgrade marker is written or it isn’t.
The result
| Metric | Value |
|---|---|
| Image size | ~792 KB |
| Chunks per update | ~7,070 |
| Round trip per chunk | ~2.8 ms |
| Retry rate | ~0.4% |
| Total time | ~26 s |
The watch went v1.0 → v1.1 → v1.2 over the air on real hardware without a single bad boot.
The lesson: when a standard stack fails in ways you can’t see, measure each hop on its own. Then make the protocol simple enough to reason about. In this case, the boring design won.
Related case study
Dual-MCU wearable: round-AMOLED watch and RF research multi-tool