RepositoryRustCNTrung Quốc
ch32-rs

ch32-rs/ch32-hal

A Rust HAL implementation for the CH32V0, CH32V1, CH32V2, CH32V3, CH32X0, CH32L1 family, with Embassy framework support and compatible with embedded-hal.

261sao
90fork
12issue
1lượt xem

ch32-hal

Demo Code Github Actions

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:

  • Embassy support
  • All-in-one metapac for peripheral register access, check ch32-data for more
  • All-in-one HAL crate, no need to create a new crate for each chip
  • Async drivers, with async/await support, DMA support
  • Write once, run on all supported chips(should be)

Supported Devices and Peripherals

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.

FamilyV2/V3V1V003V00XX0L1CH641CH643H4‡
Embassy✅✅✅✅✅✅✅✅✅
RCC✅✅✅✅✅✅✅✅✅
GPIO✅✅✅✅✅✅✅✅✅
PIOC§N/AN/AN/AN/A✅N/AN/A✅✅
EXTI*✅✅✅✅✅✅✅✅✅
UART*✅✅✅❓✅✅❓❓✅
SPI*✅✅✅❓✅✅N/A❓✅*
I2C✅✅✅❓❓❓❓❓✅
ADC✅✅✅✅✅✅✅✅✅
Timer(PWM)✅✅✅❓✅✅✅✅✅
IWDG✅N/AN/A❓N/AN/AN/AN/A❓
WWDG✅N/AN/A❓N/AN/AN/AN/A❓
CRC✅N/AN/AN/AN/AN/AN/AN/A❓
USBD✅*N/AN/AN/AN/AN/AN/AN/AN/A
USB/OTG FS✅*N/AN/AN/A✅*✅*N/AN/A✅*
USB HS✅*N/AN/AN/AN/AN/AN/AN/A❓*
USB SSN/AN/AN/AN/AN/AN/AN/AN/A✅*
USB PDN/AN/AN/AN/A✅*✅*❓❓❌
ETH*✅†N/AN/AN/AN/AN/AN/AN/A✅†
CAN*✅N/AN/AN/AN/A✅N/AN/A✅
  • ✅ : Expected to work
  • ❌ : Not implemented
  • ❓ : Not tested
  • * 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.
  • N/A: Not available

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.

Notes

  • For USB OTGFS, HS and SS, look at the respective mod.rs to understand what is / is not tested.
  • Embassy executor: most examples use 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.

Important: ROM/RAM Split Configuration (CH32V2/V3)

Warning All CH32V2 and CH32V3 series chips support configurable ROM/RAM split. The configuration is stored in FLASH_OBR.RAM_CODE_MOD register (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:

  • Program crashes with mcause=0x7 (Store/AMO access fault)
  • Stack pointer (sp) points to invalid memory region
  • No output or immediate crash after reset

Solution: 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.

TODOs

This section lists some key items that are not implemented yet. And should be noted when using this crate.

  • PLL2 for CH32V3
  • DMA2 for CH32V3 (requires special handling of high DMA channels)

Coming New Chips - Help Wanted

  • CH645, USB HUB, SerDes (V4C)
  • CH564, USBHS, 100M Ethernet (V4J)

Built with ch32-hal ✨

This is a list for awesome projects that are built using ch32-hal

Minimum supported Rust version(MSRV)

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.

Contributing

All kinds of contributions are welcome.

  • Share your project at Discussions
    • if your project is an open-source project, consider adding it to the list above
  • README and Documentation, including doc comments in code
  • Writing demo code for peripherals
  • Revising the peripheral definitions at ch32-data
  • Adding new peripheral drivers - This is difficult to make it compatible with all chips, but you can try.
  • ...

License

This project is licensed under the MIT or Apache-2.0 license, at your option.

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryRust
embassy-rs/embassy

Modern embedded framework, using Rust and async.

10.2k
Dec 1, 2026
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026
Repository
getify/You-Dont-Know-JS

A book series (2 published editions) on the JS language.

184.8k
Oct 31, 2026
RepositoryRust
farion1231/cc-switch

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

158.7k
Dec 2, 2026
RepositoryRust
tauri-apps/tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

113.4k
Dec 1, 2026
RepositoryRust
spacedriveapp/spacedrive

Spacedrive is an open source cross-platform file explorer, powered by a virtual distributed filesystem written in Rust.

39.6k
Nov 25, 2026
RepositoryTypeScript
toeverything/AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

81.6k
Dec 2, 2026
RepositoryC
raysan5/raylib

A simple and easy-to-use library to enjoy videogames programming

35.8k
Nov 25, 2026
RepositoryTypeScript
nilbuild/developer-roadmap

Interactive roadmaps, guides and other educational content to help developers grow in their careers.

373.1k
Dec 1, 2026