CH32V003 Firmware & Linux Development Setup
This folder contains the firmware source code for the CNC Water Flow Controller, built using the ch32fun framework.
Below is the guide to set up the build environment, compile, and flash the CH32V003 series on Linux using CLI tools.
Tested on: Ubuntu Linux, CH32V003J4M6 (8-pin)
1. Install toolchain
Download xPack RISC-V GCC: https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases
Extract it:
mkdir -p ~/toolchains
tar -xzf xpack-riscv-none-elf-gcc-*-linux-x64.tar.gz -C ~/toolchains
Activate it (add this to your ~/.bashrc for permanence):
export TOOLCHAIN=$HOME/toolchains/xpack-riscv-none-elf-gcc-* # Update e.g.: xpack-riscv-none-elf-gcc-15.2.0-1
export PATH=$TOOLCHAIN/bin:$PATH
Verify the installation:
riscv-none-elf-gcc --version
2. Install Flashing Tool (minichlink)
Clone the ch32fun repository and build minichlink:
git clone https://github.com/cnlohr/ch32fun ~/ch32fun
cd ~/ch32fun/minichlink
make
sudo mv minichlink /usr/local/bin/
3. Build the Firmware
Navigate to this firmware directory where the Makefile and main.c are located. Make sure the ch32fun path in the Makefile points to where you cloned ch32fun.
cd Flow-Controller/firmware
make clean
make
This will generate main.bin and main.elf.
4. Flash Firmware
Connect your WCH-LinkE programmer to the board's J1 header:
| Signal | Programmer | MCU Header (J1) |
|---|---|---|
| SWIO | SWDIO | Pin 3 (SWIO) |
| GND | GND | Pin 2 (GND) |
| 5V | 3.3V | Pin 1 (+3.3V) |
| Flash the compiled binary: |
make flash
or manually:
minichlink -w main.bin flash
5. Logs
See logs on the SWIO pin:
minichlink -T
6. Unbricking
If you accidentally misconfigure the SWIO pin and lock yourself out, you can use the CH32V003 Unbrick CLI tool:
git clone https://github.com/shakir-abdo/ch32v003-unbrick.git
cd ch32v003-unbrick
npm install
./unbrick.js