This example is taken from https://github.com/infphyny/ch32v307_GPIO_Toggle which was taken from https://github.com/openwch/ch32v307 repository.
The goal of this project is to compile binary file for CH32V307V-EVT-R1 eval board without using the MounRiver IDE, and without installing the toolchain on the local machine
- Wiring
Plug a male to female wire from PA0 to LED1. Plug a male to female wire from PB0 to USER.
- Setup udev rules
Create a file named 98-ch549.rules in directory /etc/udev/rules.d/
Inside the file write:
ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="8010", MODE="0666"
Save the file then execute:
udevadm control --reload-rules
- Download MounRiver MRS toolchain
In the current state, closed source MounRiver openocd version is needed to upload the binary file to the board. So download MRS_Toolchain_Linux_x64_V1.30.tar.xz and decompress in a directory.
Note: They are supposed to release the source code for their wch flash driver.
-
RiscV toolchain using container login to github container registry
docker login ghcr.io
-
Compile the binary file In src folder
make
to compile GPIO_Toggle.bin file
- Upload binary file
Execute in MRS_Toolchain_Linux_x64_V1.30/OpenOCD/bin
./openocd -f wch-riscv.cfg
For convenience copy GPIO_Toggle.bin in MRS_Toolchain_Linux_x64_V1.30/OpenOCD/bin.
In the same directory, open another terminal and execute
telnet localhost 4444
Inside telnet session at the prompt:
type
halt;
after type
flash write_image erase bin/baremetal/template_app
Press reset button to execute the binary.
-
ARCH in the makefile is set to rv32imafc. ABI is set to ilp32f. May need modification. After analysing the 8 uarts demo application, CH32V307 add a custom instruction sets: xw and arch is rv32imacxw. I didn't found any documentation yet for this instructions. Instructions are defined in the file riscv-op. in binutils.
-
Compile optimization is set to -Os.