[RTduino][STM32]为stm32l431-BearPi开发板对接RTduino软件包 (#6688)

This commit is contained in:
liYangYang
2022-12-04 20:28:15 -05:00
committed by GitHub
parent c53d9da22e
commit 4bdca93a8d
16 changed files with 940 additions and 161 deletions
@@ -62,6 +62,33 @@ extern "C" {
}
#endif /* BSP_USING_PWM5 */
#ifdef BSP_USING_PWM15
#define PWM15_CONFIG \
{ \
.tim_handle.Instance = TIM15, \
.name = "pwm15", \
.channel = RT_NULL \
}
#endif /* BSP_USING_PWM15 */
#ifdef BSP_USING_PWM16
#define PWM16_CONFIG \
{ \
.tim_handle.Instance = TIM16, \
.name = "pwm16", \
.channel = RT_NULL \
}
#endif /* BSP_USING_PWM16 */
#ifdef BSP_USING_PWM17
#define PWM17_CONFIG \
{ \
.tim_handle.Instance = TIM17, \
.name = "pwm17", \
.channel = RT_NULL \
}
#endif /* BSP_USING_PWM17 */
#ifdef __cplusplus
}
#endif
@@ -1,9 +1,12 @@
from building import *
import os
cwd = GetCurrentDir()
src = Glob('*.c')
cwd = GetCurrentDir()
CPPPATH = [cwd]
src = ['main.c']
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
src += ['arduino_main.cpp']
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-01 liYony first version
*/
#include <Arduino.h>
void setup(void)
{
/* put your setup code here, to run once: */
Serial.begin();
}
void loop(void)
{
/* put your main code here, to run repeatedly: */
Serial.println("Hello Arduino!");
delay(800);
}
@@ -0,0 +1,43 @@
# STM32L431-BearPi开发板的Arduino生态兼容说明
## 1 RTduino - RT-Thread的Arduino生态兼容层
STM32L431-BearPi开发板已经完整适配了[RTduino软件包](https://github.com/RTduino/RTduino),即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP,并且可以使用大量Arduino社区丰富的库,是对RT-Thread生态的极大增强。更多信息,请参见[RTduino软件包说明文档](https://github.com/RTduino/RTduino)。
### 1.1 如何开启针对本BSP的Arduino生态兼容层
Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings:
```Kconfig
Hardware Drivers Config --->
Onboard Peripheral Drivers --->
[*] Compatible with Arduino Ecosystem (RTduino)
```
## 2 Arduino引脚排布
![bearpi-l431-pinout](bearpi-l431-pinout.png)
该BSP遵照E53接口的引脚排列方式,详见 [pins_arduino.c](pins_arduino.c) 和 [pins_arduino.h](pins_arduino.h)。
| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 |
| --------------------- | --------- | ---- | --------------------------------------------- |
| 0 (D0) | PA1 | 是 | SPI-SCK,默认被RT-Thread的SPI设备框架spi1接管 |
| 1 (D1) | PA4 | 否 | SPI-SS,默认被RT-Thread的SPI设备框架spi1接管 |
| 2 (D2) | PA0 | 是 | |
| 3 (D3) | PB9 | 是 | |
| 4 (D4) | PB8 | 是 | PWM16-CH1,默认被RT-Thread的PWM设备框架pwm16接管 |
| 5 (D5) | PB6 | 是 | I2C-SCL,被RT-Thread的I2C设备框架i2c1总线接管 |
| 6 (D6) | PB7 | 是 | I2C-SDA,被RT-Thread的I2C设备框架i2c1总线接管 |
| 7 (D7) | PA6 | 是 | SPI-MISO,默认被RT-Thread的SPI设备框架spi1接管 |
| 8 (D8) | PA12 | 是 | SPI-MOSI,默认被RT-Thread的SPI设备框架spi1接管 |
| 9 (D9) | PC9 | 是 | |
| 10 (D10) | PC4 | 是 | Serial3-Tx,默认被RT-Thread的UART设备框架uart3接管 |
| 11 (D11) | PC5 | 是 | Serial3-Rx,默认被RT-Thread的UART设备框架uart3接管 |
| 12 (D12) | PA8 | 是 | PWM1-CH1,默认被RT-Thread的PWM设备框架pwm1接管 |
| A0 | PC2 | 是 | ADC1-CH3,默认被RT-Thread的ADC设备框架adc1接管 |
| DAC0 | PA5 | 否 | DAC1-CH2,默认被RT-Thread的DAC设备框架dac1接管 |
> 注意:
>
> 1. 可能是由于开发板厂商的疏忽,E53标准中,规定17号脚(RTduino的9号脚D9)应该具备输出PWM波的功能,但是通过相关资料了解到,该引脚PC9并不具备PWM的功能,所以目前这个引脚只能做普通GPIO处理。
@@ -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')
Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-01 liYony first version
*/
#include <Arduino.h>
#include <board.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(A,1), "spi1"}, /* SPI-SCK */
{D1, GET_PIN(A,4)}, /* SPI-SS */
{D2, GET_PIN(A,0)},
{D3, GET_PIN(B,9)},
{D4, GET_PIN(B,8), "pwm16", 1}, /* PWM */
{D5, GET_PIN(B,6), "i2c1"}, /* I2C-SCL (Wire) */
{D6, GET_PIN(B,7), "i2c1"}, /* I2C-SDA (Wire) */
{D7, GET_PIN(A,6), "spi1"}, /* SPI-MISO */
{D8, GET_PIN(A,12), "spi1"}, /* SPI-MOSI */
{D9, GET_PIN(C,9)},
{D10, GET_PIN(C,4), "uart3"}, /* Serial2-Tx */
{D11, GET_PIN(C,5), "uart3"}, /* Serial2-Rx */
{D12, GET_PIN(A,8), "pwm1", 1}, /* PWM */
{A0, GET_PIN(C,2), "adc1", 3}, /* ADC */
{A1, RT_NULL, "adc1", 18}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
{A2, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
{DAC0, GET_PIN(A,5), "dac1", 2}, /* DAC */
};
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-12-01 liYony first version
*/
#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 A0 (13)
#define A1 (14)
#define A2 (15)
#define DAC0 (16)
#define F_CPU 80000000L /* CPU:80MHz */
/* i2c1 : PB7-SDA PB6-SCL */
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
/* spi1 : PA1-SCK PA6-MISO PA12-MOSI */
#define SS D1 /* Chip select pin of default spi */
#define RTDUINO_DEFAULT_SPI_BUS_NAME "spi1"
/* Serial : PC4-TX PC5-RX */
#define RTDUINO_SERIAL2_DEVICE_NAME "uart3"
#endif /* Pins_Arduino_h */
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
@@ -50,6 +50,8 @@ extern "C" {
/* USER CODE END EM */
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
@@ -67,5 +69,3 @@ void Error_Handler(void);
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
File diff suppressed because it is too large Load Diff
@@ -24,7 +24,7 @@
#ifdef __cplusplus
extern "C" {
#endif
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@@ -65,5 +65,3 @@ void SysTick_Handler(void);
#endif
#endif /* __STM32L4xx_IT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
File diff suppressed because it is too large Load Diff
@@ -62,7 +62,7 @@
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M4 Processor Interruption and Exception Handlers */
/* Cortex-M4 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
@@ -200,4 +200,3 @@ void SysTick_Handler(void)
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+119 -1
View File
@@ -27,6 +27,85 @@ menu "On-chip Peripheral Drivers"
bool "Enable UART1 RX DMA"
depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA
default n
config BSP_UART1_TX_USING_DMA
bool "Enable UART1 TX DMA"
depends on BSP_USING_UART1 && RT_SERIAL_USING_DMA
default n
config BSP_USING_UART3
bool "Enable UART3"
default n
config BSP_UART3_RX_USING_DMA
bool "Enable UART3 RX DMA"
depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA
default n
config BSP_UART3_TX_USING_DMA
bool "Enable UART3 TX DMA"
depends on BSP_USING_UART3 && RT_SERIAL_USING_DMA
default n
endif
menuconfig BSP_USING_ADC
bool "Enable ADC"
default n
select RT_USING_ADC
if BSP_USING_ADC
config BSP_USING_ADC1
bool "Enable ADC1"
default n
endif
menuconfig BSP_USING_DAC
bool "Enable DAC"
default n
select RT_USING_DAC
if BSP_USING_DAC
config BSP_USING_DAC1
bool "Enable DAC1"
default n
endif
menuconfig BSP_USING_I2C1
bool "Enable I2C1 BUS (software simulation)"
default n
select RT_USING_I2C
select RT_USING_I2C_BITOPS
select RT_USING_PIN
if BSP_USING_I2C1
config BSP_I2C1_SCL_PIN
int "i2c1 scl pin number"
range 0 143
default 22
config BSP_I2C1_SDA_PIN
int "I2C1 sda pin number"
range 0 143
default 23
endif
menuconfig BSP_USING_PWM
bool "Enable PWM"
default n
select RT_USING_PWM
if BSP_USING_PWM
menuconfig BSP_USING_PWM1
bool "Enable timer1 output PWM"
default n
if BSP_USING_PWM1
config BSP_USING_PWM1_CH1
bool "Enable PWM1 channel1"
default n
endif
menuconfig BSP_USING_PWM16
bool "Enable timer16 output PWM"
default n
if BSP_USING_PWM16
config BSP_USING_PWM16_CH1
bool "Enable PWM16 channel1"
default n
endif
endif
menuconfig BSP_USING_SPI
@@ -34,6 +113,21 @@ menu "On-chip Peripheral Drivers"
default n
select RT_USING_SPI
if BSP_USING_SPI
config BSP_USING_SPI1
bool "Enable SPI1 BUS"
default n
config BSP_SPI1_TX_USING_DMA
bool "Enable SPI1 TX DMA"
depends on BSP_USING_SPI1
default n
config BSP_SPI1_RX_USING_DMA
bool "Enable SPI1 RX DMA"
depends on BSP_USING_SPI1
select BSP_SPI1_TX_USING_DMA
default n
config BSP_USING_SPI2
bool "Enable SPI2 BUS"
default n
@@ -42,7 +136,7 @@ menu "On-chip Peripheral Drivers"
bool "Enable SPI2 TX DMA"
depends on BSP_USING_SPI2
default n
config BSP_SPI2_RX_USING_DMA
bool "Enable SPI2 RX DMA"
depends on BSP_USING_SPI2
@@ -60,6 +154,30 @@ menu "Onboard Peripheral Drivers"
select BSP_USING_SPI
select BSP_USING_SPI2
default n
config BSP_USING_ARDUINO
bool "Compatible with Arduino Ecosystem (RTduino)"
select PKG_USING_RTDUINO
select BSP_USING_STLINK_TO_USART
select BSP_USING_UART3
select BSP_USING_GPIO
select BSP_USING_ADC
select BSP_USING_ADC1
select BSP_USING_DAC
select BSP_USING_DAC1
select BSP_USING_PWM
select BSP_USING_PWM1
select BSP_USING_PWM16
select BSP_USING_PWM16_CH1
select BSP_USING_PWM1_CH1
select BSP_USING_I2C
select BSP_USING_I2C1
select BSP_USING_SPI
select BSP_USING_SPI1
imply RTDUINO_USING_SERVO
imply RTDUINO_USING_WIRE
imply RTDUINO_USING_SPI
default n
endmenu
endmenu