Go to file
alexis 6e2d2d9152 Initial commit 2022-11-25 18:20:14 -07:00
ch32v103 Initial commit 2022-11-25 18:20:14 -07:00
src Initial commit 2022-11-25 18:20:14 -07:00
.gitignore Initial commit 2022-11-25 18:20:14 -07:00
Dockerfile Initial commit 2022-11-25 18:20:14 -07:00
Makefile Initial commit 2022-11-25 18:20:14 -07:00
README.md Initial commit 2022-11-25 18:20:14 -07:00
meson.build Initial commit 2022-11-25 18:20:14 -07:00
meson_cross_riscv.txt Initial commit 2022-11-25 18:20:14 -07:00
wch-riscv.cfg Initial commit 2022-11-25 18:20:14 -07:00

README.md

WCH CH32V103 build template

This repository is a template for a project built for the WCH CH32V103 RISC-V microcontroller, without using the MounRiver tools. A GCC toolchain is built in a Docker container to make the build simple on all decent platforms; I use it on macOS and have tested it on Linux.

You will need

Everything else is downloaded into the Docker container.

How to build and flash

  • Using Docker:
    • make — full build. Will create the docker container (expect 10-30min) if needed.
    • make wipe — full clean and rebuild.
  • Building locally, if you have your own toolchain already:
    • make lall ("local all")
    • make clean lall (equivalent to make wipe)
  • To flash:
    • make flash

make flash expects to find a WCH-compatible patched openocd on the system PATH. If yours lives elsewhere, define OPENOCD_DIR on the environment.

What's in here?

The directory tree contains:

  • Dockerfile — specification for the Docker image, which will be called riscv-ubuntu.
  • Makefile — makefile, orchestrating Docker, Meson, and OpenOCD.
  • meson.build — meson build file; this does the actual build.
  • meson_cross_riscv.txt — meson cross-compile definition file
  • wch-riscv.cfg — OpenOCD configuration for the CH32V103
  • ch32v103/ — WCH's support code, Apache 2.0 licensed
    • Core/ — RISC-V core support components
    • Debug/ — a few janky debug helpers WCH threw in
    • Ld/ — linker script
    • Peripheral/ — peripheral drivers
    • Startup/ — startup/CRT code
  • mbuild/ — output build directory
  • src/ — project source code
    • ch32v10x_it.c and .h — interrupt handlers (this file is not special, you could delete it)
    • main.c — contains main()
    • mcu_config.h — some hardware configuration I factored out of the WCH libs
    • system_ch32v10x.c and .h — clock/power startup code

Making it yours

  • Put code under src/ (you can start in main.c if you like)
  • Edit meson.build to list the files that need to be built, and select which peripheral libraries you want
    • Consider changing the project name from firmware for more descriptive filenames
  • Replace this readme with your own

Changes I made to the WCH support code

  • Pull user config values out of system_ch32v10x.c and ch32v10x.h into mcu_config.h.

Other useful resources

Nobody seems to link directly to these except WCH themselves, so I'm putting them here:

Copying and changing

Intellectual property is bullshit and fake, steal this and don't credit me. You might want to credit WCH for their parts, which have a pesky Apache 2.0 license header on them.