Skip to content

Commit 554865a

Browse files
committed
[bsp] add spackfun-redv bsp
1 parent 06eafe3 commit 554865a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+5620
-0
lines changed

bsp/sparkfun-redv/Kconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
mainmenu "RT-Thread Configuration"
2+
3+
config BSP_DIR
4+
string
5+
option env="BSP_ROOT"
6+
default "."
7+
8+
config RTT_DIR
9+
string
10+
option env="RTT_ROOT"
11+
default "../.."
12+
13+
config PKGS_DIR
14+
string
15+
option env="PKGS_ROOT"
16+
default "packages"
17+
18+
source "$RTT_DIR/Kconfig"
19+
source "$PKGS_DIR/Kconfig"

bsp/sparkfun-redv/Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
scons := python ${SCONS}\scons.py
2+
3+
all:
4+
@$(scons)
5+
6+
clean:
7+
@$(scons) -c

bsp/sparkfun-redv/README.md

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# SparkFun RED-V #
2+
3+
## 1 简介
4+
5+
[SparkFun RED-V](https://www.sparkfun.com/products/15594) 是一款基于 RISC-V 架构的低成本开源开发板,核心 SoC Freedom E310-002 (FE310) 是 SiFive 的 Freedom Everywhere 可定制 SoCs 系列 FE310 的一个升级版本(兼容 HiFive1-rev-b)。最大主频提高了一倍多达到 320MHz,具有 SiFive 的高性能32位 RV32IMAC 核心,性能测试表现很突出,达到了 1.61 DMIPs/MHz,甚至超过了 Arm Cortex-M4 内核。适用于微控制器、嵌入式、物联网和可穿戴应用等领域。
6+
7+
![](figures/board.jpg)
8+
9+
### 1.1 板载资源
10+
11+
| 硬件 | 描述 |
12+
| -- | -- |
13+
|Soc| SiFive Freedom E310 (FE310-G002) |
14+
| 内核 | SiFive E31 RISC-V Core |
15+
| 架构 | 32-bit RV32IMAC |
16+
| 主频 | 320+ MHz |
17+
| 性能 | 1.61 DMIPs/MHz, 2.73 Coremark/MHz |
18+
|SRAM| 16KB |
19+
|Flash| 32 Mbit Off-Chip (ISSI SPI Flash) |
20+
21+
### 1.2 特性
22+
23+
- 16KB L1 指令缓存
24+
- 16KB 数据 SRAM 暂存器
25+
- 硬件乘/除
26+
- 调试模块
27+
- OTP 非易失性存储器
28+
- 片上振荡器和 PLL 产生灵活的时钟
29+
- 外围设备,包括 UART,QSPI,PWM 和定时器
30+
- 多个电源域+低功耗待机模式
31+
32+
33+
34+
## 2 编译说明
35+
36+
### 2.2 下载 Freedom Studio
37+
38+
[Freedom Studio](https://www.sifive.com/software) 是 SiFive 公司推出的一个集成开发环境,用来编写和调试基于 SiFive 处理器的软件。内嵌了编译好的 RISC-V GCC 工具链、OpenOCD、以及一些示例和文档。
39+
40+
特别地,这里以 v2019.08.1 版本进行演示:
41+
42+
- [FreedomStudio-2019-08-1-lin64](https://static.dev.sifive.com/dev-tools/FreedomStudio/2019.08/FreedomStudio-2019-08-1-lin64.tar.gz)
43+
- [FreedomStudio-2019-08-1-win64](https://static.dev.sifive.com/dev-tools/FreedomStudio/2019.08/FreedomStudio-2019-08-1-win64.zip)
44+
- [FreedomStudio-2019-08-1-mac64](https://static.dev.sifive.com/dev-tools/FreedomStudio/2019.08/FreedomStudio-2019-08-1-mac64.tar.gz)
45+
46+
将 Freedom Studio 解压到非中文字符且不含空格的目录下,如果是 Windows 系统,还需要打开 `FreedomStudio-2019-08-1-win64\SiFive\Drivers` 文件夹,安装驱动文件。
47+
48+
- HiFive1_Driver.exe
49+
- sifive-winusb-utility.exe
50+
51+
### 2.3 配置工具链
52+
53+
工具链的默认位置为 `SiFive/riscv64-unknown-elf-gcc-8.3.0-2019.08.0/bin/` 目录。运行 Env 工具,根据实际情况,输入以下命令设置环境变量:
54+
55+
```shell
56+
set RTT_EXEC_PATH=工具链的路径
57+
set path=%path%;工具链的路径
58+
```
59+
60+
例如:
61+
62+
```shell
63+
set RTT_EXEC_PATH=C:\FreedomStudio-2019-08-1-win64\SiFive\riscv64-unknown-elf-gcc-8.3.0-2019.08.0\bin
64+
set path=%path%;C:\FreedomStudio-2019-08-1-win64\SiFive\riscv64-unknown-elf-gcc-8.3.0-2019.08.0\bin
65+
```
66+
67+
### 2.4 从 Env 工具打开 IDE
68+
69+
在 Env 中使用 cd 命令切换到 FreedomStudio 解压后的目录中,再执行 `FreedomStudio.exe` 文件启动 IDE。例如:
70+
71+
```
72+
cd C:\FreedomStudio-2019-08-1-win64
73+
FreedomStudio.exe
74+
```
75+
76+
### 2.5 导入工程
77+
78+
点击菜单栏左上角 `File -> Import...`,展开 `C/C++` ,选择 `Existing Code as Makefile Project` ,点击 Next 继续。
79+
80+
![](figures/import_makefile_project.png)
81+
82+
在编辑框中填入 bsp 文件所在目录,选择 `Cross GCC` ,点击 Finish 导入。
83+
84+
![](figures/import_makefile_project_bsp.png)
85+
86+
### 2.6 编译
87+
88+
选中要编译的工程,点击左上角的锤子图标开始编译。
89+
90+
![build](figures/freedomstudio_compile.png)
91+
92+
当窗口输出 `Build Finished` ,左侧文件列表出现 `rtthread.elf` 文件时,即为编译成功。
93+
94+
95+
96+
## 3 烧写及执行
97+
98+
### 3.1 配置 Debug 参数
99+
100+
使用 type-c usb 数据线连接电脑与开发板。右键列表中的 `rtthread.elf` 文件,选择 `Debug As->1 As JLink launch`
101+
102+
点击 Debugger 选项卡,选择设备名称 `FE310`
103+
104+
![](figures/debug_Debugger.png)
105+
106+
点击 Config 选项卡,在 'Target Architecture' 处选择 'riscv:cv32' ,点击 Debug 开始调试。
107+
108+
![](figures/debug_Config.png)
109+
110+
### 3.2 运行结果
111+
112+
下载程序之后,连接串口(115200-N-8-1),可以看到 RT-Thread 的输出信息:
113+
114+
![](./figures/debug_terminal_msh.png)
115+
116+
可以看到板载的蓝色 LED 灯以 1Hz 频率闪烁,按下 Tab 键可以查看 RT-Thread 内置的命令。
117+
118+
```
119+
msh >
120+
RT-Thread shell commands:
121+
give_me_five - Show the SiFive logo
122+
memcheck - check memory data
123+
memtrace - dump memory trace information
124+
clear - clear the terminal screen
125+
version - show RT-Thread version information
126+
list_thread - list thread
127+
list_sem - list semaphore in system
128+
list_event - list event in system
129+
list_mutex - list mutex in system
130+
list_mailbox - list mail box in system
131+
list_msgqueue - list message queue in system
132+
list_mempool - list memory pool in system
133+
list_timer - list timer in system
134+
list_device - list device in system
135+
help - RT-Thread shell help.
136+
ps - List threads in the system.
137+
free - Show the memory usage in the system.
138+
```
139+
140+
141+
142+
## 4 驱动支持情况及计划
143+
144+
| 驱动 | 支持情况 | 备注 |
145+
| ------ | ---- | :------: |
146+
| UART | 支持 | UART0_RX/TX:GPIO 16/17 |
147+
148+
149+
150+
## 5 联系人信息
151+
152+
维护人:
153+
- [luhuadong](https://github.com/luhuadong)
154+
155+
156+
157+
## 6 参考
158+
159+
* [RED-V Schematic](https://cdn.sparkfun.com/assets/d/d/1/e/7/RedFive.pdf)
160+
* [RED-V Development Guide](https://learn.sparkfun.com/tutorials/red-v-development-guide)
161+
* [Getting Started with the SparkFun Red-V](https://www.digikey.dk/da/maker/projects/getting-started-with-the-sparkfun-red-v/a28c5ce7d21a452db4aa3f4b94f345f4)
162+
* [Freedom E310-G002 Datasheet](https://cdn.sparkfun.com/assets/5/b/e/6/2/fe310-g002-ds.pdf)
163+
* [Freedom E310-G002 Manual](https://cdn.sparkfun.com/assets/7/f/0/2/7/fe310-g002-manual-v19p05.pdf)
164+
* [Freedom Studio User Manual](https://static.dev.sifive.com/dev-tools/FreedomStudio/2020.06/freedom-studio-manual-4.7.2-2020-06-0.pdf)

bsp/sparkfun-redv/SConscript

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# for module compiling
2+
import os
3+
Import('RTT_ROOT')
4+
from building import *
5+
6+
cwd = str(Dir('#'))
7+
src = Glob('*.c')
8+
objs = []
9+
list = os.listdir(cwd)
10+
11+
for d in list:
12+
path = os.path.join(cwd, d)
13+
if os.path.isfile(os.path.join(path, 'SConscript')):
14+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
15+
16+
group = DefineGroup('', src, depend = [''], CPPPATH = [])
17+
#objs += group
18+
Return('objs')

bsp/sparkfun-redv/SConstruct

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import sys
3+
import rtconfig
4+
5+
if os.getenv('RTT_ROOT'):
6+
RTT_ROOT = os.getenv('RTT_ROOT')
7+
else:
8+
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
9+
10+
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
11+
from building import *
12+
13+
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
14+
15+
env = Environment(tools = ['mingw'],
16+
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
17+
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
18+
AR = rtconfig.AR, ARFLAGS = '-rc',
19+
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
20+
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
21+
env['ASCOM'] = env['ASPPCOM']
22+
23+
Export('RTT_ROOT')
24+
Export('rtconfig')
25+
26+
# prepare building environment
27+
objs = PrepareBuilding(env, RTT_ROOT)
28+
29+
# make a building
30+
DoBuilding(TARGET, objs)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Import('RTT_ROOT')
2+
Import('rtconfig')
3+
from building import *
4+
5+
cwd = os.path.join(str(Dir('#')), 'applications')
6+
src = Glob('*.c')
7+
src.append('led/led.c')
8+
9+
CPPPATH = [cwd,
10+
str(Dir('#')),
11+
os.path.join(str(Dir('#')), 'freedom-e-sdk/bsp/env'),
12+
os.path.join(str(Dir('#')), 'freedom-e-sdk/bsp/env/freedom-e300-hifive1'),
13+
os.path.join(str(Dir('#')), 'freedom-e-sdk/include/sifive/devices'),
14+
os.path.join(cwd, 'led')]
15+
16+
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
17+
18+
Return('group')
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-10-28 luhuadong first version
9+
*/
10+
11+
#include <rtdevice.h>
12+
#include <hifive1.h>
13+
#include <platform.h>
14+
#include <gpio.h>
15+
#include "led.h"
16+
17+
#define USER_LED_OFFSET 5
18+
19+
static void _led_init(rt_uint8_t offset)
20+
{
21+
GPIO_REG(GPIO_IOF_EN) &= ~(1UL << offset);
22+
23+
GPIO_REG(GPIO_OUTPUT_EN) |= (1UL << offset);
24+
}
25+
26+
static void _led_set(rt_uint8_t offset, rt_uint8_t val)
27+
{
28+
switch (val)
29+
{
30+
case LED_ON:
31+
GPIO_REG(GPIO_OUTPUT_VAL) |= (1UL << offset);
32+
break;
33+
case LED_OFF:
34+
GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1UL << offset);
35+
break;
36+
default:
37+
break;
38+
}
39+
}
40+
41+
static void _led_toggle(rt_uint8_t offset)
42+
{
43+
GPIO_REG(GPIO_OUTPUT_VAL) ^= (1UL << offset);
44+
}
45+
46+
void led_init(void)
47+
{
48+
_led_init(USER_LED_OFFSET);
49+
}
50+
51+
void led_set(rt_uint8_t val)
52+
{
53+
_led_set(USER_LED_OFFSET, val);
54+
}
55+
56+
void led_toggle(void)
57+
{
58+
_led_toggle(USER_LED_OFFSET);
59+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2006-2020, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2020-10-28 luhuadong first version
9+
*/
10+
11+
#ifndef __LED_H__
12+
#define __LED_H__
13+
14+
#define LED_ON 1
15+
#define LED_OFF 0
16+
17+
void led_init(void);
18+
void led_set(rt_uint8_t val);
19+
void led_toggle(void);
20+
21+
#endif /* __LED_H__ */

0 commit comments

Comments
 (0)