From f94b30a8289e0ecd53deb5f8723b68339b76fff9 Mon Sep 17 00:00:00 2001 From: Z8MAN8 <1468559561@qq.com> Date: Mon, 27 Nov 2023 23:15:41 +0800 Subject: [PATCH 1/2] [bsp][pico] add rtduino --- bsp/raspberry-pico/Kconfig | 12 +++++ bsp/raspberry-pico/applications/SConscript | 7 ++- .../applications/arduino_main.cpp | 24 +++++++++ .../applications/arduino_pinout/README.md | 54 +++++++++++++++++++ .../applications/arduino_pinout/SConscript | 9 ++++ .../arduino_pinout/pins_arduino.c | 50 +++++++++++++++++ .../arduino_pinout/pins_arduino.h | 49 +++++++++++++++++ 7 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 bsp/raspberry-pico/applications/arduino_main.cpp create mode 100644 bsp/raspberry-pico/applications/arduino_pinout/README.md create mode 100644 bsp/raspberry-pico/applications/arduino_pinout/SConscript create mode 100644 bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c create mode 100644 bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h diff --git a/bsp/raspberry-pico/Kconfig b/bsp/raspberry-pico/Kconfig index 2dce6c344b6..909503c7edf 100644 --- a/bsp/raspberry-pico/Kconfig +++ b/bsp/raspberry-pico/Kconfig @@ -44,6 +44,18 @@ menu "Onboard Peripheral Drivers" default y endif + config BSP_USING_ARDUINO + bool "Compatible with Arduino Ecosystem (RTduino)" + select PKG_USING_RTDUINO + select BSP_USING_UART0 + select BSP_UART0_TX_PIN_0 + select BSP_UART0_RX_PIN_1 + select BSP_USING_UART1 + select BSP_UART1_TX_PIN_8 + select BSP_UART1_RX_PIN_9 + select BSP_USING_GPIO + default n + config BSP_USING_ON_CHIP_FLASH bool "Enable On-Chip FLASH" select FAL_DEBUG_CONFIG diff --git a/bsp/raspberry-pico/applications/SConscript b/bsp/raspberry-pico/applications/SConscript index 496584a1ae4..e1c7fa59962 100644 --- a/bsp/raspberry-pico/applications/SConscript +++ b/bsp/raspberry-pico/applications/SConscript @@ -1,9 +1,12 @@ from building import * import os -cwd = GetCurrentDir() -src = ['main.c'] +cwd = GetCurrentDir() CPPPATH = [cwd] +src = Glob('*.c') + +if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']): + src += ['arduino_main.cpp'] group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/raspberry-pico/applications/arduino_main.cpp b/bsp/raspberry-pico/applications/arduino_main.cpp new file mode 100644 index 00000000000..d04447ae443 --- /dev/null +++ b/bsp/raspberry-pico/applications/arduino_main.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-11-27 ShichengChu 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/raspberry-pico/applications/arduino_pinout/README.md b/bsp/raspberry-pico/applications/arduino_pinout/README.md new file mode 100644 index 00000000000..60e936910dc --- /dev/null +++ b/bsp/raspberry-pico/applications/arduino_pinout/README.md @@ -0,0 +1,54 @@ +# xxx 开发板的Arduino生态兼容说明 + +## 1 RTduino - RT-Thread的Arduino生态兼容层 + +xxx 开发板已经完整适配了[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)。 + +![xxx-pinout](xxx-pinout.jpg) +| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 | +| ------------------- | --------- | ---- | ------------------------------------------------------------------------- | +| 0 (D0) | P | 是/否 | Serial-TX,默认被RT-Thread的UART设备框架uart1接管 | +| 1 (D1) | P | 是/否 | Serial-RX,默认被RT-Thread的UART设备框架uart1接管 | +| 2 (D2) | P | 是/否 | | +| 3 (D3) | P | 是/否 | | +| 4 (D4) | P | 是/否 | | +| 5 (D5) | P | 是/否 | | +| 6 (D6) | P | 是/否 | | +| 7 (D7) | P | 是/否 | | +| 8 (D8) | P | 是/否 | Serial2-TX,默认被RT-Thread的UART设备框架uart2接管 | +| 9 (D9) | P | 是/否 | Serial2-RX,默认被RT-Thread的UART设备框架uart2接管 | +| 10 (D10) | P | 是/否 | | +| 11 (D11) | P | 是/否 | | +| 12 (D12) | P | 是/否 | | +| 13 (D13) | P | 是/否 | | +| 14 (D14) | P | 是/否 | | +| 15 (D15) | P | 是/否 | | +| 16 (D16) | P | 是/否 | | +| 17 (D17) | P | 是/否 | | +| 18 (D18) | P | 是/否 | | +| 19 (D19) | P | 是/否 | | +| 20 (D20) | P | 是/否 | | +| 21 (D21) | P | 是/否 | | +| 22 (D22) | P | 是/否 | | +| 23 (D23) | P | 是/否 | 板载用户LED | +| 24 (D24) | P | 是/否 | | +| 25 (D25) | P | 是/否 | | + +> 注意: +> +> 1. xxxxxxxxx +> 2. xxxxxxxxx diff --git a/bsp/raspberry-pico/applications/arduino_pinout/SConscript b/bsp/raspberry-pico/applications/arduino_pinout/SConscript new file mode 100644 index 00000000000..25399290275 --- /dev/null +++ b/bsp/raspberry-pico/applications/arduino_pinout/SConscript @@ -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') diff --git a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c new file mode 100644 index 00000000000..2bd98a1340c --- /dev/null +++ b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-11-27 ShichengChu first version + */ + +#include +#include +#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, 0, "uart1"}, /* Serial-TX */ + {D1, 1, "uart1"}, /* Serial-RX */ + {D2, 2}, + {D3, 3}, + {D4, 4}, + {D5, 5}, + {D6, 6}, + {D7, 7}, + {D8, 8, "uart2"}, /* Serial2-TX */ + {D9, 9, "uart2"}, /* Serial2-RX */ + {D10, 10}, + {D11, 11}, + {D12, 12}, + {D13, 13}, + {D14, 14}, + {D15, 15}, + {D16, 16}, + {D17, 17}, + {D18, 18}, + {D19, 19}, + {D20, 20}, + {D21, 21}, + {D22, 22}, + {D23, 25}, /* LED_BUILTIN */ + {D24, 26}, + {D25, 27}, +}; diff --git a/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h new file mode 100644 index 00000000000..6d412fb4937 --- /dev/null +++ b/bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2006-2023, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2023-11-27 ShichengChu 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 F_CPU 133000000L /* CPU:133MHz */ + +#define LED_BUILTIN D23 /* Default Built-in LED */ + +/* Serial2 : P-TX P-RX */ +#define RTDUINO_SERIAL2_DEVICE_NAME "uart2" + +#endif /* Pins_Arduino_h */ From 67956ff1031c26d7ae8d5f21fe49efacaf57c395 Mon Sep 17 00:00:00 2001 From: Z8MAN8 <1468559561@qq.com> Date: Tue, 28 Nov 2023 16:22:05 +0800 Subject: [PATCH 2/2] update .ld and SConstruct files --- bsp/raspberry-pico/SConstruct | 2 +- bsp/raspberry-pico/link.ld | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bsp/raspberry-pico/SConstruct b/bsp/raspberry-pico/SConstruct index bb72242f849..49b94d7c60e 100644 --- a/bsp/raspberry-pico/SConstruct +++ b/bsp/raspberry-pico/SConstruct @@ -16,7 +16,7 @@ DefaultEnvironment(tools=[]) env = Environment(tools = ['mingw'], AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS, - CXX = rtconfig.CXX, + CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS, AR = rtconfig.AR, ARFLAGS = '-rc', LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) env.PrependENVPath('PATH', rtconfig.EXEC_PATH) diff --git a/bsp/raspberry-pico/link.ld b/bsp/raspberry-pico/link.ld index f073344f2c7..d997d973d52 100644 --- a/bsp/raspberry-pico/link.ld +++ b/bsp/raspberry-pico/link.ld @@ -87,6 +87,8 @@ SECTIONS __rt_init_start = .; KEEP(*(SORT(.rti_fn*))) __rt_init_end = .; + + . = ALIGN(4); /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -102,7 +104,15 @@ SECTIONS *(.dtors) *(.eh_frame*) + + PROVIDE(__ctors_start__ = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + PROVIDE(__ctors_end__ = .); + . = ALIGN(4); + + _etext = .; } > FLASH .rodata : {