[bsp][essemi]es32vf2264更新部分库函数和驱动,添加RTduino支持 (#7619)

This commit is contained in:
shiwa 2023-06-08 14:13:01 +08:00 committed by GitHub
parent 1d8165851b
commit 10551b54cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 624 additions and 173 deletions

View File

@ -22,6 +22,7 @@ config SOC_ES32F0654LT
bool
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select ARCH_ARM_CORTEX_M0
default y
source "drivers/Kconfig"

View File

@ -22,6 +22,7 @@ config SOC_ES32F3696LT
bool
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select ARCH_ARM_CORTEX_M3
default y
source "drivers/Kconfig"

View File

@ -22,6 +22,7 @@ config SOC_ES32F3696LT
bool
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select ARCH_ARM_CORTEX_M3
default y
source "drivers/Kconfig"

View File

@ -22,6 +22,7 @@ config SOC_ES32VF2264
bool
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select ARCH_RISCV32
default y
source "drivers/Kconfig"

View File

@ -2,10 +2,18 @@ Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = os.path.join(str(Dir('#')), 'applications')
src = Glob('*.c')
src = Glob('*.c')
CPPPATH = [cwd, str(Dir('#'))]
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
src += ['arduino_main.cpp']
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = DefineGroup('applications', src, depend = [''], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for item in list:
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
group = group + SConscript(os.path.join(item, 'SConscript'))
Return('group')

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-12-10 Meco Man first version
* 2023-05-30 shiwa ES32VF2264
*/
#include <Arduino.h>
void setup(void)
{
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(void)
{
/* put your main code here, to run repeatedly: */
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(250);
}

View File

@ -0,0 +1,142 @@
# ES32VF2264的Arduino生态兼容说明
## 1 RTduino - RT-Thread的Arduino生态兼容层
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)
### 1.1 使用CDK+Env
1. Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings
```Kconfig
Hardware Drivers Config --->
Onboard Peripheral Drivers --->
[*] Compatible with Arduino Ecosystem (RTduino)
```
2. 进入RTduino配置打开需要使用的各项配置 (SPI,I2C,Adafrui等)
```Kconfig
RT-Thread online packages --->
system packages --->
RTduino: Arduino Ecological Compatibility Layer
```
3. 使用 pkgs --update下载RTduino包及其他软件包
4. 使用scons --target=cdk生成代码
## 2 Arduino引脚排布
该BSP遵照Arduino UNO板的引脚排列方式并额外扩展了一些LED和按键更多引脚布局相关信息参见 [pins_arduino.c](pins_arduino.c) 和 [pins_arduino.h](pins_arduino.h)。
arduino引脚排布参见下图(或arduino_pins.xlsx)。
注意由于设计原因左边部分原本对应Arduino的A2-A5这4个ADC接口不可用可以作为普通数字IO或SPI1使用。
![image-20230602165933931](picture/image-20230602165933931.png)
各引脚功能参见下表
| Arduino引脚编号 | ES32引脚编号 | 备注 |
| --------------- | ------------ | ---------------- |
| D0 | PC11 | CUART2 RX |
| D1 | PC10 | CUART2 TX |
| D2 | PB5 | 普通IO |
| D3 | PC15 | PWM3 通道4 |
| D4 | PB4 | 普通IO |
| D5 | PC7 | PWM2 通道2 |
| D6 | PC6 | PWM0 通道1 |
| D7 | PA8 | 普通IO |
| D8 | PB11 | 普通IO |
| D9 | PB10 | 普通IO |
| D10 | PA4 | SPI片选/普通IO |
| D11 | PA7 | SPI0_MOSI/普通IO |
| D12 | PA6 | SPI0_MISO/普通IO |
| D13 | PA5 | SPI0_SCK/普通IO |
| D14 | PB3 | I2C0_SDA |
| D15 | PB2 | I2C0_SCL |
| D16 | PA15 | LED4 |
| D17 | PC12 | LED5 |
| D18 | PC13 | LED6 |
| D19 | PC14 | LED7 |
| D20 | PB7 | KEY_UP |
| D21 | PB9 | KEY_DOWN |
| D22 | PB6 | KEY_LEFT |
| D23 | PB8 | KEY_RIGHT |
| D24 | PD2 | KEY_CENTER |
| D25 | PB15 | SPI1_MOSI/普通IO |
| D26 | PB14 | SPI1_MISO/普通IO |
| D27 | PB13 | SPI1_SCK/普通IO |
| D28 | PB12 | SPI片选/普通IO |
| A0 | PC1 | ADC |
| A1 | PC2 | ADC |
## 3 I2C总线
ES32-Arduino支持的I2C总线是i2c0。
I2C的引脚都是被RT-Thread I2C设备框架接管的不需要直接操控这两个引脚。
在RTduino中选择启用<Wire.h>即可使用。
或者在RTduino中开启Adafruit_Bus后可使用`Adafruit_I2CDevice.h`控制
## 4 SPI总线
ES32-Arduino的SPI总线是spi0、spi1 `SCK`、`MISO`、`MOSI`引脚是被RT-Thread SPI设备框架接管的不需要直接操控这3个引脚。
在RTduino中选择启用<SPI.h>即可使用,用户需要自行控制片选。
或者在RTduino中开启Adafruit_Bus后使用`Adafruit_SPIDevice.h`控制。
## 5 测试说明
在applications/arduino_pinout/examples/arduino_examples.cpp文件中已经根据功能预设了一系列函数用于测试arduino各个功能,可根据测试需要取消注释对应的宏定义即可启用对应的测试。如果需要测试请将arduino_examples.cpp文件的内容覆盖到applications/arduino_main.cpp文件中
1. RTduino各功能测试
目前支持的测试如下:
| 宏定义 | 名称 | 描述 |
| ---------------------- | --------------- | ------------------------------------------------------------ |
| ARDU_TEST_GPIO | 数字GPIO测试 | 测试数字管脚的输出功能,包括两个管脚输出高/低电平一个管脚输出一个0.5s周期的方波 |
| ARDU_TEST_PWM | 模拟PWM输出测试 | PWM功能输出测试分别在三个PWM管脚输出不同的三种占空比的方波 |
| ARDU_TEST_UART | UART测试 | 在cuart2串口不断打印"Hello" |
| ARDU_TEST_ADAFRUIT_I2C | AdafruitI2C测试 | 使用AdafruitI2C库发送数据测试正常可以收到不断发送的"HelloRTduinoHello" |
| ARDU_TEST_ADAFRUIT_SPI | AdafruitSPI测试 | 使用AdafruitSPI库发送数据测试正常可收到不断的"TEST" |
| ARDU_TEST_I2C | I2C测试 | 通过I2C接口发送数据测试正常可收到不断的"Hello" |
| ARDU_TEST_SPI | SPI测试 | 通过SPI接口发送和接收数据测试正常可收到不断的"ABCD" |
| ARDU_TEST_INT | 中断测试 | 测试外部中断,按下方向键的中键会打印相关信息 |
| ARDU_TEST_DIGITAL_READ | 数字读测试 | 不断读取各个方向键的状态,并在按下时输出信息 |
| ARDU_TEST_ADC_READ | ADC测试 | 循环读取各个ADC的数据并通过串口打印 |
## 6 其他说明
### 1.ADC
目前ES32的ADC返回的是原始值(范围0-4095),需要计算转换为实际的电压值,暂时不支持分辨率调节。
### 2.对非数字IO的管脚不要调用pinMode
非数字IO的管脚在其他地方已经初始化了再次调用pinMode会使他变为普通管脚且无法再重新初始化为非数字IO的功能。即对于任意管脚可以调用pinMode使它变为数字IO管脚但这一过程不可逆原有的预设功能将会失效
### 3.SPI/I2C/UART使用
默认开启了spi0、spi1、i2c0、cuart1(默认控制台串口)、cuart2,如果需要使用其他的spi/i2c/uart可以在配置中启用并在初始化时指定名称即可。如果想要调整管脚信息可以使用ESCodeMaker辅助但要注意打开对应的外设。
SPI必须先调用begin才能使用其他函数
### 4.C++异常和RTTI
若使用c++异常,则该机制会占用大量内存(~18k),该内存会在C++部分初始化时使用malloc申请。在编译参数中加入-fno-exceptions禁用c++异常机制可去除该问题。
若使用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"。
本BSP默认**禁用异常****连接stdc++库**。
### 5.已知问题
1. 开启C++选项后即使未选择使用C++ thread也会引入thread支持此支持需要使用event若未开启则会编译报错。需要在"RT-Thread Kernel → Inter-Thread communication"中,开启"Enable Event Flag"
2. rt_atomic.h文件循环包含导致编译报错临时解决方案在编译器的宏定义中添加"__RT_ATOMIC_H\_\_"临时屏蔽该文件之后的解决方案等待rt-thread更新
## 7 参考资料
- [工程师笔记 | 使用RT-Thread的Arduino兼容层开发ES32应用程序](https://mp.weixin.qq.com/s/O693pgCLl1xOGxE9O7zaHA)

View File

@ -0,0 +1,9 @@
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp')
inc = [cwd]
group = DefineGroup('RTduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
Return('group')

View File

@ -0,0 +1,187 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-12-10 Meco Man first version
* 2023-05-30 shiwa ES32VF2264
*/
#include <Arduino.h>
#define ARDU_TEST_GPIO
#define ARDU_TEST_PWM
#define ARDU_TEST_DIGITAL_READ
#define ARDU_TEST_INT
//#define ARDU_TEST_ADC_READ
//#define ARDU_TEST_I2C
//#define ARDU_TEST_SPI
//#define ARDU_TEST_ADAFRUIT_I2C
//#define ARDU_TEST_ADAFRUIT_SPI
//#define ARDU_TEST_UART
#ifdef ARDU_TEST_I2C
#include <Wire.h>
#endif
#ifdef ARDU_TEST_SPI
#include <SPI.h>
#endif
#if defined(ARDU_TEST_ADAFRUIT_I2C) || defined(ARDU_TEST_ADAFRUIT_SPI)
#include <Adafruit_BusIO_Register.h>
#endif
#ifdef ARDU_TEST_ADAFRUIT_I2C
#include <Adafruit_I2CDevice.h>
Adafruit_I2CDevice i2c_dev(0x2D);
Adafruit_BusIO_Register i2c_reg(&i2c_dev, 0x4241, 2, 0, 2);
#endif
#ifdef ARDU_TEST_ADAFRUIT_SPI
#include "Adafruit_SPIDevice.h"
Adafruit_SPIDevice spi_dev(D10, 100000);
#endif
static char buf[16] = {"test"};
static char buf2[16] = {"AB"};
void test_int()
{
Serial.println("Interrupt Triggered");
}
void setup(void)
{
/* No unused warnings */
(void)buf;
(void)buf2;
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin();
Serial.println("Hello arduino");
#ifdef ARDU_TEST_GPIO //数字管脚输出
pinMode(D2, OUTPUT);
pinMode(D4, OUTPUT);
digitalWrite(D4, 1);
pinMode(D7, OUTPUT);
digitalWrite(D7, 0);
pinMode(D18, OUTPUT); //LED6
#endif
#ifdef ARDU_TEST_INT //中断输入
attachInterrupt(digitalPinToInterrupt(D24), test_int, FALLING);
#endif
#ifdef ARDU_TEST_DIGITAL_READ //数字管脚输入
pinMode(D20,INPUT);
pinMode(D21,INPUT);
pinMode(D22,INPUT);
pinMode(D23,INPUT);
#endif
#ifdef ARDU_TEST_PWM //测试PWM输出
analogWriteFrequency(10);
analogWrite(D3, 80);
analogWrite(D5, 127);
analogWrite(D6, 200);
#endif
#ifdef ARDU_TEST_I2C //I2C
Wire.begin();
#endif
#ifdef ARDU_TEST_SPI //SPI
SPI.begin();
/* MSB Second IdleLow */
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE1));
pinMode(D10, OUTPUT);
digitalWrite(D10, HIGH);
#endif
#ifdef ARDU_TEST_ADAFRUIT_I2C //ADAFRUIT I2C
i2c_dev.begin();
#endif
#ifdef ARDU_TEST_ADAFRUIT_SPI //ADAFRUIT SPI
spi_dev.begin();
#endif
#ifdef ARDU_TEST_UART
Serial2.begin();
#endif
}
void loop(void)
{
/* put your main code here, to run repeatedly: */
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
//delay(250);
#ifdef ARDU_TEST_GPIO
digitalWrite(D2, 1);
digitalWrite(D18, 0);
#endif
delay(250);
#ifdef ARDU_TEST_GPIO
digitalWrite(D2, 0);
digitalWrite(D18, 1);
#endif
delay(250);
#ifdef ARDU_TEST_ADC_READ
int val1 = analogRead(A0);
int val2 = analogRead(A1);
rt_kprintf("A0=%d,A2=%d\r\n", val1, val2);
#endif
#ifdef ARDU_TEST_DIGITAL_READ
if (digitalRead(D20) == LOW) {
Serial.println("UP");
}
if (digitalRead(D21) == LOW) {
Serial.println("DOWN");
}
if (digitalRead(D22) == LOW) {
Serial.println("LEFT");
}
if (digitalRead(D23) == LOW) {
Serial.println("RIGHT");
}
#endif
#ifdef ARDU_TEST_I2C
strcpy(buf,"Hello");
Wire.beginTransmission(0x2D);
Wire.write((uint8_t *)buf, strlen(buf));
Wire.endTransmission();
#endif
#ifdef ARDU_TEST_SPI
strcpy(buf,"ABCD");
digitalWrite(D10, LOW);
SPI.transfer((uint8_t *)buf, strlen(buf));
digitalWrite(D10, HIGH);
buf[4] = 0;
Serial.print(buf);
#endif
#ifdef ARDU_TEST_ADAFRUIT_I2C
strcpy(buf2,"Hello");
strcpy(buf,"RTduino");
i2c_dev.write((uint8_t *)buf, strlen(buf), true, (uint8_t *)buf2, strlen(buf2));
i2c_reg.write((uint8_t *)buf2, 5);
#endif
#ifdef ARDU_TEST_ADAFRUIT_SPI
strcpy(buf,"TEST");
spi_dev.beginTransactionWithAssertingCS();
spi_dev.transfer((uint8_t *)buf, strlen(buf));
spi_dev.endTransactionWithDeassertingCS();
#endif
#ifdef ARDU_TEST_UART
Serial2.println("Hello");
#endif
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-06-05 shiwa ES32VF2264
*/
#include <Arduino.h>
#include <board.h>
#include "drv_gpio.h"
#include "pins_arduino.h"
/*
{Arduino Pin, RT-Thread Pin [, Device Name, Channel]}
[] means optional
Digital pins must NOT give the device name and channel.
Analog pins MUST give the device name and channel(ADC, PWM or DAC).
Arduino Pin must keep in sequence.
*/
const pin_map_t pin_map_table[]=
{
{D0, GET_PIN(C,11), "cuart2"}, /* UART2-RX */
{D1, GET_PIN(C,10), "cuart2"}, /* UART2-TX */
{D2, GET_PIN(B,5)}, /* GPIO0 */
{D3, GET_PIN(C,15),"pwm3",4}, /* PWM2 GP16C4T2 CH4 */
{D4, GET_PIN(B,4)}, /* GPIO1 */
{D5, GET_PIN(C,7),"pwm2",2}, /* PWM2 GP16C4T1 CH2 */
{D6, GET_PIN(C,6),"pwm0",1}, /* PWM2 AD16C4T0 CH1 */
{D7, GET_PIN(A,8)}, /* GPIO2 */
{D8, GET_PIN(B,11)}, /* GPIO3 */
{D9, GET_PIN(B,10)}, /* GPIO4 */
{D10, GET_PIN(A,4)}, /* GPIO5, SS */
{D11, GET_PIN(A,7), "spi0"}, /* SPI0-MOSI */
{D12, GET_PIN(A,6), "spi0"}, /* SPI0-MISO */
{D13, GET_PIN(A,5), "spi0"}, /* SPI0-SCK */
{D14, GET_PIN(B,3), "i2c0"}, /* I2C0-SDA */
{D15, GET_PIN(B,2), "i2c0"}, /* I2C0-SCL */
{D16, GET_PIN(A,15)}, /* LED3 */
{D17, GET_PIN(C,12)}, /* LED4 */
{D18, GET_PIN(C,13)}, /* LED5 */
{D19, GET_PIN(C,14)}, /* LED6 */
{D20, GET_PIN(B,7)}, /* KEY_UP */
{D21, GET_PIN(B,9)}, /* KEY_DOWN */
{D22, GET_PIN(B,6)}, /* KEY_LEFT */
{D23, GET_PIN(B,8)}, /* KEY_RIGHT */
{D24, GET_PIN(D,2)}, /* KEY_CENTER */
{D25, GET_PIN(B,15)}, /* GPIO/SPI1_MOSI */
{D26, GET_PIN(B,14)}, /* GPIO/SPI1_MISO */
{D27, GET_PIN(B,13)}, /* GPIO/SPI1_SCK */
{D28, GET_PIN(B,12)}, /* GPIO/SPI1_NSS */
{A0, GET_PIN(C,1),"adc0",1}, /* ADC0 */
{A1, GET_PIN(C,2),"adc0",2}, /* ADC0 */
};

View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-07-07 shiwa Adapt ES32F369x
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
/* pins alias. Must keep in sequence */
#define D0 (0)
#define D1 (1)
#define D2 (2)
#define D3 (3)
#define D4 (4)
#define D5 (5)
#define D6 (6)
#define D7 (7)
#define D8 (8)
#define D9 (9)
#define D10 (10)
#define D11 (11)
#define D12 (12)
#define D13 (13)
#define D14 (14)
#define D15 (15)
#define D16 (16)
#define D17 (17)
#define D18 (18)
#define D19 (19)
#define D20 (20)
#define D21 (21)
#define D22 (22)
#define D23 (23)
#define D24 (24)
#define D25 (25)
#define D26 (26)
#define D27 (27)
#define D28 (28)
#define A0 (25)
#define A1 (26)
#define F_CPU 72000000L /* CPU: 72MHz */
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c0"
#define SS D10
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi0"
#define RTDUINO_SERIAL2_DEVICE_NAME "cuart2"
#define LED_BUILTIN D16
#endif /* Pins_Arduino_h */

View File

@ -573,6 +573,26 @@ static const struct pin_index pins[] =
#endif
#ifndef ES_MAP__PIN_PC11_USED
#define ES_MAP__PIN_PC11_USED
#ifndef ES_CUART2_RX_GPIO_FUNC
#define ES_CUART2_RX_GPIO_FUNC ALD_GPIO_FUNC_4
#endif
#ifndef ES_CUART2_RX_GPIO_PORT
#define ES_CUART2_RX_GPIO_PORT GPIOC
#endif
#ifndef ES_CUART2_RX_GPIO_PIN
#define ES_CUART2_RX_GPIO_PIN ALD_GPIO_PIN_11
#endif
#ifndef ES_CUART2_RX_PIN
#ifdef ES_PIN_GPIO_C_11
#define ES_CUART2_RX_PIN ES_PIN_GPIO_C_11
#endif
#endif
#endif
#ifndef ES_MAP__PIN_PD0_USED
#define ES_MAP__PIN_PD0_USED
#ifndef ES_CUART2_RX_GPIO_FUNC
@ -633,6 +653,26 @@ static const struct pin_index pins[] =
#endif
#ifndef ES_MAP__PIN_PC10_USED
#define ES_MAP__PIN_PC10_USED
#ifndef ES_CUART2_TX_GPIO_FUNC
#define ES_CUART2_TX_GPIO_FUNC ALD_GPIO_FUNC_4
#endif
#ifndef ES_CUART2_TX_GPIO_PORT
#define ES_CUART2_TX_GPIO_PORT GPIOC
#endif
#ifndef ES_CUART2_TX_GPIO_PIN
#define ES_CUART2_TX_GPIO_PIN ALD_GPIO_PIN_10
#endif
#ifndef ES_CUART2_TX_PIN
#ifdef ES_PIN_GPIO_C_10
#define ES_CUART2_TX_PIN ES_PIN_GPIO_C_10
#endif
#endif
#endif
#ifndef ES_MAP__PIN_PD1_USED
#define ES_MAP__PIN_PD1_USED
#ifndef ES_CUART2_TX_GPIO_FUNC
@ -2993,26 +3033,6 @@ static const struct pin_index pins[] =
#endif
#ifndef ES_MAP__PIN_PC10_USED
#define ES_MAP__PIN_PC10_USED
#ifndef ES_CUART2_TX_GPIO_FUNC
#define ES_CUART2_TX_GPIO_FUNC ALD_GPIO_FUNC_4
#endif
#ifndef ES_CUART2_TX_GPIO_PORT
#define ES_CUART2_TX_GPIO_PORT GPIOC
#endif
#ifndef ES_CUART2_TX_GPIO_PIN
#define ES_CUART2_TX_GPIO_PIN ALD_GPIO_PIN_10
#endif
#ifndef ES_CUART2_TX_PIN
#ifdef ES_PIN_GPIO_C_10
#define ES_CUART2_TX_PIN ES_PIN_GPIO_C_10
#endif
#endif
#endif
#ifndef ES_MAP__PIN_PC10_USED
#define ES_MAP__PIN_PC10_USED
#ifndef ES_EUART1_TX_GPIO_FUNC
@ -3073,26 +3093,6 @@ static const struct pin_index pins[] =
#endif
#ifndef ES_MAP__PIN_PC11_USED
#define ES_MAP__PIN_PC11_USED
#ifndef ES_CUART2_RX_GPIO_FUNC
#define ES_CUART2_RX_GPIO_FUNC ALD_GPIO_FUNC_4
#endif
#ifndef ES_CUART2_RX_GPIO_PORT
#define ES_CUART2_RX_GPIO_PORT GPIOC
#endif
#ifndef ES_CUART2_RX_GPIO_PIN
#define ES_CUART2_RX_GPIO_PIN ALD_GPIO_PIN_11
#endif
#ifndef ES_CUART2_RX_PIN
#ifdef ES_PIN_GPIO_C_11
#define ES_CUART2_RX_PIN ES_PIN_GPIO_C_11
#endif
#endif
#endif
#ifndef ES_MAP__PIN_PC11_USED
#define ES_MAP__PIN_PC11_USED
#ifndef ES_I2C1_SCL_GPIO_FUNC

View File

@ -61,11 +61,11 @@
#ifndef ES_DEVICE_NAME_GP16C4T0_PWM
#define ES_DEVICE_NAME_GP16C4T0_PWM "pwm1"
#endif
#ifndef ES_DEVICE_NAME_GP16C2T0_PWM
#define ES_DEVICE_NAME_GP16C2T0_PWM "pwm2"
#ifndef ES_DEVICE_NAME_GP16C4T1_PWM
#define ES_DEVICE_NAME_GP16C4T1_PWM "pwm2"
#endif
#ifndef ES_DEVICE_NAME_GP16C2T1_PWM
#define ES_DEVICE_NAME_GP16C2T1_PWM "pwm3"
#ifndef ES_DEVICE_NAME_GP16C4T2_PWM
#define ES_DEVICE_NAME_GP16C4T2_PWM "pwm3"
#endif

View File

@ -8,6 +8,23 @@ menu "Hardware Drivers Config"
source "drivers/ES/Kconfig"
config BSP_USING_ARDUINO
bool "Compatible with Arduino Ecosystem (RTduino)"
select PKG_USING_RTDUINO
select BSP_USING_GPIO
select BSP_USING_CUART1
select BSP_USING_CUART2
select BSP_USING_SPI0
select BSP_USING_SPI1
select BSP_USING_I2C0
select BSP_USING_ADC0
select BSP_USING_AD16C4T0_PWM
select BSP_USING_GP16C4T1_PWM
select BSP_USING_GP16C4T2_PWM
imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE
imply RTDUINO_USING_SPI
default n
endmenu
menu "Onboard Peripheral Drivers"

View File

@ -72,8 +72,11 @@ CPPPATH = CPPPATH + [cwd + '/ES']
#__SYS_SELECT_H__ 用来规避冲突
#cdkrepo\toolchain\xtgccelfnewlib\v2.6.1\r\riscv64-unknown-elf\include\sys\select.h
#components/libc/compilers/common/include/sys/select.h
CPPDEFINES = ['__SYS_SELECT_H__']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
CPPDEFINES = ['__SYS_SELECT_H__','__RT_ATOMIC_H__']
CCFLAGS='-fno-exceptions'
#LINKFLAGS='-lstdc++'
LIBS=['stdc++']
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES,CCFLAGS=CCFLAGS,LIBS=LIBS)
objs = objs + group
Return('objs')

View File

@ -173,9 +173,9 @@ int rt_hw_pwm_init(void)
#ifdef BSP_USING_AD16C4T0_PWM /* 4 channels */
static struct rt_device_pwm ad16c4t0_pwm_dev;
static timer_handle_t ad16c4t0_timer_initstruct;
static ald_timer_handle_t ad16c4t0_timer_initstruct;
ad16c4t0_timer_initstruct.perh = AD16C4T0;
ad16c4t0_timer_initstruct.perh = AD16C4T;
ald_timer_pwm_init(&ad16c4t0_timer_initstruct);
/* gpio initialization */
@ -204,108 +204,6 @@ int rt_hw_pwm_init(void)
&ad16c4t0_timer_initstruct);
#endif
#ifdef BSP_USING_AD16C4T1_PWM /* 4 channels */
static struct rt_device_pwm ad16c4t1_pwm_dev;
static timer_handle_t ad16c4t1_timer_initstruct;
ad16c4t1_timer_initstruct.perh = AD16C4T1;
ald_timer_pwm_init(&ad16c4t1_timer_initstruct);
/* gpio initialization */
#if defined(ES_AD16C4T1_CH1_GPIO_FUNC)&&defined(ES_AD16C4T1_CH1_GPIO_PORT)&&defined(ES_AD16C4T1_CH1_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T1_CH1_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T1_CH1_GPIO_PORT, ES_AD16C4T1_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_AD16C4T1_CH2_GPIO_FUNC)&&defined(ES_AD16C4T1_CH2_GPIO_PORT)&&defined(ES_AD16C4T1_CH2_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T1_CH2_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T1_CH2_GPIO_PORT, ES_AD16C4T1_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_AD16C4T1_CH3_GPIO_FUNC)&&defined(ES_AD16C4T1_CH3_GPIO_PORT)&&defined(ES_AD16C4T1_CH3_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T1_CH3_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T1_CH3_GPIO_PORT, ES_AD16C4T1_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_AD16C4T1_CH4_GPIO_FUNC)&&defined(ES_AD16C4T1_CH4_GPIO_PORT)&&defined(ES_AD16C4T1_CH4_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T1_CH4_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T1_CH4_GPIO_PORT, ES_AD16C4T1_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&ad16c4t1_pwm_dev, ES_DEVICE_NAME_AD16C4T1_PWM, &es32f3_pwm_ops,
&ad16c4t1_timer_initstruct);
#endif
#ifdef BSP_USING_GP32C4T0_PWM /* 4 channels */
static struct rt_device_pwm gp32c4t0_pwm_dev;
static timer_handle_t gp32c4t0_timer_initstruct;
gp32c4t0_timer_initstruct.perh = GP32C4T0;
ald_timer_pwm_init(&gp32c4t0_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP32C4T0_CH1_GPIO_FUNC)&&defined(ES_GP32C4T0_CH1_GPIO_PORT)&&defined(ES_GP32C4T0_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T0_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T0_CH1_GPIO_PORT, ES_GP32C4T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T0_CH2_GPIO_FUNC)&&defined(ES_GP32C4T0_CH2_GPIO_PORT)&&defined(ES_GP32C4T0_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T0_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T0_CH2_GPIO_PORT, ES_GP32C4T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T0_CH3_GPIO_FUNC)&&defined(ES_GP32C4T0_CH3_GPIO_PORT)&&defined(ES_GP32C4T0_CH3_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T0_CH3_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T0_CH3_GPIO_PORT, ES_GP32C4T0_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T0_CH4_GPIO_FUNC)&&defined(ES_GP32C4T0_CH4_GPIO_PORT)&&defined(ES_GP32C4T0_CH4_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T0_CH4_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T0_CH4_GPIO_PORT, ES_GP32C4T0_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp32c4t0_pwm_dev, ES_DEVICE_NAME_GP32C4T0_PWM, &es32f3_pwm_ops,
&gp32c4t0_timer_initstruct);
#endif
#ifdef BSP_USING_GP32C4T1_PWM /* 4 channels */
static struct rt_device_pwm gp32c4t1_pwm_dev;
static timer_handle_t gp32c4t1_timer_initstruct;
gp32c4t1_timer_initstruct.perh = GP32C4T1;
ald_timer_pwm_init(&gp32c4t1_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP32C4T1_CH1_GPIO_FUNC)&&defined(ES_GP32C4T1_CH1_GPIO_PORT)&&defined(ES_GP32C4T1_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T1_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T1_CH1_GPIO_PORT, ES_GP32C4T1_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T1_CH2_GPIO_FUNC)&&defined(ES_GP32C4T1_CH2_GPIO_PORT)&&defined(ES_GP32C4T1_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T1_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T1_CH2_GPIO_PORT, ES_GP32C4T1_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T1_CH3_GPIO_FUNC)&&defined(ES_GP32C4T1_CH3_GPIO_PORT)&&defined(ES_GP32C4T1_CH3_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T1_CH3_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T1_CH3_GPIO_PORT, ES_GP32C4T1_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP32C4T1_CH4_GPIO_FUNC)&&defined(ES_GP32C4T1_CH4_GPIO_PORT)&&defined(ES_GP32C4T1_CH4_GPIO_PIN)
gpio_initstructure.func = ES_GP32C4T1_CH4_GPIO_FUNC;
ald_gpio_init(ES_GP32C4T1_CH4_GPIO_PORT, ES_GP32C4T1_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp32c4t1_pwm_dev, ES_DEVICE_NAME_GP32C4T1_PWM, &es32f3_pwm_ops,
&gp32c4t1_timer_initstruct);
#endif
#ifdef BSP_USING_GP16C4T0_PWM /* 4 channels */
static struct rt_device_pwm gp16c4t0_pwm_dev;
static ald_timer_handle_t gp16c4t0_timer_initstruct;
@ -339,10 +237,9 @@ int rt_hw_pwm_init(void)
&gp16c4t0_timer_initstruct);
#endif
#ifdef BSP_USING_GP16C4T1_PWM /* 4 channels */
static struct rt_device_pwm gp16c4t1_pwm_dev;
static timer_handle_t gp16c4t1_timer_initstruct;
static ald_timer_handle_t gp16c4t1_timer_initstruct;
gp16c4t1_timer_initstruct.perh = GP16C4T1;
ald_timer_pwm_init(&gp16c4t1_timer_initstruct);
@ -373,6 +270,39 @@ int rt_hw_pwm_init(void)
&gp16c4t1_timer_initstruct);
#endif
#ifdef BSP_USING_GP16C4T2_PWM /* 4 channels */
static struct rt_device_pwm gp16c4t2_pwm_dev;
static ald_timer_handle_t gp16c4t2_timer_initstruct;
gp16c4t2_timer_initstruct.perh = GP16C4T2;
ald_timer_pwm_init(&gp16c4t2_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP16C4T2_CH1_GPIO_FUNC)&&defined(ES_GP16C4T2_CH1_GPIO_PORT)&&defined(ES_GP16C4T2_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T2_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T2_CH1_GPIO_PORT, ES_GP16C4T2_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T2_CH2_GPIO_FUNC)&&defined(ES_GP16C4T2_CH2_GPIO_PORT)&&defined(ES_GP16C4T2_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T2_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T2_CH2_GPIO_PORT, ES_GP16C4T2_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T2_CH3_GPIO_FUNC)&&defined(ES_GP16C4T2_CH3_GPIO_PORT)&&defined(ES_GP16C4T2_CH3_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T2_CH3_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T2_CH3_GPIO_PORT, ES_GP16C4T2_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T2_CH4_GPIO_FUNC)&&defined(ES_GP16C4T2_CH4_GPIO_PORT)&&defined(ES_GP16C4T2_CH4_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T2_CH4_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T2_CH4_GPIO_PORT, ES_GP16C4T2_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp16c4t2_pwm_dev, ES_DEVICE_NAME_GP16C4T2_PWM, &es32f3_pwm_ops,
&gp16c4t2_timer_initstruct);
#endif
return ret;
}
INIT_DEVICE_EXPORT(rt_hw_pwm_init);

