[arduino][lpc55s69] : 对接RTduino
This commit is contained in:
parent
aaba21c938
commit
1533b88390
@ -68,7 +68,7 @@ static rt_err_t lpc_drv_pwm_get(struct rt_device_pwm *device, struct rt_pwm_conf
|
|||||||
|
|
||||||
#ifdef BSP_USING_CTIMER2
|
#ifdef BSP_USING_CTIMER2
|
||||||
/* get frequence */
|
/* get frequence */
|
||||||
pwmClock = CLOCK_GetFreq(kCLOCK_CTimer2) ;
|
pwmClock = CLOCK_GetFreq(kCLOCK_Timer2) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
get_frequence = pwmClock / (base->MR[kCTIMER_Match_3] + 1);
|
get_frequence = pwmClock / (base->MR[kCTIMER_Match_3] + 1);
|
||||||
@ -110,7 +110,7 @@ static rt_err_t lpc_drv_pwm_set(struct rt_device_pwm *device, struct rt_pwm_conf
|
|||||||
{
|
{
|
||||||
/* Get the PWM period match value and pulse width match value of DEFAULT_FREQ PWM signal with DEFAULT_DUTY dutycycle */
|
/* Get the PWM period match value and pulse width match value of DEFAULT_FREQ PWM signal with DEFAULT_DUTY dutycycle */
|
||||||
/* Calculate PWM period match value */
|
/* Calculate PWM period match value */
|
||||||
pwmPeriod = (( CLOCK_GetFreq(kCLOCK_CTimer2) / (config.prescale + 1) ) / DEFAULT_FREQ) - 1;
|
pwmPeriod = (( CLOCK_GetFreq(kCLOCK_Timer2) / (config.prescale + 1) ) / DEFAULT_FREQ) - 1;
|
||||||
|
|
||||||
/* Calculate pulse width match value */
|
/* Calculate pulse width match value */
|
||||||
if (DEFAULT_DUTY == 0)
|
if (DEFAULT_DUTY == 0)
|
||||||
@ -175,7 +175,7 @@ int rt_hw_pwm_init(void)
|
|||||||
#ifdef BSP_USING_CTIMER2_MAT1
|
#ifdef BSP_USING_CTIMER2_MAT1
|
||||||
/* Get the PWM period match value and pulse width match value of DEFAULT_FREQ PWM signal with DEFAULT_DUTY dutycycle */
|
/* Get the PWM period match value and pulse width match value of DEFAULT_FREQ PWM signal with DEFAULT_DUTY dutycycle */
|
||||||
/* Calculate PWM period match value */
|
/* Calculate PWM period match value */
|
||||||
pwmPeriod = (( CLOCK_GetFreq(kCLOCK_CTimer2) / (config.prescale + 1) ) / DEFAULT_FREQ) - 1;
|
pwmPeriod = (( CLOCK_GetFreq(kCLOCK_Timer2) / (config.prescale + 1) ) / DEFAULT_FREQ) - 1;
|
||||||
|
|
||||||
/* Calculate pulse width match value */
|
/* Calculate pulse width match value */
|
||||||
if (DEFAULT_DUTY == 0)
|
if (DEFAULT_DUTY == 0)
|
||||||
@ -186,7 +186,7 @@ int rt_hw_pwm_init(void)
|
|||||||
{
|
{
|
||||||
pulsePeriod = (pwmPeriod * (100 - DEFAULT_DUTY)) / 100;
|
pulsePeriod = (pwmPeriod * (100 - DEFAULT_DUTY)) / 100;
|
||||||
}
|
}
|
||||||
CTIMER_SetupPwmPeriod(CTIMER2, kCTIMER_Match_1 , pwmPeriod, pulsePeriod, false);
|
CTIMER_SetupPwmPeriod(CTIMER2, kCTIMER_Match_3 , kCTIMER_Match_1, pwmPeriod, pulsePeriod, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = rt_device_pwm_register(&pwm1_device, "pwm1", &lpc_drv_ops, CTIMER2);
|
ret = rt_device_pwm_register(&pwm1_device, "pwm1", &lpc_drv_ops, CTIMER2);
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import rtconfig
|
|
||||||
from building import *
|
from building import *
|
||||||
|
import os
|
||||||
|
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
src = Glob('main.c')
|
|
||||||
CPPPATH = [cwd]
|
CPPPATH = [cwd]
|
||||||
|
src = Glob('*.c')
|
||||||
|
|
||||||
# add for startup script
|
if GetDepend(['PKG_USING_RTDUINO']) and not GetDepend(['RTDUINO_NO_SETUP_LOOP']):
|
||||||
if rtconfig.PLATFORM in ['gcc']:
|
src += ['arduino_main.cpp']
|
||||||
CPPDEFINES = ['__START=entry']
|
|
||||||
else:
|
|
||||||
CPPDEFINES = []
|
|
||||||
|
|
||||||
|
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||||
|
|
||||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
|
list = os.listdir(cwd)
|
||||||
|
for item in list:
|
||||||
|
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||||
|
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||||
|
|
||||||
Return('group')
|
Return('group')
|
||||||
|
32
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/arduino_main.cpp
Normal file
32
bsp/lpc55sxx/lpc55s69_nxp_evk/applications/arduino_main.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-02-22 ChuShicheng first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
int led = 37; /* LED pin */
|
||||||
|
int brightness = 0;
|
||||||
|
int fadeAmount = 5;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
/* Do not invoke pinMode for the PWM IO! */
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
analogWrite(led, brightness);
|
||||||
|
brightness = brightness + fadeAmount;
|
||||||
|
if (brightness <= 0 || brightness >= 255)
|
||||||
|
{
|
||||||
|
fadeAmount = -fadeAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
# lpc55s69_nxp_evk开发板的Arduino生态兼容说明
|
||||||
|
|
||||||
|
## 1 RTduino - RT-Thread的Arduino生态兼容层
|
||||||
|
|
||||||
|
lpc55s69_nxp_evk开发板已经完整适配了[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)。
|
||||||
|
|
||||||
|
| Arduino引脚编号 | STM32引脚编号 | 5V容忍 | 备注 |
|
||||||
|
| ------------------- | --------- | ---- | ------------------------------------------------------------------------- |
|
||||||
|
| 0 (D0) | P | 是/否 | |
|
||||||
|
| 1 (D1) | P | 是/否 | PWM1-CH3,默认被RT-Thread的PWM设备框架pwm1接管 |
|
||||||
|
| 2 (D2) | P | 是/否 | Serial-RX,默认被RT-Thread的UART设备框架uart1接管 |
|
||||||
|
| 3 (D3) | P | 是/否 | Serial-TX,默认被RT-Thread的UART设备框架uart1接管 |
|
||||||
|
| 4 (D4) | P | 是/否 | PWM2-CH1,默认被RT-Thread的PWM设备框架pwm2接管 |
|
||||||
|
| 5 (D5) | P | 是/否 | PWM2-CH2,默认被RT-Thread的PWM设备框架pwm2接管 |
|
||||||
|
| 6 (D6) | P | 是/否 | 板载用户LED |
|
||||||
|
| 7 (D7) | P | 是/否 | PWM1-CH0,默认被RT-Thread的PWM设备框架pwm1接管 |
|
||||||
|
| 8 (D8) | P | 是/否 | |
|
||||||
|
| 9 (D9) | P | 是/否 | PWM2-CH0,默认被RT-Thread的PWM设备框架pwm2接管 |
|
||||||
|
| 10 (D10) | P | 是/否 | |
|
||||||
|
| 11 (D11) | P | 是/否 | |
|
||||||
|
| 12 (D12) | P | 是/否 | |
|
||||||
|
| 13 (D13) | P | 是/否 | |
|
||||||
|
| 14 (D14) | P | 是/否 | PWM3-CH2,默认被RT-Thread的PWM设备框架pwm3接管 |
|
||||||
|
| 15 (D15) | P | 是/否 | |
|
||||||
|
| 16 (D16) | P | 是/否 | I2C1-SCL,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||||
|
| 17 (D17) | P | 是/否 | I2C1-SDA,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||||
|
| 18 (A0) | P | 是/否 | ADC0-CH8,默认被RT-Thread的ADC设备框架adc0接管 |
|
||||||
|
| 19 (A1) | P | 是/否 | ADC0-CH0,默认被RT-Thread的ADC设备框架adc0接管 |
|
||||||
|
| 20 (A2) | -- | | 芯片内部温度 ADC,默认被RT-Thread的ADC设备框架adc1接管 |
|
||||||
|
| 21 (A3) | -- | | 芯片内部参考电压 ADC,默认被RT-Thread的ADC设备框架adc1接管 |
|
@ -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')
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-02-22 ChuShicheng 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, 50},
|
||||||
|
{D1, 49, "pwm1", 3}, /* PWM */
|
||||||
|
{D2, 57, "uart1"}, /* Serial-RX */
|
||||||
|
{D3, 28, "uart1"}, /* Serial-TX */
|
||||||
|
{D4, 39, "pwm2", 1}, /* PWM */
|
||||||
|
{D5, 40, "pwm2", 2}, /* PWM */
|
||||||
|
{D6, 37}, /* LED_BUILTIN */
|
||||||
|
{D7, 43, "pwm1", 0}, /* PWM */
|
||||||
|
{D8, 41},
|
||||||
|
{D9, 38, "pwm2", 0}, /* PWM */
|
||||||
|
{D10, 34},
|
||||||
|
{D11, 27},
|
||||||
|
{D12, 36},
|
||||||
|
{D13, 35},
|
||||||
|
{D14, 54, "pwm3", 2}, /* PWM */
|
||||||
|
{D15, 53},
|
||||||
|
{D16, 15, "i2c1"}, /* I2C-SCL (Wire) */
|
||||||
|
{D17, 14, "i2c1"}, /* I2C-SDA (Wire) */
|
||||||
|
{A0, 17, "adc0", 8}, /* ADC */
|
||||||
|
{A1, 24, "adc0", 0}, /* ADC */
|
||||||
|
{A2, RT_NULL, "adc0", 26}, /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
|
||||||
|
{A3, RT_NULL, "adc0", 13}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
|
||||||
|
};
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2023-02-22 ChuShicheng 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 A0 (18)
|
||||||
|
#define A1 (19)
|
||||||
|
#define A2 (20)
|
||||||
|
#define A3 (21)
|
||||||
|
|
||||||
|
#define F_CPU 150000000L /* CPU:150MHz */
|
||||||
|
|
||||||
|
#define LED_BUILTIN D6 /* Default Built-in LED */
|
||||||
|
|
||||||
|
/* i2c1 : P-SDA P-SCL */
|
||||||
|
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
|
||||||
|
|
||||||
|
#endif /* Pins_Arduino_h */
|
@ -180,6 +180,18 @@ menu "On-chip Peripheral Drivers"
|
|||||||
default y
|
default y
|
||||||
|
|
||||||
if BSP_USING_PWM
|
if BSP_USING_PWM
|
||||||
|
config BSP_USING_CTIMER0_MAT3
|
||||||
|
bool "Enable CIMER0 Match3 as PWM output"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config BSP_USING_CTIMER1_MAT0
|
||||||
|
bool "Enable CIMER1 Match0 as PWM output"
|
||||||
|
default y
|
||||||
|
|
||||||
|
config BSP_USING_CTIMER1_MAT3
|
||||||
|
bool "Enable CIMER1 Match3 as PWM output"
|
||||||
|
default y
|
||||||
|
|
||||||
config BSP_USING_CTIMER2_MAT0
|
config BSP_USING_CTIMER2_MAT0
|
||||||
bool "Enable CIMER2 Match0 as PWM output"
|
bool "Enable CIMER2 Match0 as PWM output"
|
||||||
default y
|
default y
|
||||||
@ -191,6 +203,10 @@ menu "On-chip Peripheral Drivers"
|
|||||||
config BSP_USING_CTIMER2_MAT2
|
config BSP_USING_CTIMER2_MAT2
|
||||||
bool "Enable CIMER2 Match2 as PWM output"
|
bool "Enable CIMER2 Match2 as PWM output"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config BSP_USING_CTIMER3_MAT2
|
||||||
|
bool "Enable CIMER3 Match2 as PWM output"
|
||||||
|
default n
|
||||||
endif
|
endif
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
@ -215,6 +231,26 @@ menu "Onboard Peripheral Drivers"
|
|||||||
default "i2c4"
|
default "i2c4"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
config BSP_USING_ARDUINO
|
||||||
|
bool "Compatible with Arduino Ecosystem (RTduino)"
|
||||||
|
select PKG_USING_RTDUINO
|
||||||
|
select BSP_USING_STLINK_TO_USART
|
||||||
|
select BSP_USING_GPIO
|
||||||
|
select BSP_USING_ADC
|
||||||
|
select BSP_USING_ADC0
|
||||||
|
select BSP_USING_PWM
|
||||||
|
select BSP_USING_CTIMER1_MAT0
|
||||||
|
select BSP_USING_CTIMER1_MAT3
|
||||||
|
select BSP_USING_CTIMER2_MAT0
|
||||||
|
select BSP_USING_CTIMER2_MAT1
|
||||||
|
select BSP_USING_CTIMER2_MAT2
|
||||||
|
select BSP_USING_CTIMER3_MAT2
|
||||||
|
select BSP_USING_I2C
|
||||||
|
select BSP_USING_I2C1
|
||||||
|
imply RTDUINO_USING_SERVO
|
||||||
|
imply RTDUINO_USING_WIRE
|
||||||
|
default n
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "Board extended module Drivers"
|
menu "Board extended module Drivers"
|
||||||
|
@ -19,7 +19,7 @@ if CROSS_TOOL == 'gcc':
|
|||||||
PLATFORM = 'gcc'
|
PLATFORM = 'gcc'
|
||||||
EXEC_PATH = r'C:\Users\XXYYZZ'
|
EXEC_PATH = r'C:\Users\XXYYZZ'
|
||||||
elif CROSS_TOOL == 'keil':
|
elif CROSS_TOOL == 'keil':
|
||||||
PLATFORM = 'armcc'
|
PLATFORM = 'armclang'
|
||||||
EXEC_PATH = r'C:/Keil_v5'
|
EXEC_PATH = r'C:/Keil_v5'
|
||||||
elif CROSS_TOOL == 'iar':
|
elif CROSS_TOOL == 'iar':
|
||||||
PLATFORM = 'iccarm'
|
PLATFORM = 'iccarm'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user