WCH usually does not provide good development support to macOS or Linux. Thanks for the open source world, there are always geeks that port the development environment. Kudos for you!
MounRiver Studio is the WCH official development environment. However, it only support Windows, so I never tried since I do not have a Windows environment.
I started CH32V003 from Stefan Wagner's CH32V003 RISC-V Mini Game Console. It is a great experience to begin with Stefan's projects, as there are always clear guides and the projects are self-contained. I then moved to CNLohr's ch32v003fun as there are more examples.
Install RISC-V Toolchain.
brew tap riscv-software-src/riscv
brew install riscv-tools
This project uses the minichlink
utility to upload, so the libusb
is required as a dependency.
brew install libusb
Clone the project, connect the board to the programmer, then run the make
command to compile and upload the firmware.
git clone https://github.com/limingjie/CH32V003-ST7789-Driver.git
cd CH32V003-ST7789-Driver/Examples/DrawTest
make
The minichlink
utility in the tools
library is built for x86_64
. If your macOS runs on Apple Silicon, you can build the minichlink
utility easily.
brew install pkg-config
brew install libusb
git clone https://github.com/cnlohr/ch32v003fun.git
cd ch32v003fun/minichlink
make
The PD1/SWDIO
, PD4
, and PD5
share the same pin on CH32V003J4M6. After the program uploaded, it is not possible to upload again. Use the minichlink -u
command to clear all code flash (unbrick) and then upload.
minichlink -u
The platform-ch32v project provides PlatformIO support to CH32V serial of chips, follow the documentation to setup the environment.
The project seems directly use the WCH official header files. I tried port some code to the PlatformIO, and it is qute easy as long as I change the registers directly instead of calling the functions. There are some differences on macro names.
To program the CH32V003 microcontroller, you will need a programmer that supports SWD.
- The official WCH-LinkE programmer.
- Check CNLohr's ch32v003fun project for other options, such as ESP32S2 and Arduino-based programmers.
WCH-LinkE | CH32V003 |
---|---|
SWDIO | SWIO |
GND | GND |
3V3 | VDD |
If the blue LED on the WCH-LinkE is always on, it is in ARM mode. To program CH32V003, it needs to be in RISC-V mode. Hold the Modes key while plugging it in the USB port.