diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_main.cpp b/bsp/stm32/stm32f407-rt-spark/applications/arduino_main.cpp new file mode 100644 index 0000000000..1335fec08c --- /dev/null +++ b/bsp/stm32/stm32f407-rt-spark/applications/arduino_main.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2006-2024, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-04-08 Li ZhenHong first version + */ + +#include + +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); +} diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/README.md b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/README.md new file mode 100644 index 0000000000..330a1089ff --- /dev/null +++ b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/README.md @@ -0,0 +1,69 @@ +# stm32f407-rt-spark 开发板的Arduino生态兼容说明 + +## 1 RTduino - RT-Thread的Arduino生态兼容层 + +stm32f407-rt-spark 开发板已经完整适配了[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引脚排布 + +更多引脚布局相关信息参见 [pins_arduino.c](pins_arduino.c) 和 [pins_arduino.h](pins_arduino.h)。 + +![Rt-spark_Rtduino_Pin_Map.drawio](Rt-spark_Rtduino_Pin_Map.drawio.png) + +| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 | +| ------------------- | --------- | ---- | ------------------------------------------------------------------------- | +| 0 (D0) | GET_PIN(A, 10) | 是 | Serial-RX,默认被RT-Thread的UART设备框架uart1接管 | +| 1 (D1) | GET_PIN(A, 9) | 是 | Serial-TX,默认被RT-Thread的UART设备框架uart1接管 | +| 2 (D2) | GET_PIN(A, 8) | 是 | | +| 3 (D3) | GET_PIN(B, 10) | 是 | PWM2-CH3,默认被RT-Thread的PWM设备框架pwm2接管 | +| 4 (D4) | GET_PIN(A, 1) | 是 | | +| 5 (D5) | GET_PIN(B, 14) | 是 | | +| 6 (D6) | GET_PIN(B, 11) | 是 | PWM2-CH4,默认被RT-Thread的PWM设备框架pwm2接管 | +| 7 (D7) | GET_PIN(B, 15) | 是 | | +| 8 (D8) | GET_PIN(F, 15) | 是 | | +| 9 (D9) | GET_PIN(E, 11) | 是 | PWM1-CH2,默认被RT-Thread的PWM设备框架pwm1接管 | +| 10 (D10) | GET_PIN(E, 13) | 是 | PWM1-CH3,默认被RT-Thread的PWM设备框架pwm1接管 | +| 11 (D11) | GET_PIN(D, 12) | 是 | PWM4-CH1,默认被RT-Thread的PWM设备框架pwm4接管 | +| 12 (D12) | GET_PIN(D, 10) | 是 | | +| 13 (D13) | GET_PIN(D, 8) | 是 | | +| 14 (D14) | GET_PIN(E, 14) | 是 | | +| 15 (D15) | GET_PIN(E, 12) | 是 | | +| 16 (D16) | GET_PIN(E, 15) | 是 | | +| 17 (D17) | GET_PIN(D, 9) | 是 | | +| 18 (D18) | GET_PIN(G, 2) | 是 | | +| 19 (D19) | GET_PIN(B, 2) | 是 | | +| 20 (D20) | GET_PIN(G, 0) | 是 | | +| 21 (D21) | GET_PIN(A, 0) | 是 | | +| 22 (D22) | GET_PIN(G, 5) | 是 | SSPI1-SCK,默认被RT-Thread的SPI设备框架sspi1接管| +| 23 (D23) | GET_PIN(G, 3) | 是 | SSPI1-MISO,默认被RT-Thread的SPI设备框架sspi1接管 | +| 24 (D24) | GET_PIN(G, 1) | 是 | SSPI1-MOSI,默认被RT-Thread的SPI设备框架sspi1接管 | +| 25 (D25) | GET_PIN(G, 7) | 是 | I2C1-SCL,默认被RT-Thread的I2C设备框架i2c1接管 | +| 26 (D26) | GET_PIN(D, 7) | 是 | I2C1-SDA,默认被RT-Thread的I2C设备框架i2c1接管 | +| 27 (D27) | GET_PIN(B, 6) | 是 | I2C2-SCL,默认被RT-Thread的I2C设备框架i2c2接管 | +| 28 (D28) | GET_PIN(B, 7) | 是 | I2C2-SDA,默认被RT-Thread的I2C设备框架i2c2接管 | +| 29 (D29) | GET_PIN(G, 6) | 是 | | +| 30 (D30) | GET_PIN(G, 4) | 是 | | +| 31 (D31) | GET_PIN(A, 2) | 是 | Serial2-TX,默认被RT-Thread的UART设备框架uart2接管 | +| 32 (D32) | GET_PIN(A, 3) | 是 | Serial2-RX,默认被RT-Thread的UART设备框架uart2接管 | +| 33 (D33) | GET_PIN(F, 12) | 是 | 板载用户R_LED | +| 34 (D34) | GET_PIN(F, 11) | 是 | 板载用户B_LED | +| 35 (D35) | GET_PIN(B, 0) | 是 | 板载蜂鸣器 | +| 36 (D36) | GET_PIN(C, 5) | 是 | 板载按键KEY_UP | +| 37 (D37) | GET_PIN(C, 1) | 是 | 板载按键KEY_DOWM | +| 38 (D38) | GET_PIN(C, 0) | 是 | 板载按键KEY_LEFT | +| 39 (D39) | GET_PIN(C, 4) | 是 | 板载按键KEY_RIGHT | +| 40 (A0) | GET_PIN(F, 6) | 是 | ADC3-CH4,默认被RT-Thread的ADC设备框架adc3接管 | +| 41 (A1) | GET_PIN(F, 7) | 是 | ADC3-CH5,默认被RT-Thread的ADC设备框架adc3接管 | +| 42 (A2) | GET_PIN(F, 4) | 是 | ADC3-CH14,默认被RT-Thread的ADC设备框架adc3接管 | +| 43 (A3) | GET_PIN(F, 5) | 是 | ADC3-CH15,默认被RT-Thread的ADC设备框架adc3接管 | +| 44 (DAC0) | GET_PIN(A, 4) | 否 | DAC1-CH1,默认被RT-Thread的DAC设备框架dac1接管 | diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/Rt-spark_Rtduino_Pin_Map.drawio.png b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/Rt-spark_Rtduino_Pin_Map.drawio.png new file mode 100644 index 0000000000..b84867a536 Binary files /dev/null and b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/Rt-spark_Rtduino_Pin_Map.drawio.png differ diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/SConscript b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/SConscript new file mode 100644 index 0000000000..da85e053c3 --- /dev/null +++ b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/SConscript @@ -0,0 +1,9 @@ +from building import * + +cwd = GetCurrentDir() +src = Glob('*.c') + Glob('*.cpp') +inc = [cwd] + +group = DefineGroup('RTduino-pinout', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc) + +Return('group') diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.c b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.c new file mode 100644 index 0000000000..88fed11beb --- /dev/null +++ b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2006-2024, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-04-10 Li ZhenHong first version + */ + +#include +#include "pins_arduino.h" +#include + +/* + * {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, 10), "uart1"}, /* Serial-RX */ + {D1, GET_PIN(A, 9), "uart1"}, /* Serial-TX */ + {D2, GET_PIN(A, 8)}, + {D3, GET_PIN(B, 10), "pwm2", 3}, /* PWM */ + {D4, GET_PIN(A, 1)}, + {D5, GET_PIN(B, 14)}, + {D6, GET_PIN(B, 11), "pwm2", 4}, /* PWM */ + {D7, GET_PIN(B, 15)}, + {D8, GET_PIN(F, 15)}, + {D9, GET_PIN(E, 11), "pwm1", 2}, /* PWM */ + {D10, GET_PIN(E, 13), "pwm1", 3}, /* PWM */ + {D11, GET_PIN(D, 12), "pwm4", 1}, /* PWM */ + {D12, GET_PIN(D, 10)}, + {D13, GET_PIN(D, 8)}, + {D14, GET_PIN(E, 14)}, + {D15, GET_PIN(E, 12)}, + {D16, GET_PIN(E, 15)}, + {D17, GET_PIN(D, 9)}, + {D18, GET_PIN(G, 2)}, + {D19, GET_PIN(B, 2)}, + {D20, GET_PIN(G, 0)}, + {D21, GET_PIN(A, 0)}, + {D22, GET_PIN(G, 5), "sspi1"}, /* SOFT-SPI-SCK */ + {D23, GET_PIN(G, 3), "sspi1"}, /* SOFT-SPI-SCK */ + {D24, GET_PIN(G, 1), "sspi1"}, /* SOFT-SPI-SCK */ + {D25, GET_PIN(G, 7), "i2c4"}, /* I2C-SCL (Wire) */ + {D26, GET_PIN(D, 7), "i2c4"}, /* I2C-SDA (Wire) */ + {D27, GET_PIN(B, 6), "i2c5"}, /* I2C-SCL (Wire) */ + {D28, GET_PIN(B, 7), "i2c5"}, /* I2C-SDA (Wire) */ + {D29, GET_PIN(G, 6)}, /* SPI-SS */ + {D30, GET_PIN(G, 4)}, + {D31, GET_PIN(A, 2), "uart2"}, /* Serial2-TX */ + {D32, GET_PIN(A, 3), "uart2"}, /* Serial2-RX */ + {D33, GET_PIN(F, 12)}, /* On-Board R_LED */ + {D34, GET_PIN(F, 11)}, /* On-Board B_LED */ + {D35, GET_PIN(B, 0)}, /* On_Board Buzzer */ + {D36, GET_PIN(C, 5)}, /* On-Board KEY_UP */ + {D37, GET_PIN(C, 1)}, /* On-Board KEY_DOWM */ + {D38, GET_PIN(C, 0)}, /* On-Board KEY_LEFT */ + {D39, GET_PIN(C, 4)}, /* On-Board KEY_RIGHT */ + {A0, GET_PIN(F, 6), "adc3", 4}, /* ADC */ + {A1, GET_PIN(F, 7), "adc3", 5}, /* ADC */ + {A2, GET_PIN(F, 4), "adc3", 14}, /* ADC */ + {A3, GET_PIN(F, 5), "adc3", 15}, /* ADC */ + {DAC0, GET_PIN(A, 4), "dac1", 1}, /* DAC */ +}; diff --git a/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.h b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.h new file mode 100644 index 0000000000..12b7d60885 --- /dev/null +++ b/bsp/stm32/stm32f407-rt-spark/applications/arduino_pinout/pins_arduino.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2006-2024, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2024-04-07 Li ZhenHong 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 D29 (29) +#define D30 (30) +#define D31 (31) +#define D32 (32) +#define D33 (33) +#define D34 (34) +#define D35 (35) +#define D36 (36) +#define D37 (37) +#define D38 (38) +#define D39 (39) +#define A0 (40) +#define A1 (41) +#define A2 (42) +#define A3 (43) +#define DAC0 (44) + +#define RTDUINO_PIN_MAX_LIMIT DAC0 /* pin number max limit check */ + +#define F_CPU 168000000L /* CPU:168MHz */ + +#define LED_BUILTIN D33 /* Default Built-in LED */ + +/* i2c4 : PD.7-SDA PG.7-SCL */ +#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c4" + +#define SS D32 /* Chip select pin of default spi */ +/* sspi1 : PG.5-SCK PG.3-MISO PG.1-MOSI */ +#define RTDUINO_DEFAULT_SPI_BUS_NAME "sspi1" + +/* Serial2(uart2) : PA.2-TX PA.3-RX */ +#define RTDUINO_SERIAL2_DEVICE_NAME "uart2" + +#endif /* Pins_Arduino_h */