Skip to main content

CH32 Environment Setup

The RISC-V toolchain situation for the CH32 series is quite chaotic. The following two options are recommended:

  • The official riscv-wch-elf bundled with MRS: Supports WCH's rv32imafcxw extended instruction set, but has incomplete C++ standard library support, making it incompatible with libraries like Eigen.
  • Upstream riscv32-unknown-elf: Does not support WCH's extended instruction set, but provides complete C++ standard library support. On Windows, that means using MSYS2, which can be a bit of a hassle.

For quick compilation, you can use the Docker image provided by this project.

CMake Configuration

An additional option needs to be configured: LIBXR_CH32_CONFIG_FILE, which specifies the path to the CH32 peripheral library configuration file, such as: ch32v30x_conf.h.

set(LIBXR_SYSTEM FreeRTOS)
set(LIBXR_DRIVER ch)

set(LIBXR_CH32_CONFIG_FILE "ch32v30x_conf.h")

add_subdirectory(libxr)

...

Example Project

CH32V307+FreeRTOS+XRUSB