2022-10-18 11:02:39 +08:00
# CH32V307V-R1 BSP Introduction
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
**English** | [中文 ](README_zh.md )
2022-08-24 09:51:35 +08:00
2022-10-19 09:40:42 +08:00
## 1 Introduction
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
CH32V307V-R1 is a RISC-V core-based development board with a maximum main frequency of 144Mhz. It delivers the best value for developers to try and get started with RISC-V architecture.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
This document records the execution instruction of the BSP (board support package) provided by the RT-Thread community for the CH32V307V-R1 development board.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
The document is covered in three parts:
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
- Board Resources Introduction
- Compiling
- Quickly Get Started
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
By reading the Quickly Get Started section developers can quickly get their hands on this BSP and run RT-Thread on the board.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
![board ](./figures/ch32v307.jpg )
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
**Features**
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
- MCU: CH32V307VCT6, main frequency 144MHz, FLASH and RAM are available for configuration.
- LED: 2, user LEDs, LED1(blue), LED2(blue).
- Button: 2, Reset, User.
- USB: 2, Tpye-C.
- Network Port: 1, 10M PHY inside.
- WCH-Link download debugging tools onboard.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
For more details about this board, please refer to: [CH32V307 ](https://www.wch.cn/products/CH32V307.html )
2022-08-24 09:51:35 +08:00
2022-10-19 09:40:42 +08:00
## 2 Compiling
2022-10-10 07:08:19 +08:00
2022-10-18 11:02:39 +08:00
The BSP supports the RISC-V GCC development environment, here's the specific version information:
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
| IDE/Compiler | Version Tested |
| ------------ | -------------------- |
| GCC | WCH RISC-V GCC 8.2.0 |
2022-08-24 09:51:35 +08:00
2022-10-19 09:40:42 +08:00
## 3 Quickly Get Started
2022-08-24 09:51:35 +08:00
2022-10-19 09:40:42 +08:00
### 3.1 Using [Env](https://www.rt-thread.io/download.html?download=Env) to compile BSP
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
This section is about to introduce how to use Env to compile the BSP.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
#### 3.1.1 Compile BSP
2022-08-24 09:51:35 +08:00
2022-10-19 09:40:42 +08:00
1. [Download WCH Compile Toolchain ](https://github.com/NanjingQinheng/sdk-toolchain-RISC-V-GCC-WCH/releases )
2022-10-18 11:02:39 +08:00
2. [Download the Env tool latest version ](https://github.com/RT-Thread/env-windows/releases )
3. [Download the RT-Thread latest code ](https://github.com/RT-Thread/rt-thread/archive/refs/heads/master.zip )
2022-10-19 09:40:42 +08:00
4. Open the Env tool in the current BSP root directory and execute the `scons -j12 --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0bin` command, compile it directly while specifying the toolchain location.
2022-10-18 11:02:39 +08:00
5. After compilation, the **rtthread.bin** file will be generated
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
![sconscompile ](./figures/sconscompile.jpg )
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
#### 3.1.2 Hardware Connection
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
Use a data cable to connect the onboard wch-link to the PC, and turn on the power switch.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
#### 3.1.3 Download
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
Open the WCH RISC-V MCU ProgrammerTool, select the **rtthread.bin** file that we just generated, and download it.
2022-08-24 09:51:35 +08:00
![tool ](./figures/tool.png )
2022-10-18 11:02:39 +08:00
> Note that Chip Mem here is set to 224K ROM + 96K RAM.
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
#### 3.1.4 Running Result
2022-08-24 09:51:35 +08:00
2022-10-18 11:02:39 +08:00
In the terminal tool, open the onboard wch-link serial port (WCHDapLink SERIAL, default 115200-8-1-N), and after resetting the device, you can see the output information of RT-Thread on the serial port:
2022-08-24 09:51:35 +08:00
![end ](./figures/end.png )
2022-10-15 11:06:24 +08:00
2022-10-19 09:40:42 +08:00
### 3.2 Use VSCode to edit and compile the project
In the Env terminal, type command `scons --target=vsc` to generate the VSCode project. Then, type command `code .` in the Env terminal to open the VSCode.
Use **VSCode terminal** to type command `scons -j12 --exec-path=D:\sdk-toolchain-RISC-V-GCC-WCH-1.0.0bin` to compile the project in VSCode.
![vscode-terminal ](./figures/vscode-terminal.png )
<!-- ### 3.3 Import RT - Thread Studio Project
2022-10-18 11:02:39 +08:00
**CH32V307V-R1 is pending upgrade in Studio. It's not encouraged now to use Studio to compile this BSP.**
2022-10-15 11:06:24 +08:00
2022-10-19 09:40:42 +08:00
#### 3.3.1 Import
2022-10-18 11:02:39 +08:00
Open RT-Thread Studio and click: File-> Import:
2022-10-15 11:06:24 +08:00
![import ](./figures/import.png )
2022-10-18 11:02:39 +08:00
Select "RT-Thread BSP Project into Workspace":
2022-10-15 11:06:24 +08:00
![windows ](./figures/windows.png )
填写项目信息, Bsp 根目录为 \rt-thread\bsp\wch\risc-v\ch32v307v-r1 目录:
2022-10-18 11:02:39 +08:00
Fill in the project info, the BSP root directory is \rt-thread\bsp\wch\risc-v\ch32v307v-r1:
2022-10-15 11:06:24 +08:00
![config ](./figures/config.png )
2022-10-19 09:40:42 +08:00
#### 3.3.2 Compilation Environment
2022-10-15 11:06:24 +08:00
工程导入后进行编译环境的设置,首先点击“打开构建设置”进入设置界面:
2022-10-18 11:02:39 +08:00
After the project is imported, set the compilation environment, click "Open Build Settings" to enter the setting interface:
2022-10-15 11:06:24 +08:00
![set ](./figures/set.png )
将编译链路径复制到 Toolchain path 中:
2022-10-18 11:02:39 +08:00
Copy the compilation chain path into the Toolchain path:
2022-10-15 11:06:24 +08:00
![toolchain ](./figures/toolchain.png )
2022-10-18 11:02:39 +08:00
Change Prefix:
2022-10-15 11:06:24 +08:00
![prefix ](./figures/prefix.png )
2022-10-18 11:02:39 +08:00
Set the tool:
2022-10-15 11:06:24 +08:00
![toolset ](./figures/toolset.png )
2022-10-19 09:40:42 +08:00
#### 3.3.3 Compiling
2022-10-15 11:06:24 +08:00
2022-10-18 11:02:39 +08:00
The result is shown as below:
2022-10-15 11:06:24 +08:00
2022-10-18 11:02:39 +08:00
![success](./figures/success.png -->