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 |
|---|---|---|---|---|---|---|---|---|
| Embassy | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| RCC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| GPIO | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| EXTI* | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| UART* | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | ❓ | ❓ |
| SPI* | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | N/A | ❓ |
| I2C | ✅ | ✅ | ✅ | ❓ | ❓ | ❓ | ❓ | ❓ |
| ADC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Timer(PWM) | ✅ | ✅ | ✅ | ❓ | ✅ | ✅ | ✅ | ✅ |
| USBD | ✅* | 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 | N/A | N/A |
| USB HS | ✅* | 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)† ETH: only the CH32V208 10M MAC+PHY. V305/V307 Synopsys DWC MAC is in progress (PR #157)V00X covers CH32V002 / CH32V004 / CH32V005 / CH32V006 / CH32V007 and CH32M007.
mod.rs respsectively to understand what is / is not tested.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.
$ claude mcp add ch32-hal \
-- python -m otcore.mcp_server <graph>