Skip to content

Commit 10551b5

Browse files
authored
[bsp][essemi]es32vf2264更新部分库函数和驱动,添加RTduino支持 (#7619)
1 parent 1d81658 commit 10551b5

File tree

23 files changed

+624
-173
lines changed

23 files changed

+624
-173
lines changed

bsp/essemi/es32f0654/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config SOC_ES32F0654LT
2222
bool
2323
select RT_USING_COMPONENTS_INIT
2424
select RT_USING_USER_MAIN
25+
select ARCH_ARM_CORTEX_M0
2526
default y
2627

2728
source "drivers/Kconfig"

bsp/essemi/es32f365x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config SOC_ES32F3696LT
2222
bool
2323
select RT_USING_COMPONENTS_INIT
2424
select RT_USING_USER_MAIN
25+
select ARCH_ARM_CORTEX_M3
2526
default y
2627

2728
source "drivers/Kconfig"

bsp/essemi/es32f369x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config SOC_ES32F3696LT
2222
bool
2323
select RT_USING_COMPONENTS_INIT
2424
select RT_USING_USER_MAIN
25+
select ARCH_ARM_CORTEX_M3
2526
default y
2627

2728
source "drivers/Kconfig"

bsp/essemi/es32vf2264/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config SOC_ES32VF2264
2222
bool
2323
select RT_USING_COMPONENTS_INIT
2424
select RT_USING_USER_MAIN
25+
select ARCH_RISCV32
2526
default y
2627

2728
source "drivers/Kconfig"

bsp/essemi/es32vf2264/applications/SConscript

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ Import('RTT_ROOT')
22
Import('rtconfig')
33
from building import *
44

5-
cwd = os.path.join(str(Dir('#')), 'applications')
6-
src = Glob('*.c')
5+
src = Glob('*.c')
76

8-
CPPPATH = [cwd, str(Dir('#'))]
9-
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
7+
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
8+
src += ['arduino_main.cpp']
9+
10+
cwd = GetCurrentDir()
11+
CPPPATH = [cwd]
12+
group = DefineGroup('applications', src, depend = [''], CPPPATH = CPPPATH)
13+
14+
list = os.listdir(cwd)
15+
for item in list:
16+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
17+
group = group + SConscript(os.path.join(item, 'SConscript'))
1018

1119
Return('group')
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-12-10 Meco Man first version
9+
* 2023-05-30 shiwa ES32VF2264
10+
*/
11+
#include <Arduino.h>
12+
13+
void setup(void)
14+
{
15+
pinMode(LED_BUILTIN, OUTPUT);
16+
}
17+
18+
void loop(void)
19+
{
20+
/* put your main code here, to run repeatedly: */
21+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
22+
delay(250);
23+
}
24+
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# ES32VF2264的Arduino生态兼容说明
2+
3+
## 1 RTduino - RT-Thread的Arduino生态兼容层
4+
5+
ES32VF2264已经适配了[RTduino软件包](https://github.com/RTduino/RTduino),可正常使用全部功能,包含GPIO、PWM、I2C、SPI、UART功能。除标准arduino uno的接口外,该开发板还额外添加了4个led和一组方向键对应的GPIO,由于设计原因,该开发板仅有A0-A1两个ADC可用,原本对应A2-A5的ADC被换为了数字接口(可用作SPI1)。更多信息,请参见[RTduino软件包说明文档](https://github.com/RTduino/RTduino)
6+
7+
### 1.1 使用CDK+Env
8+
9+
1. Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings:
10+
11+
```Kconfig
12+
Hardware Drivers Config --->
13+
Onboard Peripheral Drivers --->
14+
[*] Compatible with Arduino Ecosystem (RTduino)
15+
```
16+
17+
2. 进入RTduino配置,打开需要使用的各项配置 (SPI,I2C,Adafrui等)
18+
19+
```Kconfig
20+
RT-Thread online packages --->
21+
system packages --->
22+
RTduino: Arduino Ecological Compatibility Layer
23+
```
24+
25+
3. 使用 pkgs --update下载RTduino包及其他软件包
26+
4. 使用scons --target=cdk生成代码
27+
28+
## 2 Arduino引脚排布
29+
30+
该BSP遵照Arduino UNO板的引脚排列方式,并额外扩展了一些LED和按键,更多引脚布局相关信息参见 [pins_arduino.c](pins_arduino.c)[pins_arduino.h](pins_arduino.h)
31+
32+
arduino引脚排布参见下图(或arduino_pins.xlsx)。
33+
34+
注意,由于设计原因,左边部分原本对应Arduino的A2-A5这4个ADC接口不可用,可以作为普通数字IO或SPI1使用。
35+
36+
![image-20230602165933931](picture/image-20230602165933931.png)
37+
38+
各引脚功能参见下表
39+
40+
| Arduino引脚编号 | ES32引脚编号 | 备注 |
41+
| --------------- | ------------ | ---------------- |
42+
| D0 | PC11 | CUART2 RX |
43+
| D1 | PC10 | CUART2 TX |
44+
| D2 | PB5 | 普通IO |
45+
| D3 | PC15 | PWM3 通道4 |
46+
| D4 | PB4 | 普通IO |
47+
| D5 | PC7 | PWM2 通道2 |
48+
| D6 | PC6 | PWM0 通道1 |
49+
| D7 | PA8 | 普通IO |
50+
| D8 | PB11 | 普通IO |
51+
| D9 | PB10 | 普通IO |
52+
| D10 | PA4 | SPI片选/普通IO |
53+
| D11 | PA7 | SPI0_MOSI/普通IO |
54+
| D12 | PA6 | SPI0_MISO/普通IO |
55+
| D13 | PA5 | SPI0_SCK/普通IO |
56+
| D14 | PB3 | I2C0_SDA |
57+
| D15 | PB2 | I2C0_SCL |
58+
| D16 | PA15 | LED4 |
59+
| D17 | PC12 | LED5 |
60+
| D18 | PC13 | LED6 |
61+
| D19 | PC14 | LED7 |
62+
| D20 | PB7 | KEY_UP |
63+
| D21 | PB9 | KEY_DOWN |
64+
| D22 | PB6 | KEY_LEFT |
65+
| D23 | PB8 | KEY_RIGHT |
66+
| D24 | PD2 | KEY_CENTER |
67+
| D25 | PB15 | SPI1_MOSI/普通IO |
68+
| D26 | PB14 | SPI1_MISO/普通IO |
69+
| D27 | PB13 | SPI1_SCK/普通IO |
70+
| D28 | PB12 | SPI片选/普通IO |
71+
| A0 | PC1 | ADC |
72+
| A1 | PC2 | ADC |
73+
74+
75+
76+
## 3 I2C总线
77+
78+
ES32-Arduino支持的I2C总线是:i2c0。
79+
80+
I2C的引脚都是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚。
81+
82+
在RTduino中选择启用<Wire.h>即可使用。
83+
84+
或者在RTduino中开启Adafruit_Bus后,可使用`Adafruit_I2CDevice.h`控制
85+
86+
## 4 SPI总线
87+
88+
ES32-Arduino的SPI总线是spi0、spi1, `SCK``MISO``MOSI`引脚是被RT-Thread SPI设备框架接管的,不需要直接操控这3个引脚。
89+
90+
在RTduino中选择启用<SPI.h>即可使用,用户需要自行控制片选。
91+
92+
或者在RTduino中开启Adafruit_Bus后,使用`Adafruit_SPIDevice.h`控制。
93+
94+
## 5 测试说明
95+
96+
在applications/arduino_pinout/examples/arduino_examples.cpp文件中,已经根据功能预设了一系列函数用于测试arduino各个功能,可根据测试需要,取消注释对应的宏定义即可启用对应的测试。如果需要测试,请将arduino_examples.cpp文件的内容覆盖到applications/arduino_main.cpp文件中
97+
98+
1. RTduino各功能测试
99+
100+
目前支持的测试如下:
101+
102+
| 宏定义 | 名称 | 描述 |
103+
| ---------------------- | --------------- | ------------------------------------------------------------ |
104+
| ARDU_TEST_GPIO | 数字GPIO测试 | 测试数字管脚的输出功能,包括两个管脚输出高/低电平,一个管脚输出一个0.5s周期的方波 |
105+
| ARDU_TEST_PWM | 模拟PWM输出测试 | PWM功能输出测试,分别在三个PWM管脚输出不同的三种占空比的方波 |
106+
| ARDU_TEST_UART | UART测试 | 在cuart2串口不断打印"Hello" |
107+
| ARDU_TEST_ADAFRUIT_I2C | AdafruitI2C测试 | 使用AdafruitI2C库发送数据,测试正常可以收到不断发送的"HelloRTduinoHello" |
108+
| ARDU_TEST_ADAFRUIT_SPI | AdafruitSPI测试 | 使用AdafruitSPI库发送数据,测试正常可收到不断的"TEST" |
109+
| ARDU_TEST_I2C | I2C测试 | 通过I2C接口发送数据,测试正常可收到不断的"Hello" |
110+
| ARDU_TEST_SPI | SPI测试 | 通过SPI接口发送和接收数据,测试正常可收到不断的"ABCD" |
111+
| ARDU_TEST_INT | 中断测试 | 测试外部中断,按下方向键的中键会打印相关信息 |
112+
| ARDU_TEST_DIGITAL_READ | 数字读测试 | 不断读取各个方向键的状态,并在按下时输出信息 |
113+
| ARDU_TEST_ADC_READ | ADC测试 | 循环读取各个ADC的数据,并通过串口打印 |
114+
115+
## 6 其他说明
116+
117+
### 1.ADC
118+
目前ES32的ADC返回的是原始值(范围0-4095),需要计算转换为实际的电压值,暂时不支持分辨率调节。
119+
### 2.对非数字IO的管脚不要调用pinMode
120+
非数字IO的管脚在其他地方已经初始化了,再次调用pinMode会使他变为普通管脚且无法再重新初始化为非数字IO的功能。即对于任意管脚可以调用pinMode使它变为数字IO管脚,但这一过程不可逆,原有的预设功能将会失效
121+
### 3.SPI/I2C/UART使用
122+
123+
默认开启了spi0、spi1、i2c0、cuart1(默认控制台串口)、cuart2,如果需要使用其他的spi/i2c/uart可以在配置中启用,并在初始化时指定名称即可。如果想要调整管脚信息,可以使用ESCodeMaker辅助,但要注意打开对应的外设。
124+
125+
SPI必须先调用begin才能使用其他函数
126+
127+
### 4.C++异常和RTTI
128+
129+
若使用c++异常,则该机制会占用大量内存(~18k),该内存会在C++部分初始化时使用malloc申请。在编译参数中加入-fno-exceptions禁用c++异常机制可去除该问题。
130+
131+
若使用RTTI(运行时类型识别),会需要额外的stdc++库支持,需要在CDK的Linker页面中,在Library Name中添加"stdc++",可通过在编译参数中加入-fno-rtti禁用,但由于CDK不区分C和C++的编译参数,会导致编译C文件时产生警告"warning: command-line option '-fno-rtti' is valid for C++/D/ObjC++ but not for C"。
132+
133+
本BSP默认**禁用异常****连接stdc++库**
134+
135+
### 5.已知问题
136+
137+
1. 开启C++选项后,即使未选择使用C++ thread,也会引入thread支持,此支持需要使用event,若未开启则会编译报错。需要在"RT-Thread Kernel → Inter-Thread communication"中,开启"Enable Event Flag"
138+
2. rt_atomic.h文件循环包含导致编译报错,临时解决方案:在编译器的宏定义中添加"__RT_ATOMIC_H\_\_",临时屏蔽该文件,之后的解决方案等待rt-thread更新
139+
140+
## 7 参考资料
141+
142+
- [工程师笔记 | 使用RT-Thread的Arduino兼容层开发ES32应用程序](https://mp.weixin.qq.com/s/O693pgCLl1xOGxE9O7zaHA)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c') + Glob('*.cpp')
5+
inc = [cwd]
6+
7+
group = DefineGroup('RTduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
8+
9+
Return('group')
Binary file not shown.

0 commit comments

Comments
 (0)