This repo is about progamming the CH32V307 microcontroller using raw RISCV32 assembly and an open source toolchain. Specifically, this was written for the CH32V307V-R1-1v0 devboard (about $15 on LCSC).
Since the devboard comes with a debug interface, it is great for learning RISCV programming.
Since the docs on the memory map are terrible, here is a quick overview:
- program flash starts at 0x08000000
- sram (program ram) starts at 0x20000000
- peripheral control memory starts at 0x40000000
- http://www.wch-ic.com/downloads/CH32FV2x_V3xRM_PDF.html (more useful)
- chapter 10.3.1 lists GPIO registers
- http://www.wch-ic.com/downloads/CH32V307DS0_PDF.html (less useful)
- http://www.wch-ic.com/downloads/QingKeV4_Processor_Manual_PDF.html
- https://github.com/openwch/ch32v307/tree/main -- Github containing links to docs and schematics
Make sure you have llvm and clang installed. Then install wlink.
cargo install --git https://github.com/ch32-rs/wlink
./build.sh
Look at build.sh
to learn how to assemble your own code.
I promise it's just two commands.
To dump the generated code for a compiled example, run:
cd examples/<EXAMPLE>
llvm-objdump -d main.o
Plug in your devboard, then run
cd examples/<EXAMPLE>
wlink flash main.bin
To dump all registers, run
wlink regs
To dump memory, run
wlink dump <ADDRESS> <SIZE>
and you get a nice hexdump-like view of the memory range.
To write registers and memory, you can use
wlink write-reg <REG> <VALUE>
and
wlink write-mem <ADDRESS> <VALUE>