readme.md
1# Core-V-MCU BSP 说明
2
3[English](readme_EN.md) | **中文**
4
5## 1 MCU简介
6
7Core-V-MCU的目的是展示cv32e40p,这是Open Hardware Group(OpenHW)提供的经过充分验证的RISC-V内核。cv32e40p核心连接到一组具有代表性的外围设备。
8
9
10
11**Core-V-MCU资源:**
12
13- 2xUART
14- 2xI2C master
15- 1xI2C slave
16- 2xQSPI master
17- 1xCAMERA
18- 1xSDIO
19- 4xPWM
20- eFPGA with 4 math units
21
22更多信息请访问[Core-V-MCU介绍](https://docs.openhwgroup.org/projects/core-v-mcu/doc-src/overview.html)
23
24更多资源[OpenHW官网](https://www.openhwgroup.org/)
25
26## 2 编译说明
27
28板级包支持 RISC-V GCC 开发环境,以下是具体版本信息:
29
30| IDE/编译器 | 已测试版本 |
31| ---------- | ----------------------- |
32| GCC | riscv32-unknown-elf-gcc |
33
34## 3 使用说明
35
36>本章节是为在Core-V-MCU上使用RT-Thread的用户提供,Core-V-MCU目前没有实际的硬件,采用QEMU的方式实现模拟,本文使用的qemu为ubuntu18.04环境下编译qemu。
37
38### 3.1 使用Env编译BSP
39
40本节讲解如何使用Env工具来编译BSP工程。
41
42#### 3.1.1 编译BSP
43
441. 准备工作1:[下载Linux环境下GCC编译工具链](https://github.com/Yaochenger/openhw-/tree/master/toolchain)),将下载的工具链放在自己的Linux环境下。
45
462. 准备工作2:在Linux环境下安装ENV,在控制台运行以下命令。
47
48 ```shell
49 wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh
50 chmod 777 install_ubuntu.sh
51 ./install_ubuntu.sh --gitee
52 ```
53
543. 准备工作3:在Linux环境下编译PLCT实验室提供的[qemu]([plctlab/plct-qemu at plct-corev-upstream-sync-dma (github.com)](https://github.com/plctlab/plct-qemu/tree/plct-corev-upstream-sync-dma)),参考README.rst中给出的编译方法编译Linux环境下的qemu,或使用笔者编译好的[qemu](https://github.com/Yaochenger/openhw-/releases/tag/qemu-linux)。
55
564. Windows环境下载RT-Thread[最新源码](https://github.com/RT-Thread/rt-thread/archive/refs/heads/master.zip),此步骤同样可以在Linux环境下完成。
57
585. Windows环境下载当前BSP根目录下打开Env工具并执行以下命令编译,`scons --exec-path=工具链路径`,Windows下的工具链可以直接使用RT-Studio下载,工具链的路径依据用户的具体环境进行配置,此步骤同样可以在Linux环境下完成,示例命令如下:
59
60 ```shell
61 scons --exec-path=D:\RT-ThreadStudio\repo\Extract\ToolChain_Support_Packages
62 \RISC-V\RISC-V-GCC-RV32\2022-04-12\bin
63 ```
64
65 在指定工具链位置的同时直接编译,编译后生成rtthread.elf文件。
66
67 
68
696. 试运行rtthread.elf,将上步生成的rtthread.elf拷贝到编到编译的qemu工具的bin文件目录下,执行以下命令
70
71 ```shell
72 ./qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio
73 ```
74
75 运行结果如下:
76
77 
78
79 7.运行以下命令生成完整可拷贝的工程
80
81```shell
82scons --dist
83```
84
85将生成的独立工程拷贝到Linux环境下。
86
87### 3.2Liunx环境下编译运行工程
88
89#### 3.2.1 配置工程
90
911.在上文拷贝的完整的工程根目录下找到**rtconfig.h**,去掉该文件中的预编译命令**#ifndef RT_CONFIG_H__**,**#define RT_CONFIG_H__**,**#ifndef RT_CONFIG_H__**,**#endif**,一定要执行这步操作,否则会编译报错。
92
93
94
952.执行以下命令生成makefile工程
96
97```shell
98scons --target=makefile
99```
100
1013.在命令行输入**make**编译工程
102
1034.运行以下命令,启动qemu运行编译出rtthread.elf,`/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32`为Linux环境的工具链路径,这里设置为用户的工具链路径。
104
105```shell
106/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio
107```
108
109BSP支持RT-Thread的Finsh组件,输入version可以查看rt-thread的版本信息,Tap键可以查看支持的命令,运行结果如下:
110
111
112
113至此,基于Core-V-MCU的RT-Thread工程的配置与运行测试完成。
114
115### 3.3 将RT-Thread工程导入OpenHW的Core-V-IDE
116
1171.下载安装[core-v-sdk](https://github.com/openhwgroup/core-v-sdk),按照[README.md](https://github.com/openhwgroup/core-v-sdk#readme)中的步骤安装Linux环境下的IDE。
118
1192.在主目录下创建workspace文件夹,打开IDE将workspace文件夹作为工作路径。
120
1213.选择`Import projects选项 `。
122
123
124
1254.选择`Existing Code as Makefile Project选项`
126
127
128
1295.设置如下
130
131
132
1336.工程配置设置
134
135
136
1377.修改编译命令
138
139
140
1418.清空工程编译出的文件,重新编译工程
142
143
144
1459.在使用IDE编译的工程的根目录下运行以下命令,结果和**3.2.1**运行的结果一致IDE下的工程便配置完成,至此,IDE导入Core-V-MCU的RT-Thread工程的导入与运行测试完成。
146
147```shell
148/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio
149```
150
151### 3.4调试配置
152
1531.Debug Configurations 配置
154
155
156
1572.双击`GDB OpenOCD Debugging`,生成调试配置选项
158
159
160
1613.导入片上外设寄存器文件
162
163文件路径`OpenHW/CORE-V-SDKv0.0.0.4/registers/csr`,具体路径根据用户安装的SDK路径配置。
164
165
166
1673.导入片上外设寄存器文件
168
169文件路径`/home/wangshun/OpenHW/CORE-V-SDKv0.0.0.4/registers/peripheral`,具体路径根据用户安装的SDK路径配置。
170
171
172
1733.配置qemu运行环境
174
175取消`Start OpenOCD locally的勾选`,配置参数如下
176
177
178
1794.运行下述指令
180
181```shell
182/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio -s -S
183```
184
1855.点击debug开始调试
186
187 
188
189### 4.CLI组件
190
191 OPENHW提供的FreeRTOS工程支持一个CLI组件用于测试,在使用RT-Thread时为了兼容原有的CLI,所以将原来的CLI做成了独立的软件包,同时该软件包自动开启FreeRTOS兼容层,所以该软件包既可以支持原有的CLI组件,同时用户可以自行选择使用FreeRTOS的API或者RT-Thread的API。
192
193#### 4.1使用方法
194
195 在ENV工具中使用menuconfig配置开启CorevMCU_CL软件包,将example.c中的示例代码放到main.c提示的地方。使用menuconfig配置的步骤如下:
196
197> `RT-Thread online packages`
198> `miscellaneous packages --->`
199> ` [*] CorevMCU_CLI`
200
201
readme_EN.md
1# Core-V-MCU BSP Description
2
3English| [Chinese](readme.md)
4
5## 1 MCU Introduction
6
7The purpose of Core-V-MCU is to show cv32e40p, which is a fully validated RISC-V kernel provided by Open Hardware Group (OpenHW). The cv32e40p core is connected to a group of representative peripherals.
8
9
10
11**Core-V-MCU resources:**
12
13- 2xUART
14- 2xI2C master
15- 1xI2C slave
16- 2xQSPI master
17- 1xCAMERA
18- 1xSDIO
19- 4xPWM
20- eFPGA with 4 math units
21
22For more information, please visit[Introduction to Core-V-MCU](https://docs.openhwgroup.org/projects/core-v-mcu/doc-src/overview.html)
23
24More resources,please visit[OpenHW official website](https://www.openhwgroup.org/)
25
26## 2 Compilation Description
27
28The board level package supports the RISC-V GCC development environment. The specific version information is as follows:
29
30| IDE/Compiler | Tested version |
31| ------------ | ----------------------- |
32| GCC | riscv32-unknown-elf-gcc |
33
34## 3 Instruction for user
35
36>This chapter is provided for users who use RT Thread on the Core-V-MCU. At present, the Core-V-MCU has no actual hardware and uses QEMU to implement simulation. The qemu used in this article is compiled under the ubuntu18.04 environment.
37
38### 3.1 Compile BSP with Env
39
40This section explains how to use Env tools to compile BSP projects.
41
42#### 3.1.1 编译BSP
43
441. Preparation 1:[Download GCC compilation tool chain under Linux environment](https://github.com/Yaochenger/openhw-/tree/master/toolchain)),put the downloaded tool chain in your Linux environment.
45
462. Preparation 2:Install ENV under Linux environment, and run the following command on the console.
47
48 ```shell
49 wget https://gitee.com/RT-Thread-Mirror/env/raw/master/install_ubuntu.sh
50 chmod 777 install_ubuntu.sh
51 ./install_ubuntu.sh --gitee
52 ```
53
543. Preparation 3:Compile [qemu](https://github.com/plctlab/plct-qemu/tree/plct-corev-upstream-sync-dma) provided by PLCT lab in Linux environment,Refer to the compilation method given in README.rst to compile qemu in the Linux environment, or use the[qemu](https://github.com/Yaochenger/openhw-/releases/tag/qemu-linux).
55
564. Windows environment download RT Thread[最新源码](https://github.com/RT-Thread/rt-thread/archive/refs/heads/master.zip),This step can also be completed in the Linux environment.
57
585. Download in the Windows environment Open the Env tool under the current BSP root directory and execute the following command to compile, 'scons -- exec path=tool chain path'. The tool chain under Windows can be downloaded directly using RT Studio. The path of the tool chain is configured according to the user's specific environment. This step can also be completed in the Linux environment. The example command is as follows:
59
60 ```shell
61 scons --exec-path=D:\RT-ThreadStudio\repo\Extract\ToolChain_Support_Packages
62 \RISC-V\RISC-V-GCC-RV32\2022-04-12\bin
63 ```
64
65 Compile directly while specifying the tool chain location, and then generate the rtthread.elf file.
66
67 
68
696. Try running rtthread.elf, copy the rtthread.elf generated in the previous step to the bin file directory of the compiled qemu tool, and execute the following command:
70
71 ```shell
72 ./qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio
73 ```
74
75 The operation results are as follows:
76
77 
78
79 7.Run the following command to generate a complete, copyable project.
80
81```shell
82scons --dist
83```
84
85Copy the generated independent project to the Linux environment.
86
87### 3.2Compile and run the project in the Linux environment
88
89#### 3.2.1 Configuration project
90
911.Found in the complete project root directory copied above**rtconfig.h**,remove the precompiled command from the file**#ifndef RT_CONFIG_H__**,**#define RT_CONFIG_H__**,**#ifndef RT_CONFIG_H__**,**#endif**,be sure to perform this step, or an error will be reported during compilation.
92
93
94
952.Line the following command to generate the makefile project
96
97```shell
98scons --target=makefile
99```
100
1013.Enter **make ** at the command line to compile the project
102
1034.Run the following command to start qemu and compile rtthread.elf,`/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32`is the tool chain path of the Linux environment. It is set here as the user's tool chain path.
104
105```shell
106/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio
107```
108
109BSP supports the Finsh component of RT-Thread. Enter the command`version` to view the version information of RT-Thread. Click Tap to view the supported commands. The running results are as follows:
110
111
112
113So far, the configuration and running test of RT-Thread project based on Core-V-MCU have been completed.
114
115### 3.3 Import the RT Thread project into OpenHW's Core V-IDE
116
1171.Download and Install[core-v-sdk](https://github.com/openhwgroup/core-v-sdk),according [README.md](https://github.com/openhwgroup/core-v-sdk#readme)to install the IDE in a Linux environment。
118
1192.Create a workspace folder in the home directory, and open the IDE to use the workspace folder as the working path.
120
1213.Choose`Import projects Option `:
122
123
124
1254.Choose`Existing Code as Makefile Project`:
126
127
128
1295.The settings are as follows:
130
1316.Project configuration settings:
132
133
134
1357.Modify compilation command:
136
137
138
1398.Clear the files compiled from the project and recompile the project:
140
141
142
1439.Run the following command in the root directory of the project compiled with IDE, and the result is consistent with that of **3.2.1**. The project under IDE will be configured. So far, the import and running tests of the RT-Thread project imported from IDE to Core-V-MCU have been completed.
144
145### 3.4调试配置
146
1471.Debug Configurations settings:
148
149
150
1512.Double click`GDB OpenOCD Debugging`,build debug configuration options:
152
153
154
1553.Import on chip peripheral register file:
156
157PATH:`OpenHW/CORE-V-SDKv0.0.0.4/registers/csr`,the specific path is configured according to the SDK path installed by the user。
158
159
160
1613.Import on chip peripheral register file:
162
163PATH`/home/wangshun/OpenHW/CORE-V-SDKv0.0.0.4/registers/peripheral`,the specific path is configured according to the SDK path installed by the user.
164
165
166
1673.Configure the QEMU running environment:
168
169Cancle`Start OpenOCD locally`,the configuration parameters are as follows:
170
1714.Run the following commands:
172
173```shell
174/home/wangshun/bin/qemu-riscv/bin/qemu-system-riscv32 -M core_v_mcu -bios none -kernel rtthread.elf -nographic -monitor none -serial stdio -s -S
175```
176
1775.Click debug to start debugging:
178
179
180
181### 4.CLI components
182
183 The FreeRTOS project provided by OPENHW supports a CLI component for testing. To ensure compatibility with the original CLI when using RT Thread again, the original CLI is made into an independent software package. At the same time, the software package automatically opens the FreeRTOS compatibility layer, so the software package can support the original CLI components and still use FreeRTOS interface functions.
184
185#### 4.1使用方法
186
187 Enable CorevMCU with menuconfig configuration in ENV tool_ CL software package, place the sample code in example. c at the prompt of main. c. The steps to use menuconfig configuration are as follows:
188
189> `RT-Thread online packages`
190> ` miscellaneous packages --->`
191> ` [*] CorevMCU_CLI`