parent
76885ca908
commit
a8581ac8a4
|
@ -13,11 +13,12 @@
|
|||
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!\n");
|
||||
Serial.println("Hello Arduino!");
|
||||
delay(800);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ cwd = GetCurrentDir()
|
|||
src = Glob('*.c')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
|
||||
src += ['arduino_main.cpp']
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-05 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,74 @@
|
|||
# STM32F103 Blue-Pill开发板的Arduino生态兼容说明
|
||||
|
||||
## 1 RTduino - RT-Thread的Arduino生态兼容层
|
||||
|
||||
STM32F103 Blue-Pill开发板已经完整适配了[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 --->
|
||||
[*] Support Arduino
|
||||
```
|
||||
|
||||
## 2 Arduino引脚排布
|
||||
|
||||
![blue-pill-f103-pinout](blue-pill-f103-pinout.png)
|
||||
|
||||
该BSP遵照Arduino UNO板的引脚排列方式,并扩展增加了Blue-pill自身的板载资源功能引脚。详见 `pins_arduino.c`
|
||||
|
||||
| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 |
|
||||
| --------------- | ------------- | ------ | ------------------------------------------------------------ |
|
||||
| 0 (D0) | -- | | 该引脚在UNO板中为串口RX引脚,不可当做普通IO |
|
||||
| 1 (D1) | -- | | 该引脚在UNO板中为串口TX引脚,不可当做普通IO |
|
||||
| 2 (D2) | PB9 | 是 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 3 (D3) | PB8 | 是 | I2C1_SCL,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 4 (D4) | PB7 | 是 | |
|
||||
| 5 (D5) | PB6 | 是 | |
|
||||
| 6 (D6) | PB5 | 否 | PWM3-CH2(定时器3发生) |
|
||||
| 7 (D7) | PB4 | 是 | PWM3-CH1(定时器3发生) |
|
||||
| 8 (D8) | PB3 | 是 | PWM2-CH2(定时器2发生) |
|
||||
| 9 (D9) | PA15 | 是 | PWM2-CH1(定时器2发生) |
|
||||
| 10 (D10) | PA12 | 是 | USB-DB,不可当做普通IO |
|
||||
| 11 (D11) | PA11 | 是 | USB-DM,不可当做普通IO |
|
||||
| 12 (D12) | PA10 | 是 | UART1-RX,被RT-Thread的UART设备框架uart1接管,不可当做普通IO |
|
||||
| 13 (D13) | PA9 | 是 | UART1-RX,被RT-Thread的UART设备框架uart1接管,不可当做普通IO |
|
||||
| 14 (D14) | PA8 | 是 | PWM1-CH1(定时器1发生) |
|
||||
| 15 (D15) | PB15 | 是 | |
|
||||
| 16 (D16) | PB14 | 是 | |
|
||||
| 17 (D17) | PB13 | 是 | PWM1-CH1N(定时器1发生) |
|
||||
| 18 (D18) | PB12 | 是 | |
|
||||
| 19 (D19) | PC13 | 否 | 板载LED默认引脚 |
|
||||
| 20 (D20) | PC14 | 否 | |
|
||||
| 21 (D21) | PC15 | 否 | |
|
||||
| 22 (D22) | PA2 | 否 | UART2-TX,被RT-Thread的UART设备框架uart2接管,不可当做普通IO |
|
||||
| 23 (D23) | PA3 | 否 | UART2-RX,被RT-Thread的UART设备框架uart2接管,不可当做普通IO |
|
||||
| 24 (D24) | PA5 | 否 | SPI-SCK, SPI功能尚未完全实现,目前仅作普通IO使用 |
|
||||
| 25 (D25) | PA6 | 否 | SPI-MISO,SPI功能尚未完全实现,目前仅作普通IO使用 |
|
||||
| 26 (D26) | PA7 | 否 | SPI-MOSI,SPI功能尚未完全实现,目前仅作普通IO使用 |
|
||||
| 27 (D27) | PB10 | 是 | UART3-TX,被RT-Thread的UART设备框架uart3接管,不可当做普通IO |
|
||||
| 28 (D28) | PB11 | 是 | UART3-RX,被RT-Thread的UART设备框架uart3接管,不可当做普通IO |
|
||||
| A0 | PA0 | 否 | ADC |
|
||||
| A1 | PA1 | 否 | ADC |
|
||||
| A2 | PA4 | 否 | ADC |
|
||||
| A3 | PB0 | 否 | ADC |
|
||||
| A4 | PB1 | 否 | ADC |
|
||||
| A5 | -- | | 芯片内部参考电压 ADC |
|
||||
| A6 | -- | | 芯片内部温度 ADC |
|
||||
|
||||
> 注意:
|
||||
>
|
||||
> 1. 驱动舵机和analogWrite函数要选择不同定时器发生的PWM信号引脚,由于STM32的定时器4个通道需要保持相同的频率,如果采用相同的定时器发生的PWM分别驱动舵机和analogWrite,可能会导致舵机失效。
|
||||
> 4. D10引脚是PWM反相位引脚(也就是常说的互补输出引脚CHxN)。但是这里不用考虑到占空比互补问题(CHx-20%,CHxN-80%),直接正常使用即可。
|
||||
> 4. STM32的PA15引脚默认作为JTAG下载使用,但是如果采用SWD调试时,PA15(D9)可以作为普通的IO口使用,但是需要设置一些寄存器。
|
||||
|
||||
> 参考资料
|
||||
>
|
||||
> 1. 暂无
|
||||
|
||||
## 3 I2C总线
|
||||
|
||||
STM32F103 Blue-Pill板的I2C总线是板上丝印的 `SCL/D3` 和 `SDA/D2` 引脚,这两个引脚是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚,直接引用`#include <Wire.h>`(Arduino官方I2C头文件)即可使用。
|
|
@ -0,0 +1,9 @@
|
|||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
inc = [cwd]
|
||||
|
||||
group = DefineGroup('Arduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
|
||||
|
||||
Return('group')
|
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-05 liYony first version
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <board.h>
|
||||
#include "pins_arduino.h"
|
||||
|
||||
/*
|
||||
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), 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}, /* RX */
|
||||
{D1}, /* TX */
|
||||
{D2}, /* I2C1-SDA */
|
||||
{D3}, /* I2C1-SCL */
|
||||
{D4, GET_PIN(B,7)},
|
||||
{D5, GET_PIN(B,6)},
|
||||
{D6, GET_PIN(B,5), "pwm3", 2},/* PWM */
|
||||
{D7, GET_PIN(B,4), "pwm3", 1}, /* PWM */
|
||||
{D8, GET_PIN(B,3), "pwm2", 2}, /* PWM */
|
||||
{D9, GET_PIN(A,15), "pwm2", 1}, /* PWM */
|
||||
{D10}, /* USB-DP */
|
||||
{D11}, /* USB-DM */
|
||||
{D12}, /* UART1-RX */
|
||||
{D13}, /* UART1-TX */
|
||||
{D14, GET_PIN(A,8), "pwm1", 1}, /* PWM */
|
||||
{D15, GET_PIN(B,15)},
|
||||
{D16, GET_PIN(B,14)},
|
||||
{D17, GET_PIN(B,13), "pwm1", -1}, /* PWM */
|
||||
{D18, GET_PIN(B,12)},
|
||||
{D19, GET_PIN(C,13)}, /* user led1 */
|
||||
{D20, GET_PIN(C,14)},
|
||||
{D21, GET_PIN(C,15)},
|
||||
{D22}, /* UART2-TX */
|
||||
{D23}, /* UART2-RX */
|
||||
/* The connection of RTdunio SPI has not been completed, *
|
||||
* and it can only be used as a common GPIO at present. */
|
||||
{D24, GET_PIN(A,5)}, /* SPI-SCK */
|
||||
{D25, GET_PIN(A,6)}, /* SPI-MISO */
|
||||
{D26, GET_PIN(A,7)}, /* SPI-MOSI */
|
||||
{D27}, /* UART3-TX */
|
||||
{D28}, /* UART3-RX */
|
||||
{A0, GET_PIN(A,0), "adc1", 0}, /* ADC */
|
||||
{A1, GET_PIN(A,1), "adc1", 1}, /* ADC */
|
||||
{A2, GET_PIN(A,4), "adc1", 4}, /* ADC */
|
||||
{A3, GET_PIN(B,0), "adc1", 8}, /* ADC */
|
||||
{A4, GET_PIN(B,1), "adc1", 9}, /* ADC */
|
||||
{A5, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
|
||||
{A6, RT_NULL, "adc1", 16} /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
|
||||
};
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-08-05 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 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 (29)
|
||||
#define A1 (30)
|
||||
#define A2 (31)
|
||||
#define A3 (32)
|
||||
#define A4 (33)
|
||||
#define A5 (34)
|
||||
#define A6 (35)
|
||||
|
||||
#define F_CPU 72000000L /* CPU: 72MHz */
|
||||
#define LED_BUILTIN D19 /* Default Built-in LED */
|
||||
|
||||
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
|
||||
|
||||
#define RTDUINO_SERIAL2_DEVICE_NAME "uart2"
|
||||
#define RTDUINO_SERIAL3_DEVICE_NAME "uart3"
|
||||
|
||||
#endif /* Pins_Arduino_h */
|
|
@ -33,33 +33,34 @@ Mcu.Pin12=PB0
|
|||
Mcu.Pin13=PB1
|
||||
Mcu.Pin14=PB10
|
||||
Mcu.Pin15=PB11
|
||||
Mcu.Pin16=PA8
|
||||
Mcu.Pin17=PA9
|
||||
Mcu.Pin18=PA10
|
||||
Mcu.Pin19=PA11
|
||||
Mcu.Pin16=PB13
|
||||
Mcu.Pin17=PA8
|
||||
Mcu.Pin18=PA9
|
||||
Mcu.Pin19=PA10
|
||||
Mcu.Pin2=PD0-OSC_IN
|
||||
Mcu.Pin20=PA12
|
||||
Mcu.Pin21=PA13
|
||||
Mcu.Pin22=PA14
|
||||
Mcu.Pin23=PA15
|
||||
Mcu.Pin24=PB3
|
||||
Mcu.Pin25=PB4
|
||||
Mcu.Pin26=PB5
|
||||
Mcu.Pin27=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin28=VP_ADC1_Vref_Input
|
||||
Mcu.Pin29=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin20=PA11
|
||||
Mcu.Pin21=PA12
|
||||
Mcu.Pin22=PA13
|
||||
Mcu.Pin23=PA14
|
||||
Mcu.Pin24=PA15
|
||||
Mcu.Pin25=PB3
|
||||
Mcu.Pin26=PB4
|
||||
Mcu.Pin27=PB5
|
||||
Mcu.Pin28=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin29=VP_ADC1_Vref_Input
|
||||
Mcu.Pin3=PD1-OSC_OUT
|
||||
Mcu.Pin30=VP_SYS_VS_Systick
|
||||
Mcu.Pin31=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin32=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin33=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin30=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin31=VP_SYS_VS_Systick
|
||||
Mcu.Pin32=VP_TIM1_VS_ClockSourceINT
|
||||
Mcu.Pin33=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin34=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin4=PA0-WKUP
|
||||
Mcu.Pin5=PA1
|
||||
Mcu.Pin6=PA2
|
||||
Mcu.Pin7=PA3
|
||||
Mcu.Pin8=PA4
|
||||
Mcu.Pin9=PA5
|
||||
Mcu.PinsNb=34
|
||||
Mcu.PinsNb=35
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F103C8Tx
|
||||
|
@ -122,6 +123,9 @@ PB10.Mode=Asynchronous
|
|||
PB10.Signal=USART3_TX
|
||||
PB11.Mode=Asynchronous
|
||||
PB11.Signal=USART3_RX
|
||||
PB13.Locked=true
|
||||
PB13.Mode=PWM Generation1 CH1 CH1N
|
||||
PB13.Signal=TIM1_CH1N
|
||||
PB3.Signal=S_TIM2_CH2
|
||||
PB4.Signal=S_TIM3_CH1
|
||||
PB5.Signal=S_TIM3_CH2
|
||||
|
@ -195,7 +199,7 @@ SH.ADCx_IN8.0=ADC1_IN8,IN8
|
|||
SH.ADCx_IN8.ConfNb=1
|
||||
SH.ADCx_IN9.0=ADC1_IN9,IN9
|
||||
SH.ADCx_IN9.ConfNb=1
|
||||
SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1 CH1N
|
||||
SH.S_TIM1_CH1.ConfNb=1
|
||||
SH.S_TIM2_CH1_ETR.0=TIM2_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM2_CH1_ETR.ConfNb=1
|
||||
|
@ -211,8 +215,8 @@ SPI1.Direction=SPI_DIRECTION_2LINES
|
|||
SPI1.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
TIM1.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM1.IPParameters=Channel-PWM Generation1 CH1
|
||||
TIM1.Channel-PWM\ Generation1\ CH1\ CH1N=TIM_CHANNEL_1
|
||||
TIM1.IPParameters=Channel-PWM Generation1 CH1 CH1N
|
||||
TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM2.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2
|
||||
|
|
|
@ -327,10 +327,17 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
|
|||
/* USER CODE BEGIN TIM1_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 0 */
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM1 GPIO Configuration
|
||||
PB13 ------> TIM1_CH1N
|
||||
PA8 ------> TIM1_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_13;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_8;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
|
|
@ -15,6 +15,32 @@ menu "Onboard Peripheral Drivers"
|
|||
select BSP_USING_UART1
|
||||
default y
|
||||
|
||||
config BSP_USING_ARDUINO
|
||||
bool "Support Arduino"
|
||||
select PKG_USING_RTDUINO
|
||||
select BSP_USING_STLINK_TO_USART
|
||||
select BSP_USING_UART2
|
||||
select BSP_USING_UART3
|
||||
select BSP_USING_GPIO
|
||||
select BSP_USING_ADC
|
||||
select BSP_USING_ADC1
|
||||
select BSP_USING_PWM
|
||||
select BSP_USING_PWM1
|
||||
select BSP_USING_PWM1_CH1
|
||||
select BSP_USING_PWM2
|
||||
select BSP_USING_PWM2_CH1
|
||||
select BSP_USING_PWM2_CH2
|
||||
select BSP_USING_PWM3
|
||||
select BSP_USING_PWM3_CH1
|
||||
select BSP_USING_PWM3_CH2
|
||||
select BSP_USING_I2C
|
||||
select BSP_USING_I2C1
|
||||
imply RTDUINO_USING_SERVO
|
||||
imply RTDUINO_USING_WIRE
|
||||
imply RTDUINO_USING_ADAFRUIT
|
||||
imply RTDUINO_USING_MSTIMER2
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
menu "On-chip Peripheral Drivers"
|
||||
|
|
|
@ -13,11 +13,12 @@
|
|||
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!\n");
|
||||
Serial.println("Hello Arduino!");
|
||||
delay(800);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ menu "Onboard Peripheral Drivers"
|
|||
select BSP_USING_UART2
|
||||
default y
|
||||
|
||||
config BSP_USING_ARDUINO
|
||||
config BSP_USING_ARDUINO
|
||||
bool "Support Arduino"
|
||||
select PKG_USING_RTDUINO
|
||||
select BSP_USING_STLINK_TO_USART
|
||||
|
|
Loading…
Reference in New Issue