Repository navigation
embassy-boot-ch32 — an A/B bootloader (embassy-boot) for CH32V2/V3 on ch32-hal, serial + USB DFU #208
alexxy
started this conversation in
Show and tell
Replies: 1 comment 2 replies
|
Seems neat, but what benefits does this bring? WCH chips have a built-in bootloader that you can't overwrite, so it should theoretically be impossible to brick your chip. Automatic roll-backs are cool and all, but you're now paying a 3 second startup cost for a feature you already have, from what I can tell? |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone. I've put together an adaptation of embassy-boot for the CH32 parts driven by ch32-hal: repo alexxy/embassy-boot-ch32, published on crates.io as
embassy-boot-ch32v0.3.0, docs on docs.rs. MIT OR Apache-2.0.What it is. A
NorFlashadapter overch32-hal's flash driver, linker-script-driven partition maps, and a complete bootloader / application example pair. 20 parts across five families: CH32V203, V208, V303, V305, V307. Tested on real hardware — the nanoCH32V305 (CH32V305RBT6).Two selectable update transports:
i(partition map / state) andd(update session). The protocol is deliberately trivial —f <len>plus raw bytes, acknowledged with a.after each 256-byte page — and a host script (tools/serial_update.py) ships with it.dfu-util -a 0 -D app.bin), and the application exposes the DFU runtime interface, sodfu-util -efrom a running application resets the board straight into the USB bootloader. Controllers covered: USBD (V208), OTG_FS (V305RBT6, V307), USBHS (V305FBP6/GBU6). Built on embassy-usb-dfu.Under the hood:
CoarseFlashhides the flash's 256-byte pages behind an 8 KiB erase granularity: the embassy-boot state partition stays at 8 KiB instead of ballooning to ~193 KiB, and the swap remains power-loss safe.BOOTLOADER 16K/32K + ACTIVE + DFU + STATE) are a single source of truth for both binaries via the__bootloader_*linker symbols — they can never disagree about the geometry.mark_booted(), the bootloader reverts the previous image on the next reset, so a bad image cannot brick the board.Quickstart (nanoCH32V305):
After the first ISP flash, updates need no debugger:
din the application console (ordfu-util -ein a USB build), then ship the new binary.Limitations worth knowing:
ch32-halonly has for thev3flash IP: the CH32V2/V3 lines. V003 / X03x / L103 are not covered yet.TimerBits::Bits32, while that enum variant is gated#[cfg(any(ch32l1, ch32v208))]— the HAL simply does not compile for this part. It is a one-line upstream fix; the part comes back into the matrix as soon as it lands.0xc0de:0xcafe(replace before shipping), no MSOS descriptors — Windows needs the DFU driver assigned by hand.rust-src(riscv32imfc is a JSON target); the crate itself is a plaincargo check, MSRV 1.87.Roadmap:
ch32-haltimer bug is fixed.The full chip matrix, partition geometry, both protocols and the pairing rules are in the README; each example has its own README with the details (bootloader, application).
Feedback, issues and PRs welcome — especially tests on other parts and boards.
All reactions