When we first wrote about the 10-cent CH32V003 RISC-V MCU it was offered in a $7 development board and the closed-source MounRiver Studio IDE had to be used for programming. But things have improved since October 2022, and now, you can buy a CH32V003 board for as little as $1.5 plus shipping, and an open-source GCC toolchain and flasher/downloader are now available.
Let’s have a look at the hardware first with the low-cost nanoCH32V003 development board featuring a 48 MHz CH32V003 RISC-V microcontroller with 2KB SRAM and 16KB flash, a USB Type-C port for power, a reset button, and two rows of headers for the GPIOs.
- MCU – WCH CH32V003F4U6 32-bit RISC-V2A microcontroller up to 48 MHz with 2KB SRAM, 16KB flash (QFN20 package)
- Expansion – 2x 11-pin headers with up to 18x GPIOs, 1x USART, 1x I2C, 1x SPI, 8-channel 10-bit ADC, 5V, 3.3V, GND
- Debugging – 3-pin 1-wire serial debug interface to connect WCHLink-E debugger
- Misc – 24MHz crystal oscillator, Reset button, and LED
- Power Supply – 5V via USB-C port
- Dimensions – TBD
The board requires the WCHLink-E debugger shown on the right above for programming and debugging. MuseLab provides PDF schematics, demo binaries, tools, and documentation on GitHub. Two development methods are available: the usual MounRiver Studio IDE and WCH-LinkUtility for the WCH-LinkE downloader/debugger, and an open-source toolchain based on GCC named xPack RISC-V Embedded GCC along with samples that can be compiled with make:
git clone https://github.com/wuxx/CH32V003-makefile-example
But you’d still need to use the WCH-LinkUtility programs to flash the resulting binary to the board through the WCHLink-E debugger.
That’s unless you rely on CNLohr work, as he played with the CH32V003 MCU to create the Makefile samples compiled with the gcc-riscv64 toolchain and the minichlink open-source utility to flash the program to the board. It can be tried with the blink sample as follows:
sudo apt-get install build-essential libnewlib-dev gcc-riscv64-unknown-elf libusb-1.0-0-dev
It fails for me because the make command will not only compile the sample, but also flash the hex file to the board, and I don’t have the board nor the WCHLink-E debugger attached to my computer:
riscv64-unknown-elf-gcc -o blink.elf blink.c ../ch32v003evt/startup_ch32v00x.S ../ch32v003evt/embedlibc.c -g -Os -flto -ffunction-sections -static-libgcc -lgcc -march=rv32ec -mabi=ilp32e -I/usr/include/newlib -I../ch32v003evt -nostdlib -I. -T ../ch32v003evt/ch32v003.ld -Wl,--gc-sections
text data bss dec hex filename
596 0 256 852 354 blink.elf
riscv64-unknown-elf-objdump -S blink.elf > blink.lst
riscv64-unknown-elf-objdump -t blink.elf > blink.map
riscv64-unknown-elf-objcopy -O binary blink.elf blink.bin
riscv64-unknown-elf-objcopy -O ihex blink.elf blink.hex
make -C ../minichlink all
make: Entering directory '/home/jaufranc/edev/sandbox/ch32v003fun/minichlink'
make: Nothing to be done for 'all'.
make: Leaving directory '/home/jaufranc/edev/sandbox/ch32v003fun/minichlink'
../minichlink/minichlink -w blink.bin -r
Error: couldn't find wch link device
make: *** [Makefile:37: flash] Error 247
The toolchain and utility can be used in Windows, Linux and/or WSL, but minichlink program still needs some work as it currently ignores all the response codes, except when querying the chip. As a side note, there’s also another project that updated OpenOCD to support CH32V003 microcontroller.
You can purchase the nanoCH32V003 for $1.5 on Aliexpress. But that price does not include shipping ($3.78 here), and you may want to purchase a pack of ten for $15 instead since the shipping fee is the same. You may also want to get one WCHLinkE provided in a $6.5 bundle with the nanoCH32V003 since it’s needed to program the board.
Via LinuxGizmos and thanks to Zoobab and Jon for the tips.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.