Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bsp][pico] add rtduino #8304

Merged
merged 2 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bsp/raspberry-pico/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bsp/raspberry-pico/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions bsp/raspberry-pico/applications/SConscript
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
24 changes: 24 additions & 0 deletions bsp/raspberry-pico/applications/arduino_main.cpp
Original file line number Diff line number Diff line change
@@ -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 <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);
}
54 changes: 54 additions & 0 deletions bsp/raspberry-pico/applications/arduino_pinout/README.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions bsp/raspberry-pico/applications/arduino_pinout/SConscript
Original file line number Diff line number Diff line change
@@ -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')
50 changes: 50 additions & 0 deletions bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.c
Original file line number Diff line number Diff line change
@@ -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 <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, 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},
};
49 changes: 49 additions & 0 deletions bsp/raspberry-pico/applications/arduino_pinout/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -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 */
10 changes: 10 additions & 0 deletions bsp/raspberry-pico/link.ld
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 : {
Expand Down
Loading