Browse by type
Rust HAL(Hardware Abstraction Layer) crate for WCH's 32-bit RISC-V microcontrollers.
Note This project is under development. While it's usable for experimentation and testing, it may not be fully stable for production environments. We welcome user feedback and encourage reporting any issues you encounter to help improve the hal crate.
This HAL crates is the Embassy framework driver for WCH's 32-bit RISC-V microcontrollers.
This HAL crates uses the metapac approach to support multiple chips in the same crate.
The metapac is maintained in the ch32-rs/ch32-data repository, published as a crate ch32-metapac.
Keypoints:
Currently, supported chips are listed in Cargo.toml as feature flags,
others should work if you are careful as most peripherals are similar enough.
For a full list of chip capabilities and peripherals, check the ch32-data repository.
| Family | V2/V3 | V1 | V003 | V00X | X0 | L1 | CH641 | CH643 | H4‡ |
|---|---|---|---|---|---|---|---|---|---|
| Embassy | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| RCC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| GPIO | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| PIOC§ | N/A | N/A | N/A | N/A | ✅ | N/A | N/A | ✅ | ✅ |
| EXTI* | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| UART* | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | ❓ | ❓ | ✅ |
| SPI* | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | N/A | ❓ | ✅* |
| I2C | ✅ | ✅ | ✅ | ❓ | ❓ | ❓ | ❓ | ❓ | ✅ |
| ADC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Timer(PWM) | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | ✅ | ✅ | ✅ |
| IWDG | ✅ | N/A | N/A | ❓ | N/A | N/A | N/A | N/A | ❓ |
| WWDG | ✅ | N/A | N/A | ❓ | N/A | N/A | N/A | N/A | ❓ |
| CRC | ✅ | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ❓ |
| USBD | ✅* | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A |
| USB/OTG FS | ✅* | N/A | N/A | N/A | ✅* | ✅* | N/A | N/A | ✅* |
| USB HS | ✅* | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ❓* |
| USB SS | N/A | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ✅* |
| USB PD | N/A | N/A | N/A | N/A | ✅* | ✅* | ❓ | ❓ | ❌ |
| ETH* | ✅† | N/A | N/A | N/A | N/A | N/A | N/A | N/A | ✅† |
| CAN* | ✅ | N/A | N/A | N/A | N/A | ✅ | N/A | N/A | ✅ |
* marks the async driver (EXTI is also opt-in via the exti Cargo feature)§ PIOC is behind the manual pioc Cargo feature and needs a firmware image;
X0 and H4 are board-tested, CH643 follows X0.† ETH: the CH32V208 10M MAC+PHY and the H4 internal 10/100 PHY are
validated; the V305/V307 Synopsys DWC MAC is in progress (PR #157), and the
H4 RGMII/Gigabit path is not board-tested.‡ H4 is the dual-core CH32H417 (QingKe V3F + V5F). USB FS is the OTG-v2
device block (usbfs_h4, reusing the otg_fs driver); USB HS reuses the
V4x7 driver (usbhs_h4) and has not been validated at High Speed. USB SS
(usbss) is a SuperSpeed device driver for embassy-usb; host mode only
brings the link up. USB PD is compiled out because the H4 register layout
differs. I2C is flagged version: v3 in the H4 metadata, so the V3 driver
applies as-is. DMA is not in the table; the H4 DMAMUX is driven from
request numbers in metadata. The H4 Embassy time driver is
time_driver_systick_h4, so no time-driver-timN feature is needed.V00X covers CH32V002 / CH32V004 / CH32V005 / CH32V006 / CH32V007 and CH32M007.
I2C also has slave support (blocking, interrupt and DMA); see
examples/ch32l103/src/bin/i2c_slave.rs,
validated on the CH32L103 against a CH32V203 master.
Dual-core examples for the CH32H417 (separate V3F and V5F images, a shared
mailbox, xtask for flash/report) live in examples/ch32h417.
mod.rs to understand what is / is not tested.platform-spin, which never sleeps. platform-riscv32 sleeps in WFI between polls, and on the CH32V003 and CH32V203 the DMA makes no progress while the core sleeps. One-shot DMA transfers keep the executor awake on these chips: while one is pending the core keeps polling instead of sleeping, and with scheduler-priority its task can starve lower-priority tasks. Ring-buffered reception (RingBufferedUartRx) does not keep the executor awake and loses bytes on these chips with platform-riscv32, so keep platform-spin if you use it.Warning All CH32V2 and CH32V3 series chips support configurable ROM/RAM split. The configuration is stored in
FLASH_OBR.RAM_CODE_MODregister (read-only at runtime, can only be modified via external tools).If your program crashes immediately after flashing (e.g., Store Access Fault at stack addresses), your chip's ROM/RAM configuration likely doesn't match the linker script.
Symptoms:
mcause=0x7 (Store/AMO access fault)sp) points to invalid memory regionSolution: Use WCH's official tool (WCHISPTool) to configure the ROM/RAM split to match the default values defined in ch32-data.
The linker script expects the default RAM size for each chip. Check your chip's YAML definition in ch32-data for the expected memory layout.
This section lists some key items that are not implemented yet. And should be noted when using this crate.
This is a list for awesome projects that are built using ch32-hal
This project is developed with a recent nightly version of Rust compiler. And is expected to work with beta versions of Rust.
Feel free to change this if you did some testing with some version of Rust.
All kinds of contributions are welcome.
This project is licensed under the MIT or Apache-2.0 license, at your option.
browse all types & interfaces →
$ claude mcp add ch32-hal \
-- python -m otcore.mcp_server <graph>