An open source development environment (tooling, headers, examples) for the CH32V003 (and many other chips within the CH32V family) with gcc-riscv64 that can be used in Windows (Native), Linux and/or WSL. The CH32V003 is 10-cent part with a RISC-V EC core that runs at 48MHz, has 16kB of flash and 2kB of RAM and a bunch of peripherals. It also comes in SOP-8, QFN-20 and SOIC packages. You can get the datasheet here.
The goal of this project is to develop the tooling and environment for efficient use of the CH32V003. Avoid complicated HALs, and unleash the hardware! The existing EVT is massive, and dev environment weighty. This project specifically avoids the HAL and makes it so you can just use the TRM. In contrast, blinky is only 500 bytes with ch32v003fun, boots faster, and significantly simpler overall.
ch32v003fun contains:
misc/libgcc.a
.Currently, there is experimental support for the ch32v103, ch32v203, ch32v208, ch32v303 and ch32v307. Note: GDB will only workon the 003 at this time.
For installation / setup instructions, see the wiki page here
And by fast I mean very fast. Typically around 36kBytes/sec.
./minichlink -T | pv > /dev/null
Found ESP32S2 Programmer
536KiB 0:00:15 [36.7KiB/s] [ <=> ]
You can just try out the debugprintf project, or call SetupDebugPrintf(); and printf() away.
Via gdbserver built into minichlink! It works with gdb-multiarch
as well as in Visual Studio Code
cd examples/blink
make
text = code, data = constants and initialization values, bss = uninitialized values.
dec is the sum of the 3 and reflects the number of bytes in flash that will get taken up by the program.
The generated .bin is used by minichlink and the .hex file is compatible with the official WCH flash tool.
Note: With PlatformIO is genearlly used for CI on this repo. However, note that this is not the path that allows for debugging on Windows (For that see template project)
This project can also be built, uploaded and debugged with VSCode and the PlatformIO extension. Simply clone and open this project in VSCode and have the PlatformIO extension installed.
See here for further details.
If the C/C++ language server clangd is unable to find ch32v003fun.h
, the example will have to be wiped make clean
and built once with bear -- make build
, which will generate a compile_commands.json
, which clangd uses to find the include paths specified in the makefiles.
make clangd
does this in one step.
build_all_clangd.sh
does in build scripts
does this for all examples.
SWIO
is on PD1
. Do not re-use PD1 for multiple functions.NRST
is on PD7
. Not needed, defaults as GPIO in some configurations.TX
is on: PD5
. We recommend using SWIO for printf
debugging.
Other third party tools are adding lots of examples, etc. See the following repos, for extra libraries, etc.
You can open a github ticket or join my Discord in the #ch32v003fun channel. Right now invites are private, so just ping me @cnlohr for an invite link. My PMs are open.
CPI/Processor Speed:
Ignoring branches and load/stores, compressed instructions run at 1 CPI. Non-compressed instructions run at 1 CPI for the first 2 instructions, then further ones take 2 CPI regardless of how many more you have. Running from RAM and running from FLASH have slightly different performance characteristics depending on wait states that should be measured in-situation.