README.md
1# The Arduino Compatible for STM32F103 Blue Pill Board
2
3**English** | [中文](README_zh.md)
4
5## 1 RTduino - Arduino Ecosystem Compatibility Layer for RT-Thread
6
7STM32 Blue Pill board has support [RTduino](https://github.com/RTduino/RTduino). Users can use Arduino APIs, third party libraries and programming method to program on the board.
8
9### 1.1 How to Enable RTduino
10
11Please go to the [RTduino repository](https://github.com/RTduino/RTduino) to see the details.
12
13```Kconfig
14Hardware Drivers Config --->
15 Onboard Peripheral Drivers --->
16 [*] Compatible with Arduino Ecosystem (RTduino)
17```
18
19## 2 Arduino Pinout
20
21For more information, please see [pins_arduino.c](pins_arduino.c) and [pins_arduino.h](pins_arduino.h).
22
23
24
25| Arduino Pin | STM32 Pin | 5V Tolerate | Note |
26| ------------------- | --------- | ----------- | ----------------------------------------------------------------------------------------------------------- |
27| 0 (D0) | PB7 | Yes | |
28| 1 (D1) | PB6 | Yes | |
29| 2 (D2) | PB5 | No | PWM3-CH2. Token over by RT-Thread PWM device by default |
30| 3 (D3) | PB4 | Yes | PWM3-CH1. Token over by RT-Thread PWM device by default |
31| 4 (D4) | PB3 | Yes | PWM2-CH2. Token over by RT-Thread PWM device by default |
32| 5 (D5) | PA15 | Yes | PWM2-CH1. Token over by RT-Thread PWM device by default |
33| 6 (D6) | PA8 | Yes | |
34| 7 (D7, SS) | PB12 | Yes | SPI chip select by default |
35| 8 (D8, LED_BUILTIN) | PC13 | No | USER LED |
36| 9 (D9) | PC14 | No | |
37| 10 (D10) | PC15 | No | |
38| 11 (D11) | PA0 | No | |
39| 12 (D12) | PB0 | No | PWM3-CH3. Token over by RT-Thread PWM device by default |
40| 13 (D13) | PB1 | No | PWM3-CH4. Token over by RT-Thread PWM device by default |
41| 14 (D14) | PB9 | Yes | I2C-SDA. Token over by RT-Thread I2C device by default |
42| 15 (D15) | PB8 | Yes | I2C-SCL. Token over by RT-Thread I2C device by default |
43| 16 (D16) | PA12 | Yes | USB-DP. Token over by [TinyUSB](https://github.com/RT-Thread-packages/tinyusb) software package by default. |
44| 17 (D17) | PA11 | Yes | USB-DM. Token over by [TinyUSB](https://github.com/RT-Thread-packages/tinyusb) software package by default. |
45| 18 (D18) | PA10 | Yes | Serial-Rx. Token over by RT-Thread UART device by default |
46| 19 (D19) | PA9 | Yes | Serial-Tx. Token over by RT-Thread UART device by default |
47| 20 (D20) | PA2 | No | Serial2-Tx. Token over by RT-Thread UART device by default |
48| 21 (D21) | PA3 | No | Serial2-Rx. Token over by RT-Thread UART device by default |
49| 22 (D22) | PB10 | Yes | Serial3-Tx. Token over by RT-Thread UART device by default |
50| 23 (D23) | PB11 | Yes | Serial3-Rx. Token over by RT-Thread UART device by default |
51| 24 (D24) | PB15 | Yes | SPI-MOSI. Token over by RT-Thread SPI device by default |
52| 25 (D25) | PB14 | Yes | SPI-MISO. Token over by RT-Thread SPI device by default |
53| 26 (D26) | PB13 | Yes | SPI-SCK. Token over by RT-Thread SPI device by default |
54| 27 (A0) | PA1 | No | ADC1-CH1. Token over by RT-Thread ADC device by default |
55| 28 (A1) | PA4 | No | ADC1-CH4. Token over by RT-Thread ADC device by default |
56| 29 (A2) | PA5 | No | ADC1-CH5. Token over by RT-Thread ADC device by default |
57| 30 (A3) | PA6 | No | ADC1-CH6. Token over by RT-Thread ADC device by default |
58| 31 (A4) | PA7 | No | ADC1-CH7. Token over by RT-Thread ADC device by default |
59| 32 (A5) | -- | | ADC of chip internal reference voltage. Token over by RT-Thread ADC device by default |
60| 33 (A6) | -- | | ADC of chip internal temperature. Token over by RT-Thread ADC device by default |
61
62> Notice:
63>
64> 1. Don't use a same hardware timer to drive PWM (analogRead) and servos at same time, because hardware timers can only generate a same frequency for 4 PWM channels. Otherwise, it could cause a failure when drive servos.
65
66## 3 Communication
67
68### 3.1 I2C Bus
69
70I2C bus is `D14` and `D15` pins. Users can directly include the `#include <Wire.h>`, which is the Arduino official I2C header file, to use the I2C bus.
71
72### 3.2 SPI Bus
73
74SPI bus is `D24`, `D25` and `D26` pins. Users can directly include the `#include <SPI.h>`, which is the Arduino official SPI header file, to use the SPI bus. In addition, chip select pin (SS) also is used, which is `D7` by default.
75
76### 3.3 Serial
77
78This board supports to use `Serial.` method to operate `uart1` device; use `Serial2.` method to use `uart2` device; use `Serial3.` method to use `uart3` device. See [example](https://github.com/RTduino/RTduino/blob/master/examples/Basic/helloworld.cpp).
79
80### 3.4 USB Virtual Serial
81
82This board supports USB virtual serial. See [example](https://github.com/RTduino/RTduino/tree/master/examples/USBSerial). You may enable it if is needed.
83
84```Kconfig
85RT-Thread online packages --->
86 Arduino libraries --->
87 [*] RTduino: Arduino Ecological Compatibility Layer
88 [*] Enable USB Serial
89```
90
README_zh.md
1# STM32F103 Blue-Pill开发板的Arduino生态兼容说明
2
3[English](README.md) | **中文**
4
5## 1 RTduino - RT-Thread的Arduino生态兼容层
6
7STM32F103 Blue-Pill开发板已经完整适配了[RTduino软件包](https://github.com/RTduino/RTduino),即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP,并且可以使用大量Arduino社区丰富的库,是对RT-Thread生态的极大增强。更多信息,请参见[RTduino软件包说明文档](https://github.com/RTduino/RTduino)。
8
9### 1.1 如何开启针对本BSP的Arduino生态兼容层
10
11Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings:
12
13```Kconfig
14Hardware Drivers Config --->
15 Onboard Peripheral Drivers --->
16 [*] Compatible with Arduino Ecosystem (RTduino)
17```
18
19## 2 Arduino引脚排布
20
21更多引脚布局相关信息参见 [pins_arduino.c](pins_arduino.c) 和 [pins_arduino.h](pins_arduino.h)。
22
23
24
25| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 |
26| ------------------- | --------- | ---- | ------------------------------------------------------------------------- |
27| 0 (D0) | PB7 | 是 | |
28| 1 (D1) | PB6 | 是 | |
29| 2 (D2) | PB5 | 否 | PWM3-CH2,默认被RT-Thread的PWM设备框架pwm3接管 |
30| 3 (D3) | PB4 | 是 | PWM3-CH1,默认被RT-Thread的PWM设备框架pwm3接管 |
31| 4 (D4) | PB3 | 是 | PWM2-CH2,默认被RT-Thread的PWM设备框架pwm2接管 |
32| 5 (D5) | PA15 | 是 | PWM2-CH1,默认被RT-Thread的PWM设备框架pwm2接管 |
33| 6 (D6) | PA8 | 是 | |
34| 7 (D7, SS) | PB12 | 是 | SPI片选默认引脚 |
35| 8 (D8, LED_BUILTIN) | PC13 | 否 | 板载用户LED |
36| 9 (D9) | PC14 | 否 | |
37| 10 (D10) | PC15 | 否 | |
38| 11 (D11) | PA0 | 否 | |
39| 12 (D12) | PB0 | 否 | PWM3-CH3,默认被RT-Thread的PWM设备框架pwm3接管 |
40| 13 (D13) | PB1 | 否 | PWM3-CH4,默认被RT-Thread的PWM设备框架pwm3接管 |
41| 14 (D14) | PB9 | 是 | I2C-SDA,默认被RT-Thread的I2C设备框架i2c1总线接管 |
42| 15 (D15) | PB8 | 是 | I2C-SCL,默认被RT-Thread的I2C设备框架i2c1总线接管 |
43| 16 (D16) | PA12 | 是 | USB-DP,默认被 [TinyUSB软件包](https://github.com/RT-Thread-packages/tinyusb) 接管 |
44| 17 (D17) | PA11 | 是 | USB-DM,默认被 [TinyUSB软件包](https://github.com/RT-Thread-packages/tinyusb) 接管 |
45| 18 (D18) | PA10 | 是 | Serial-Rx,默认被RT-Thread的UART设备框架uart1接管 |
46| 19 (D19) | PA9 | 是 | Serial-Tx,默认被RT-Thread的UART设备框架uart1接管 |
47| 20 (D20) | PA2 | 否 | Serial2-Tx,默认被RT-Thread的UART设备框架uart2接管 |
48| 21 (D21) | PA3 | 否 | Serial2-Rx,默认被RT-Thread的UART设备框架uart2接管 |
49| 22 (D22) | PB10 | 是 | Serial3-Tx,默认被RT-Thread的UART设备框架uart3接管 |
50| 23 (D23) | PB11 | 是 | Serial3-Rx,默认被RT-Thread的UART设备框架uart3接管 |
51| 24 (D24) | PB15 | 是 | SPI-MOSI,默认被RT-Thread的SPI设备框架spi2接管 |
52| 25 (D25) | PB14 | 是 | SPI-MISO,默认被RT-Thread的SPI设备框架spi2接管 |
53| 26 (D26) | PB13 | 是 | SPI-SCK ,默认被RT-Thread的SPI设备框架spi2接管 |
54| 27 (A0) | PA1 | 否 | ADC1-CH1,默认被RT-Thread的ADC设备框架adc1接管 |
55| 28 (A1) | PA4 | 否 | ADC1-CH4,默认被RT-Thread的ADC设备框架adc1接管 |
56| 29 (A2) | PA5 | 否 | ADC1-CH5,默认被RT-Thread的ADC设备框架adc1接管 |
57| 30 (A3) | PA6 | 否 | ADC1-CH6,默认被RT-Thread的ADC设备框架adc1接管 |
58| 31 (A4) | PA7 | 否 | ADC1-CH7,默认被RT-Thread的ADC设备框架adc1接管 |
59| 32 (A5) | -- | | 芯片内部参考电压 ADC,默认被RT-Thread的ADC设备框架adc1接管 |
60| 33 (A6) | -- | | 芯片内部温度 ADC,默认被RT-Thread的ADC设备框架adc1接管 |
61
62> 注意:
63>
64> 1. 如果同时驱动舵机和调度analogWrite函数要选择不同定时器发生的PWM信号引脚,由于STM32的定时器4个通道需要保持相同的频率,如果采用相同的定时器发生的PWM分别驱动舵机和analogWrite,可能会导致舵机失效。
65
66## 3 通信
67
68### 3.1 I2C (Wire.h)
69
70I2C总线是 `D14` 和 `D15` 引脚,这两个引脚默认是被RT-Thread I2C设备框架接管的,直接引用`#include <Wire.h>`(Arduino官方I2C头文件)即可使用。
71
72### 3.2 SPI
73
74SPI总线是 `D24` 、`D25` 和 `D26` 引脚,这三个引脚默认是被RT-Thread SPI设备框架接管的,直接引用`#include <SPI.h>`(Arduino官方SPI头文件)即可使用。此外,还使用到了片选引脚(SS),默认为 `D7`。
75
76### 3.3 串口
77
78默认支持通过 `Serial.` 方法调用 `uart1` 串口设备;通过 `Serial2.` 方法调用 `uart2` 串口设备;通过 `Serial3.` 方法调用 `uart3` 串口设备。详见[例程](https://github.com/RTduino/RTduino/blob/master/examples/Basic/helloworld.cpp)。
79
80### 3.4 USB虚拟串口
81
82本BSP支持USB虚拟串口,如果需要使用,可以手动使能。详见[例程](https://github.com/RTduino/RTduino/tree/master/examples/USBSerial)。
83
84```Kconfig
85RT-Thread online packages --->
86 Arduino libraries --->
87 [*] RTduino: Arduino Ecological Compatibility Layer
88 [*] Enable USB Serial
89```
90