Hardware Preparation
CH32V103 Development Board/Core Edition
WCH-Link
Software Preparation
The software is mainly RISC-V GCC for compilation, and OpenOCD for burning. Both of them need to use the Qinheng version
RISC-V GCC can only use the WCH version for now. The public version cannot correctly handle interrupts defined as interrupt ("WCH-Interrupt-fast")
OpenOCD can only use the WCH customized version for now, the public version cannot recognize wlink
Toolchain provided by MounRiver, including RISC-V GCC and OpenOCD
Go to http://mounriver.com/download and download MRS_Toolchain_Linux_x64, currently MRS_Toolchain_Linux_x64_V1.50.tar.xz, RISC-V GCC version is 8.2.0.
Unzip the toolchain compressed package, the directory structure is
── beforeinstall
│ ├── 50-wch.rules
│ ├── 60-openocd.rules
│ ├── libhidapi-hidraw.so -> libhidapi-hidraw.so.0.0.0
│ ├── libhidapi-hidraw.so.0 -> libhidapi-hidraw.so.0.0.0
│ ├── libhidapi-hidraw.so.0.0.0
│ ├── libhidapi-libusb.so -> libhidapi-libusb.so.0.0.0
│ ├── libhidapi-libusb.so.0 -> libhidapi-libusb.so.0.0.0
│ ├── libhidapi-libusb.so.0.0.0
│ ├── libjaylink.so -> libjaylink.so.0.1.0
│ ├── libjaylink.so.0 -> libjaylink.so.0.1.0
│ ├── libjaylink.so.0.1.0
│ ├── libmcuupdate.so
│ ├── libncurses.so.5 -> libncurses.so.5.9
│ ├── libncurses.so.5.9
│ ├── libtinfo.so.5 -> libtinfo.so.5.9
│ ├── libtinfo.so.5.9
│ ├── libusb-1.0.so -> libusb-1.0.so.0.3.0
│ ├── libusb-1.0.so.0 -> libusb-1.0.so.0.3.0
│ ├── libusb-1.0.so.0.3.0
│ └── start.sh
├── OpenOCD
│ ├── bin
│ │ ├── openocd
│ │ ├── wch-arm.cfg
│ │ └── wch-riscv.cfg
│ ├── README.md
│ └── share
├── README
└── RISC-V Embedded GCC
├── bin
├── distro-info
├── include
│ └── gdb
│ └── jit-reader.h
├── lib
│ ├── bfd-plugins
│ └── gcc
├── lib64
│ ├── libcc1.so -> libcc1.so.0.0.0
│ ├── libcc1.so.0 -> libcc1.so.0.0.0
│ ├── libcc1.so.0.0.0
│ ├── libgcc_s.so.1
│ ├── libstdc++.so.6 -> libstdc++.so.6.0.24
│ └── libstdc++.so.6.0.24
├── libexec
│ └── gcc
├── README.md
├── riscv-none-embed
└── share
in
The beforeinstall directory contains the dynamic link library files and device rule files that need to be configured in Ubuntu.
The start.sh file contains commands to set up the environment
The OpenOCD directory contains a custom openocd executable file, as well as the corresponding wch-arm and wch-riscv configuration files.
RISC-V Embedded GCC RISC-V Compiler
Install
RISC-V GCC Installation
This part is relatively simple. Create a gcc-riscv directory in the /opt directory, unzip the tool and copy it there, set the corresponding permissions, the path will be used later when configuring the Makefile, and use --version to verify whether it is normal
/opt/gcc-riscv$ /opt/gcc-riscv/wch-riscv-embed-gcc/bin/riscv-none-embed-gcc --version
If you use the public version of RISC-V GCC, it can also be compiled, but a warning will be thrown in the interrupt part. There is no problem running the while loop and GPIO, but when running the RTC module code, you will find that the interrupt per second is not executed.
OpenOCD Installation
Also unzip and copy to the /opt directory to verify
/opt/gcc-riscv$ /opt/openocd/wch-openocd/bin/openocd --version
Open On-Chip Debugger 0.11.0+dev-02215-gcc0ecfb6d-dirty (2022-06-23-10:21)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Environment Configuration
Before openocd can be burned normally, some environment configuration is required. Refer to the beforeinstall directory under the WCH toolkit.
1. Configure the dynamic link library
Because other tools are installed in the environment, to avoid conflicts, manually install the steps in start.sh. Create a separate directory under /usr/lib to place these dynamic link library files
cd /usr/lib
sudo mkdir wch-moun-river
sudo cp ./beforeinstall/lib* wch-moun-river/
Add ldconfig configuration for this new link library file directory, create the file wch-moun-river.conf under /etc/ld.so.conf.d/, the content is as follows
more /etc/ld.so.conf.d/wch-moun-river.conf
# lib for wch moun river studio
/usr/lib/wch-moun-river
Then the update takes effect
sudo ldconfig
If such a prompt appears, it means that there are multiple dynamic link libraries with the same name in the environment. If you do not want to see these warnings, you can delete these files or ignore them.
/sbin/ldconfig.real: /usr/lib/wch-moun-river/libtinfo.so.5 is not a symbolic link
2. Configure device permissions
First check whether there is any relevant configuration under /etc/udev/. If so, you need to integrate it with these two rules. If not, just copy it and update it.
sudo cp ./50-wch.rules /etc/udev/rules.d
sudo cp ./60-openocd.rules /etc/udev/rules.d
# Reload rules
sudo udevadm control --reload-rules
3. Check whether it is effective
Connect WCH-Link and the development board to the computer. At this time, dmesg should be able to detect the WCH-Link device normally. Check whether WCH-Link is running in WCH-Link mode. If it is running in DAP-Link mode, you need to switch it.
[ 2449.285125] usb 2-3: USB disconnect, device number 2
[ 2452.341042] usb 2-3: new full-speed USB device number 5 using xhci_hcd
[ 2452.494530] usb 2-3: New USB device found, idVendor=1a86, idProduct=8010, bcdDevice= 2.05
[ 2452.494543] usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2452.494549] usb 2-3: Product: WCH-Link
[ 2452.494554] usb 2-3: Manufacturer: wch.cn
[ 2452.494558] usb 2-3: SerialNumber: 0001A0000000
[ 2452.498525] cdc_acm 2-3:1.1: ttyACM0: USB ACM device
Go to the toolchain unzip directory and use OpenOCD to check whether it can connect normally.
./openocd -f wch-riscv.cfg -c init -c halt
# If the following information is displayed, the configuration is correct.
Open On-Chip Debugger 0.11.0+dev-02215-gcc0ecfb6d-dirty (2022-06-23-10:21)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'jtag'
Ready for Remote Connections
Info : WCH-Link-CH549 mod:RV version 2.5
Info: wlink_init ok
Info : This adapter doesn't support configurable speed
Info : JTAG tap: riscv.cpu tap/device found: 0x00000001 (mfg: 0x000 ( Warn : Bypassing JTAG setup events due to errors Info : [riscv.cpu.0] datacount=2 progbufsize=8 Info : Examined RISC-V core; found 1 harts Info : hart 0: XLEN=32, misa=0x0 [riscv.cpu.0] Target successfully examined. Info : starting gdb server for riscv.cpu.0 on 3333 Info : Listening on port 3333 for gdb connections Info : Listening on port 6666 for tcl connections Info : Listening on port 4444 for telnet connections If the following error is displayed, it means that the dynamic link library is configured incorrectly ./openocd: symbol lookup error: ./openocd: undefined symbol: jaylink_device_get_usb_bus_ports If the following error is displayed, it means that the customized openocd provided by wch is not used. wch-riscv.cfg:2: Error: invalid command name "adapter" in procedure 'script' at file "embedded:startup.tcl", line 60 at file "wch-riscv.cfg", line 2 Run the Example Project Export Project Export the project from GitHub to your local machine git clone https://github.com/IOsetting/ch32v103-template.git Modify project configuration Open Makefile and configure the tool path to your own path TOOL_CHAIN_PATH ?= /opt/gcc-riscv/wch-riscv-embed-gcc/bin OPENOCD_PATH ?= /opt/openocd/wch-openocd/bin The project name can be modified PROJECT_NAME = test001 Compile the project # Cleanup make clean # Compile make Burn make flash appendix Compile command and parameter description The basic format of the compilation command is as follows riscv-none-embed-gcc -march=rv32imac -mabi=ilp32 -msmall-data-limit=8 -mno-save-restore -You -fmessage-length=0 -fsigned-char -ffunction-sections -trusted-sections -Wunused -Wuninitialized -g -I"/home/milton/WorkRiscV/ch32v_ws001/ch32v103_test001/Debug" -I"/home/milton/WorkRiscV/ch32v_ws001/ch32v103_test001/Core" -I"/home/milton/WorkRiscV/ch32v_ws001/ch32v103_test001/User" -I"/home/milton/WorkRiscV/ch32v_ws001/ch32v103_test001/Peripheral/inc" -std=gnu99 -MMD -MP -MF"Peripheral/src/ch32v10x_crc.d" -MT"Peripheral/src/ch32v10x_crc.o" -c -o "Peripheral/src/ch32v10x_crc.o" "../Peripheral/src/ch32v10x_crc.c" Description of each parameter, quoted from RISC-V-Options, GCC C Dialect Options GCC Preprocessor Options -march=ISA-string Set the instruction set architecture Generate code for given RISC-V ISA (e.g. ‘rv64im’). ISA strings must be lower-case. Examples include ‘rv64i’, ‘rv32g’, ‘rv32e’, and ‘rv32imaf’. When -march= is not specified, use the setting from -mcpu. If both -march and -mcpu= are not specified, the default for this argument is system dependent, users who want a specific architecture extensions should specify one explicitly. -mabi=ABI-string Set the application binary interface Specify integer and floating-point calling convention. ABI-string contains two parts: the size of integer types and the registers used for floating-point types. For example ‘-march=rv64ifd -mabi=lp64d’ means that ‘long’ and pointers are 64-bit (implicitly defining ‘int’ to be 32-bit), and that floating-point values up to 64 bits wide are passed in F registers. Contrast this with ‘-march=rv64ifd -mabi=lp64f’, which still allows the compiler to generate code that uses the F and D extensions but only allows floating-point values up to 32 bits long to be passed in registers; or ‘-march=rv64ifd -mabi=lp64’, in which no floating-point arguments will be passed in registers. The default for this argument is system dependent, users who want a specific calling convention should specify one explicitly. The valid calling conventions are: ‘ilp32’, ‘ilp32f’, ‘ilp32d’, ‘lp64’, ‘lp64f’, and ‘lp64d’. Some calling conventions are impossible to implement on some ISAs: for example, ‘-march=rv32if -mabi=ilp32d’ is invalid because the ABI requires 64-bit values be passed in F registers, but F registers are only 32 bits wide. There is also the ‘ilp32e’ ABI that can only be used with the ‘rv32e’ architecture. This ABI is not well specified at present, and is subject to change.
Previous article:Lianshengde HLK-W806 (Thirteen): Run FatFs to read and write SD cards/TF cards in FAT and exFat formats
Next article:STC8H Development (XIV): I2C driver for RX8025T high-precision real-time clock chip
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- EEWORLD University Hall----Live Replay: Future Perception is Predicted by Me-The Latest Application of Sensors in the Internet of Things
- Design of Power Amplifier Circuit for MSP430F449 Single Chip Microcomputer
- Senior Sales Engineer
- [MM32 eMiniBoard Review] + Reunion with Smart Development Board
- [2022 Digi-Key Innovation Design Competition] Home Smart Dashboard - LVGL transplantation and testing
- 5G system core capability indicators
- The relationship between the four major parameters of RF microwave
- DSP basic experiment: light emitting diode display led.c
- [RVB2601 development board trial] speaker experiment
- [Shanghai Hangxin ACM32F070 development board] Light up the LCD screen and touch button function operation, drive the buzzer evaluation