Bare metal programming on WCH RISC-V MCU CH32V307VCT6 board (CH32V307V-EVT-R1)
This repository implements an entirely manually-written, pure bare metal Blinky Project for the SiFive RISC-V MCU CH32V307VCT6 board (CH32V307V-EVT-R1).
Features include:
- CPU, power, chip, clock and PLL initialization,
- timebase derived from the
R32_STK
timer, - blinky LED show with adjustable frequency,
- implementation in C99 with absolute minimal use of assembly.
Clear and easy-to-understand build systems based on either GNUmake or CMake complete this fun and educational project.
This repository provides keen insight on starting up a bare metal SiFive RISC-V controller. It emphasizes simplicity and independence from monolithic toolchains through its lightweight, self-written implementation.
The application boots from a tiny startup code in the boot ROM.
Following low-level chip initialization, the program jumps to
the main()
subroutine. Here the timer interrupt is setup
for LED blinky.
The adjustable LED-phase (its half-period) can be tuned
to provide a rudimentary, visible blinky LED show.
The timebase for blinky is based on the R32_STK
timer
with an interrupt handler once per second.
Blinky running on the target is shown in the image below.
A wire is required connecting port pins PC0
and LED1
in order to observe the blinky toggle. See the orange wire
in the picture.
Build on *nix*
is easy using gcc-riscv32-unknown-elf
Both classic GNUmake as well as CMake can be used to build the Application:
cd WCH_V307_RISC-V/Build
./Rebuild.sh
mkdir Output && cd Output
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-unix.cmake .. && make
The build results including ELF-file, HEX-mask, MAP-file
and assembly list file are created in the Output
directory.
If gcc-riscv32-unknown-elf
is not installed, it can easily
be obtained from embecosm.
If necessary, add the path of the RISC-V GCC tools' bin folder to
$PATH
in the usual *nix
way.
CI runs on pushes and pull-requests with simple
build(s) including result verification on ubuntu-latest
and macos-latest
using GitHub Actions.
- The source and build code written for this repo are licensed under The Unlicense.
- The system-register file
riscv-csr.h
, originally from five-embedded, is also licenced under The Unlicense.