I could not find a small and simple blinky example for CH32V003 and probe-rs, so here it is!
I used CH32V003F4P6-EVT-R0 and WCH-LinkE. The project is set up for CH32V003F4P6 but should work with any other CH32V chip as well, just change it in Cargo.toml and .cargo/config.toml. The WCH-Link is detected automatically by probe-rs.
On CH32V003F4P6-EVT-R0, connect PD6 to LED1.
Between CH32V003F4P6-EVT-R0 and WCH-LinkE, connect:
VCC to 3V3
GND to GND
PD1 to SWDIO/TMS
- Install Rust and probe-rs. Recommend installing version 0.26.0 of probe-rs-tools as the latest version has a bug (probe-rs/probe-rs#3455). If installing the binary in Linux, use
https://github.com/probe-rs/probe-rs/releases/download/v0.26.0/probe-rs-tools-installer.sh, or for installing from source:
cargo install probe-rs-tools --version 0.26.0- Set up project to use Rust Nightly
cd ch32v003-blinky-rust
rustup install nightly
rustup override set nightly- Install std sources
rustup component add rust-src- Connect board and run with
cargo runor to run with the cargo-embed environment installed with probe-rs:
cargo embed- To open a debug environment in VSCode, add this to a launch.json file:
{
"type": "probe-rs-debug",
"request": "launch",
"name": "probe-rs ch32",
"cwd": "${workspaceFolder}",
"connectUnderReset": false,
"chip": "CH32V003",
"flashingConfig": {
"flashingEnabled": true,
"haltAfterReset": true
},
"probe": "1a86:8010",
"coreConfigs": [
{
"coreIndex": 0,
"programBinary": "./target/riscv32ec-unknown-none-elf/debug/${workspaceFolderBasename}"
}
]
}
This was based on the examples project in ch32-hal. You can find the original code here:
https://github.com/ch32-rs/ch32-hal/tree/main/examples/ch32v003