Skip to content

Commit 8903606

Browse files
committed
[xuantie] 添加E902 BSP
1 parent dcd17ed commit 8903606

File tree

18 files changed

+2678
-0
lines changed

18 files changed

+2678
-0
lines changed

bsp/xuantie/smartl/e902/.config

Lines changed: 1362 additions & 0 deletions
Large diffs are not rendered by default.

bsp/xuantie/smartl/e902/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mainmenu "RT-Thread Configuration"
2+
3+
BSP_DIR := .
4+
5+
RTT_DIR := ../../../..
6+
7+
PKGS_DIR := packages
8+
9+
source "$(RTT_DIR)/Kconfig"
10+
osource "$PKGS_DIR/Kconfig"
11+
rsource "board/Kconfig"

bsp/xuantie/smartl/e902/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# XuanTie - E902 Series
2+
3+
## 一 简介
4+
5+
### 1. 内核
6+
7+
玄铁 E902 是杭州中天微系统有限公司自主研发的极低功耗、极低成本嵌入式 CPU 核,以 8 位 CPU的成本获得 32 位嵌入式 CPU 的运行效率与性能。E902 兼容 RISC-V 指令架构,采用 16/32 位混合编码系统,指令系统与流水线硬件结构精简高效,具备极低成本、极低功耗和高代码密度等优点。E902 主要针对智能卡、智能电网、低成本微控制器、无线传感网络等嵌入式应用。
8+
9+
### 2.特点
10+
11+
E902 处理器体系结构的主要特点如下:
12+
13+
• 支持 RISC-V RV32E[M]C 指令集;
14+
15+
• 16 个 32 位通用寄存器;
16+
17+
• 两级顺序执行流水线;
18+
19+
• 支持 RISC-V 机器模式和用户模式;
20+
21+
• 支持 RISCV debug 架构,支持标准五线 jtag 调试接口,支持 cjtag 两线调试接口;
22+
23+
• 可配置的单周期硬件乘法器,多周期硬件除法器;
24+
25+
• 兼容 RISC-V CLIC 中断标准,支持中断嵌套,外部中断源数量最高可配置 240 个;
26+
27+
• 兼容 RISC-V PMP 内存保护标准,0/4/8/12/16 区域可配置;
28+
29+
• 支持 AHB-Lite 总线协议,支持指令总线,系统总线;
30+
31+
• 支持可配置的指令高速缓存,缓存行 16 字节,容量 2KiB/4KiB/8KiB 可配;
32+
33+
• 支持玄铁扩展编程模型;
34+
35+
• 支持复位启动地址硬件集成时可配置;
36+
37+
• 支持软复位操作。
38+
39+
### 3.BSP支持情况
40+
41+
- 当前BSP支持下述内核:
42+
43+
```asciiarmor
44+
e902 e902m e902mt e902t
45+
```
46+
47+
- 当前BSP默认设置的内核是e902。
48+
49+
- 当使用其他内核架构时需要修改,rtconfig.py文件中的`MCPU`字段。
50+
51+
### 4.运行QEMU
52+
53+
- BSP根目录下存在`qemu.bat`脚本,生成可执行文件后可点击该脚本直接启动QEMU.
54+
55+
## 二 工具
56+
57+
- 编译器: https://www.xrvm.cn/community/download?id=4433353576298909696
58+
- 模拟器: https://www.xrvm.cn/community/download?id=4397435198627713024
59+
60+
注:若上述链接中的编译器与模拟器不能使用,可以使用下述CDK中的编译器与模拟器
61+
62+
- SDK:https://www.xrvm.cn/community/download?id=4397799570420076544
63+
64+
## 三 调试方法
65+
66+
**下述调试方法以E902举例,本BSP操作方式一致**,搭建完成RT-Thread开发环境,在BSP根目录使用env工具在当前目录打开env。
67+
68+
![](figures/1.env.png)
69+
70+
使用前执行一次**menuconfig**命令,更新rtconfig.h配置,然后在当前目录执行**scons -j12**命令编译生成可可执行文件。
71+
72+
<img src="figures/2.scons.png" alt="env" style="zoom: 95%;" />
73+
74+
生成可执行文件,可以直接在命令行启动qemu或者配置vscode脚本借助vscode强大的插件进行图形化调试,qemu的相关命令可以查看玄铁qemu的[用户手册](https://www.xrvm.cn/community/download?id=4397435198627713024),下述是启动qemu的命令,在powershell或命令行可直接执行下述命令,注意qemu需要导出至环境变量或者使用绝对路径。
75+
76+
```shell
77+
qemu-system-riscv64 -machine smartl -nographic -kernel rtthread.elf -cpu e906
78+
```
79+
80+
下述是使用vscode调试的展示。
81+
82+
<img src="figures/3.vscode.png" alt="env" style="zoom: 63%;" />
83+
84+
一起为RISC-V加油!

bsp/xuantie/smartl/e902/SConscript

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# for module compiling
2+
import os
3+
Import('RTT_ROOT')
4+
from building import *
5+
6+
cwd = GetCurrentDir()
7+
objs = []
8+
list = os.listdir(cwd)
9+
10+
for d in list:
11+
path = os.path.join(cwd, d)
12+
if os.path.isfile(os.path.join(path, 'SConscript')):
13+
objs = objs + SConscript(os.path.join(d, 'SConscript'))
14+
15+
Return('objs')

bsp/xuantie/smartl/e902/SConstruct

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import sys
3+
import rtconfig
4+
from SCons.Script import *
5+
from termcolor import colored
6+
7+
if os.getenv('RTT_ROOT'):
8+
RTT_ROOT = os.getenv('RTT_ROOT')
9+
else:
10+
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
11+
12+
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
13+
14+
try:
15+
from building import *
16+
except:
17+
print('Cannot found RT-Thread root directory, please check RTT_ROOT')
18+
print(RTT_ROOT)
19+
exit(-1)
20+
21+
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
22+
23+
print(colored('RT-Thread root directory: %s' % RTT_ROOT, 'green'))
24+
print(colored('Building path: %s' % os.path.abspath('.'), 'green'))
25+
print(colored('Building target: %s' % TARGET, 'green'))
26+
27+
DefaultEnvironment(tools=[])
28+
env = Environment(tools = ['mingw'],
29+
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
30+
CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
31+
AR = rtconfig.AR, ARFLAGS = '-rc',
32+
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
33+
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
34+
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
35+
36+
Export('RTT_ROOT')
37+
Export('rtconfig')
38+
39+
SDK_ROOT = os.path.abspath('./')
40+
print(colored('SDK_ROOT: %s' % SDK_ROOT, 'green'))
41+
42+
if os.path.exists(SDK_ROOT + '/libraries'):
43+
libraries_path_prefix = SDK_ROOT + '../libraries'
44+
else:
45+
libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/../libraries'
46+
47+
print(colored('libraries_path_prefix: %s' % libraries_path_prefix, 'green'))
48+
SDK_LIB = libraries_path_prefix
49+
Export('SDK_LIB')
50+
51+
# prepare building environment
52+
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
53+
54+
bsp_vdir = 'build'
55+
library_vdir = 'build/libraries'
56+
57+
# common include drivers
58+
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'SConscript'), variant_dir=library_vdir, duplicate=0))
59+
60+
# make a building
61+
DoBuilding(TARGET, objs)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from building import *
2+
import os
3+
4+
cwd = GetCurrentDir()
5+
CPPPATH = [cwd]
6+
src = ['main.c']
7+
8+
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
9+
10+
Return('group')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-04-21 Wangshun first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <rtdevice.h>
13+
#include "pre_main.h"
14+
15+
int main(void)
16+
{
17+
rt_kprintf("Hello RT-Thread!\r\n");
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
menu "Hardware Drivers Config"
2+
3+
config SOC_XUANTIE
4+
bool
5+
select SOC_XUANTIE_SERIES_E906
6+
select RT_USING_COMPONENTS_INIT
7+
select RT_USING_USER_MAIN
8+
default y
9+
10+
11+
menu "On-chip Peripheral Drivers"
12+
13+
menuconfig BSP_USING_UART
14+
bool "Enable UART"
15+
select RT_USING_SERIAL
16+
default n
17+
18+
if BSP_USING_UART
19+
config BSP_USING_UART0
20+
bool "Enable UART0"
21+
default n
22+
endif
23+
24+
menuconfig ENABLE_FPU
25+
bool "Enable FPU"
26+
select ARCH_RISCV_FPU
27+
default n
28+
29+
endmenu
30+
31+
endmenu
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import rtconfig
3+
from building import *
4+
5+
Import('SDK_LIB')
6+
7+
cwd = GetCurrentDir()
8+
9+
# add general drivers
10+
src = ['board.c']
11+
12+
path = [cwd]
13+
14+
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)
15+
Return('group')
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-04-23 Wangshun first version
9+
*/
10+
11+
#include <board.h>
12+
#include <rthw.h>
13+
#include <rtthread.h>
14+
#include <drv_usart.h>
15+
16+
extern unsigned long __heap_start;
17+
extern unsigned long __heap_end;
18+
19+
/**
20+
* This function will initialize your board.
21+
*/
22+
void rt_hw_board_init()
23+
{
24+
rt_hw_interrupt_init();
25+
26+
#ifdef RT_USING_HEAP
27+
rt_system_heap_init((void *)&__heap_start, (void *)&__heap_end);
28+
#endif
29+
30+
#ifdef BSP_USING_UART
31+
rt_hw_usart_init();
32+
#endif
33+
34+
#ifdef RT_USING_CONSOLE
35+
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
36+
#endif
37+
38+
#ifdef RT_USING_COMPONENTS_INIT
39+
rt_components_board_init();
40+
#endif
41+
}

0 commit comments

Comments
 (0)