View File

@ -249,12 +249,12 @@ rt_err_t es32f3_spi_device_attach(rt_uint32_t pin, const char *bus_name, const c
#ifdef BSP_USING_SPI1
static struct rt_spi_bus _spi_bus1;
static spi_handle_t _spi1;
static ald_spi_handle_t _spi1;
#endif
#ifdef BSP_USING_SPI2
static struct rt_spi_bus _spi_bus2;
static spi_handle_t _spi2;
static ald_spi_handle_t _spi2;
#endif
int rt_hw_spi_init(void)
@ -328,7 +328,7 @@ int rt_hw_spi_init(void)
spi = &_spi1;
/* SPI1 gpio init */
gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.mode = ALD_GPIO_MODE_OUTPUT;
#if defined(ES_SPI1_SCK_GPIO_FUNC)&&defined(ES_SPI1_SCK_GPIO_PORT)&&defined(ES_SPI1_SCK_GPIO_PIN)
gpio_instruct.func = ES_SPI1_SCK_GPIO_FUNC;
@ -341,7 +341,7 @@ int rt_hw_spi_init(void)
#endif
#if !defined(ES_SPI1_I2S_MODE)
gpio_instruct.mode = GPIO_MODE_INPUT;
gpio_instruct.mode = ALD_GPIO_MODE_INPUT;
#endif
#if defined(ES_SPI1_MISO_GPIO_FUNC)&&defined(ES_SPI1_MISO_GPIO_PORT)&&defined(ES_SPI1_MISO_GPIO_PIN)
@ -379,7 +379,7 @@ int rt_hw_spi_init(void)
spi = &_spi2;
/* SPI2 gpio init */
gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.mode = ALD_GPIO_MODE_OUTPUT;
#if defined(ES_SPI2_SCK_GPIO_FUNC)&&defined(ES_SPI2_SCK_GPIO_PORT)&&defined(ES_SPI2_SCK_GPIO_PIN)
gpio_instruct.func = ES_SPI2_SCK_GPIO_FUNC;

View File

@ -44,6 +44,13 @@ SECTIONS
*(.jcr)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN (4) ;
PROVIDE(__ctors_start__ = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE(__ctors_end__ = .);
. = ALIGN(0x40) ;
KEEP(*startup_es32vf2264.o(*.vectors*))
@ -105,14 +112,6 @@ SECTIONS
*(.rodata.str1.4)
*(.srodata*)
. = ALIGN(0x4) ;
__ctor_start__ = .;
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
__ctor_end__ = .;
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
__dtor_end__ = .;
. = ALIGN(0x4) ;
__erodata = .;
__rodata_end__ = .;
} > REGION_RODATA
@ -141,6 +140,10 @@ SECTIONS
__start_cmd = .;
*(.bootloaddata.cmd)
. = ALIGN(4) ;
PROVIDE(__dtors_start__ = .);
KEEP(*(SORT(.dtors.*)))
KEEP(*(.dtors))
PROVIDE(__dtors_end__ = .);
__stop_cmd = .;
__global_pointer$ = .;
*(.sdata)

View File

@ -571,7 +571,7 @@ uint32_t ald_adc_get_error(ald_adc_handle_t *hperh);
* @}
*/
#ifdef __cplusplus
extern "C" }
}
#endif /* __cplusplus */
#endif /* __ALD_ADC_H */

View File

@ -31,8 +31,11 @@
#ifndef __ES32VF2264_H__
#define __ES32VF2264_H__
#ifdef __cplusplus
#define __I volatile /* defines 'read only' permissions */
#else
#define __I volatile const /* defines 'read only' permissions */
#endif
#define __O volatile /* defines 'write only' permissions */
#define __IO volatile /* defines 'read / write' permissions */

View File

@ -140,8 +140,8 @@ BareMetal: Without RTOS
<InhibitWarn>no</InhibitWarn>
<AllWarn>yes</AllWarn>
<WarnErr>no</WarnErr>
<OneElfS>no</OneElfS>
<OneElfSPerData>no</OneElfSPerData>
<OneElfS>yes</OneElfS>
<OneElfSPerData>yes</OneElfSPerData>
<Fstrict>no</Fstrict>
</Compiler>
<Asm>