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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Europe's three largest chip giants re-examine their supply chains
- Breaking through the intelligent competition, Changan Automobile opens the "God's perspective"
- The world's first fully digital chassis, looking forward to the debut of the U7 PHEV and EV versions
- Design of automotive LIN communication simulator based on Renesas MCU
- When will solid-state batteries become popular?
- Adding solid-state batteries, CATL wants to continue to be the "King of Ning"
- The agency predicts that my country's public electric vehicle charging piles will reach 3.6 million this year, accounting for nearly 70% of the world
- U.S. senators urge NHTSA to issue new vehicle safety rules
- Giants step up investment, accelerating the application of solid-state batteries
- Guangzhou Auto Show: End-to-end competition accelerates, autonomous driving fully impacts luxury...
- Design of two-choice multiplexer excitation
- VGA Display Circle - Simple Design and Application FPGA
- SDR development board BladeRF, HackRF, USRP
- Does battery charging affect stm32 adc sampling?
- Internet of Things (IoT) solutions based on CC3120/CC3220 products
- MSP430 touch button
- 【Toshiba Photorelay TLP3547 Review】-1
- Multisim noise simulation and noise coefficient simulation issues
- Millimeter wave radar is used in automobile collision avoidance system
- LIS3DH X-axis data output abnormality