mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-02 14:23:19 +08:00
[stm32f401-nucleo] arduino support (#5842)
* [stm32f401-nucleo] arduino support * 增加application arduino main文件 * 调整目录结构
This commit is contained in:
@@ -162,7 +162,7 @@ static struct stm32_pwm stm32_pwm_obj[] =
|
||||
/* APBx timer clocks frequency doubler state related to APB1CLKDivider value */
|
||||
static void pclkx_doubler_get(rt_uint32_t *pclk1_doubler, rt_uint32_t *pclk2_doubler)
|
||||
{
|
||||
rt_uint32_t flatency = 0;
|
||||
uint32_t flatency = 0;
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
RT_ASSERT(pclk1_doubler != RT_NULL);
|
||||
|
||||
@@ -5,6 +5,9 @@ cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
src = ['main.c']
|
||||
|
||||
if GetDepend(['PKG_USING_RTDUINO']):
|
||||
src += ['arduino_main.cpp']
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-12-10 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
uint8_t led = LED_BUILTIN;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
/* put your setup code here, to run once: */
|
||||
pinMode(led, OUTPUT);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
/* put your main code here, to run repeatedly: */
|
||||
digitalWrite(led, !digitalRead(led));
|
||||
delay(100);
|
||||
}
|
||||
+35
-27
@@ -1,8 +1,8 @@
|
||||
# STM32L072 Nucleo开发板的Arduino生态兼容说明
|
||||
# STM32F072 Nucleo开发板的Arduino生态兼容说明
|
||||
|
||||
## 1 RTduino - RT-Thread的Arduino生态兼容层
|
||||
|
||||
STM32L072 Nucleo开发板已经完整适配了[RTduino软件包](https://github.com/mysterywolf/RTduino),即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP,并且可以使用大量Arduino社区丰富的库,是对RT-Thread生态的极大增强。更多信息,请参见[RTduino软件包说明文档](https://github.com/mysterywolf/RTduino)。
|
||||
STM32F072 Nucleo开发板已经完整适配了[RTduino软件包](https://github.com/mysterywolf/RTduino),即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP,并且可以使用大量Arduino社区丰富的库,是对RT-Thread生态的极大增强。更多信息,请参见[RTduino软件包说明文档](https://github.com/mysterywolf/RTduino)。
|
||||
|
||||
### 1.1 如何开启针对本BSP的Arduino生态兼容层
|
||||
|
||||
@@ -16,33 +16,37 @@ Hardware Drivers Config --->
|
||||
|
||||
## 2 Arduino引脚排布
|
||||
|
||||

|
||||
|
||||
该BSP遵照Arduino UNO板的引脚排列方式。详见 `pins_arduino.c`
|
||||
|
||||
| Arduino引脚编号 | STM32引脚编号 | 备注 |
|
||||
| --------------- | ------------- | ---------------------------------------------- |
|
||||
| 0 (D0) | -- | 该引脚在UNO板中为串口RX引脚,不能被当做普通IO |
|
||||
| 1 (D1) | -- | 该引脚在UNO板中为串口TX引脚,不能被当做普通IO |
|
||||
| 2 (D2) | PA10 | |
|
||||
| 3 (D3) | PB3 | PWM(定时器2发生) |
|
||||
| 4 (D4) | PB5 | |
|
||||
| 5 (D5) | PB4 | PWM(定时器3发生) |
|
||||
| 6 (D6) | PB10 | PWM(定时器2发生) |
|
||||
| 7 (D7) | PA8 | |
|
||||
| 8 (D8) | PA9 | |
|
||||
| 9 (D9) | PC7 | PWM(定时器3发生) |
|
||||
| 10 (D10) | PB6 | PWM反相位(定时器16发生) |
|
||||
| 11 (D11) | PA7 | PWM(定时器17发生) |
|
||||
| 12 (D12) | PA6 | |
|
||||
| 13 (D13) | PA5 | |
|
||||
| 14 (D14) | PC13 | 扩展:Nucleo板载用户按键(左侧蓝色) |
|
||||
| A0 | PA0 | ADC |
|
||||
| A1 | PA1 | ADC |
|
||||
| A2 | PA4 | ADC |
|
||||
| A3 | PB0 | ADC |
|
||||
| A4 | PC1 | ADC |
|
||||
| A5 | PC0 | ADC |
|
||||
| -- | PB9 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管 |
|
||||
| -- | | I2C1_SCL,被RT-Thread的I2C设备框架i2c1总线接管 |
|
||||
| Arduino引脚编号 | STM32引脚编号 | 备注 |
|
||||
| --------------- | ------------- | ------------------------------------------------------------ |
|
||||
| 0 (D0) | -- | 该引脚在UNO板中为串口RX引脚,不可当做普通IO |
|
||||
| 1 (D1) | -- | 该引脚在UNO板中为串口TX引脚,不可当做普通IO |
|
||||
| 2 (D2) | PA10 | |
|
||||
| 3 (D3) | PB3 | PWM(定时器2发生) |
|
||||
| 4 (D4) | PB5 | |
|
||||
| 5 (D5) | PB4 | PWM(定时器3发生) |
|
||||
| 6 (D6) | PB10 | PWM(定时器2发生) |
|
||||
| 7 (D7) | PA8 | |
|
||||
| 8 (D8) | PA9 | |
|
||||
| 9 (D9) | PC7 | PWM(定时器3发生) |
|
||||
| 10 (D10) | PB6 | PWM反相位(定时器16发生) |
|
||||
| 11 (D11) | PA7 | PWM(定时器17发生) |
|
||||
| 12 (D12) | PA6 | |
|
||||
| 13 (D13) | PA5 | |
|
||||
| 14 (D14) | PB9 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 15 (D15) | PB8 | I2C1_SCL,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 16 (D16) | PC13 | Nucleo板载用户按键(左侧蓝色) |
|
||||
| A0 | PA0 | ADC |
|
||||
| A1 | PA1 | ADC |
|
||||
| A2 | PA4 | ADC |
|
||||
| A3 | PB0 | ADC |
|
||||
| A4 | PC1 | ADC |
|
||||
| A5 | PC0 | ADC |
|
||||
| A6 | -- | 芯片内部参考电压 ADC |
|
||||
| A7 | -- | 芯片内部温度 ADC |
|
||||
|
||||
> 注意:
|
||||
>
|
||||
@@ -51,6 +55,10 @@ Hardware Drivers Config --->
|
||||
> 3. USART2是Nucleo板的默认串口,理论应对接到了Arduino引脚编号的D0和D1,但是其实际用于串口通信,因此不允许当做普通IO来使用和操作。如果需要将D0、D1与STM32 USART2的引脚相连,需要手动焊接锡桥SB62、SB63。
|
||||
> 4. Nucleo板的Arduino接口中AVDD(即AREF)默认是与VDD相连的,如果需要扩展板提供外部参考电压,需要将SB57锡桥挑开。
|
||||
|
||||
> 参考资料
|
||||
>
|
||||
> 【1】[STM32 Nucleo板官方手册](https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf)
|
||||
|
||||
## 3 I2C总线
|
||||
|
||||
STM32F072 Nucleo板的I2C总线是板上丝印的 `SCL/D15` 和 `SDA/D14` 引脚,这两个引脚是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚,直接引用`#include <Wire.h>`(Arduino官方I2C头文件)即可使用。
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 284 KiB |
+6
-2
@@ -34,11 +34,15 @@ const pin_map_t pin_map_table[]=
|
||||
{D11, GET_PIN(A,7), "pwm17", 1}, /* PWM */
|
||||
{D12, GET_PIN(A,6)},
|
||||
{D13, GET_PIN(A,5)},
|
||||
{D14, GET_PIN(C,13)}, /* user button */
|
||||
{D14}, /* I2C1-SDA */
|
||||
{D15}, /* I2C1-SCL */
|
||||
{D16, GET_PIN(C,13)}, /* user button */
|
||||
{A0, GET_PIN(A,0), "adc1", 0}, /* ADC */
|
||||
{A1, GET_PIN(A,1), "adc1", 1}, /* ADC */
|
||||
{A2, GET_PIN(A,4), "adc1", 4}, /* ADC */
|
||||
{A3, GET_PIN(B,0), "adc1", 8}, /* ADC */
|
||||
{A4, GET_PIN(C,1), "adc1", 11}, /* ADC */
|
||||
{A5, GET_PIN(C,0), "adc1", 10} /* ADC */
|
||||
{A5, GET_PIN(C,0), "adc1", 10}, /* ADC */
|
||||
{A6, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
|
||||
{A7, RT_NULL, "adc1", 16} /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
|
||||
};
|
||||
+10
-6
@@ -27,12 +27,16 @@
|
||||
#define D12 (12)
|
||||
#define D13 (13)
|
||||
#define D14 (14)
|
||||
#define A0 (15)
|
||||
#define A1 (16)
|
||||
#define A2 (17)
|
||||
#define A3 (18)
|
||||
#define A4 (19)
|
||||
#define A5 (20)
|
||||
#define D15 (15)
|
||||
#define D16 (16)
|
||||
#define A0 (17)
|
||||
#define A1 (18)
|
||||
#define A2 (19)
|
||||
#define A3 (20)
|
||||
#define A4 (21)
|
||||
#define A5 (22)
|
||||
#define A6 (23)
|
||||
#define A7 (24)
|
||||
|
||||
#define LED_BUILTIN D13 /* Default Built-in LED */
|
||||
|
||||
@@ -30,11 +30,13 @@ Mcu.Pin19=PB3
|
||||
Mcu.Pin2=PC15-OSC32_OUT
|
||||
Mcu.Pin20=PB4
|
||||
Mcu.Pin21=PB6
|
||||
Mcu.Pin22=VP_SYS_VS_Systick
|
||||
Mcu.Pin23=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin24=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin25=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin26=VP_TIM17_VS_ClockSourceINT
|
||||
Mcu.Pin22=VP_ADC_TempSens_Input
|
||||
Mcu.Pin23=VP_ADC_Vref_Input
|
||||
Mcu.Pin24=VP_SYS_VS_Systick
|
||||
Mcu.Pin25=VP_TIM2_VS_ClockSourceINT
|
||||
Mcu.Pin26=VP_TIM3_VS_ClockSourceINT
|
||||
Mcu.Pin27=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin28=VP_TIM17_VS_ClockSourceINT
|
||||
Mcu.Pin3=PF0-OSC_IN
|
||||
Mcu.Pin4=PF1-OSC_OUT
|
||||
Mcu.Pin5=PC0
|
||||
@@ -42,7 +44,7 @@ Mcu.Pin6=PC1
|
||||
Mcu.Pin7=PA0
|
||||
Mcu.Pin8=PA1
|
||||
Mcu.Pin9=PA2
|
||||
Mcu.PinsNb=27
|
||||
Mcu.PinsNb=29
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F072RBTx
|
||||
@@ -209,6 +211,10 @@ TIM3.IPParameters=Channel-PWM Generation2 CH2,Channel-PWM Generation1 CH1
|
||||
USART2.IPParameters=VirtualMode,VirtualMode-Asynchronous
|
||||
USART2.VirtualMode=VM_ASYNC
|
||||
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
||||
VP_ADC_TempSens_Input.Mode=IN-TempSens
|
||||
VP_ADC_TempSens_Input.Signal=ADC_TempSens_Input
|
||||
VP_ADC_Vref_Input.Mode=IN-Vrefint
|
||||
VP_ADC_Vref_Input.Signal=ADC_Vref_Input
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
VP_TIM16_VS_ClockSourceINT.Mode=Enable_Timer
|
||||
|
||||
@@ -274,6 +274,22 @@ static void MX_ADC_Init(void)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure for the selected ADC regular channel to be converted.
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
|
||||
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure for the selected ADC regular channel to be converted.
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_VREFINT;
|
||||
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC_Init 2 */
|
||||
|
||||
/* USER CODE END ADC_Init 2 */
|
||||
|
||||
@@ -36,6 +36,7 @@ menu "Onboard Peripheral Drivers"
|
||||
imply RTDUINO_USING_SERVO
|
||||
imply RTDUINO_USING_WIRE
|
||||
imply RTDUINO_USING_ADAFRUIT
|
||||
imply RTUSING_USING_SPI
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -5,6 +5,9 @@ cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
src = ['main.c']
|
||||
|
||||
if GetDepend(['PKG_USING_RTDUINO']):
|
||||
src += ['arduino_main.cpp']
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-04-19 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
/* put your setup code here, to run once: */
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
/* put your main code here, to run repeatedly: */
|
||||
Serial.println("Hello RT-Thread from arduino_main.cpp\n");
|
||||
delay(800);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
# STM32F401 Nucleo开发板的Arduino生态兼容说明
|
||||
|
||||
## 1 RTduino - RT-Thread的Arduino生态兼容层
|
||||
|
||||
STM32F401 Nucleo开发板已经完整适配了[RTduino软件包](https://github.com/mysterywolf/RTduino),即RT-Thread的Arduino生态兼容层。用户可以按照Arduino的编程习惯来操作该BSP,并且可以使用大量Arduino社区丰富的库,是对RT-Thread生态的极大增强。更多信息,请参见[RTduino软件包说明文档](https://github.com/mysterywolf/RTduino)。
|
||||
|
||||
### 1.1 如何开启针对本BSP的Arduino生态兼容层
|
||||
|
||||
Env 工具下敲入 menuconfig 命令,或者 RT-Thread Studio IDE 下选择 RT-Thread Settings:
|
||||
|
||||
```Kconfig
|
||||
Hardware Drivers Config --->
|
||||
Onboard Peripheral Drivers --->
|
||||
[*] Support Arduino
|
||||
```
|
||||
|
||||
## 2 Arduino引脚排布
|
||||
|
||||

|
||||
|
||||
该BSP遵照Arduino UNO板的引脚排列方式。详见 `pins_arduino.c`
|
||||
|
||||
| Arduino引脚编号 | STM32引脚编号 | 备注 |
|
||||
| --------------- | ------------- | ------------------------------------------------------------ |
|
||||
| 0 (D0) | -- | 该引脚在UNO板中为串口RX引脚,不可当做普通IO |
|
||||
| 1 (D1) | -- | 该引脚在UNO板中为串口TX引脚,不可当做普通IO |
|
||||
| 2 (D2) | PA10 | |
|
||||
| 3 (D3) | PB3 | PWM(定时器2发生) |
|
||||
| 4 (D4) | PB5 | |
|
||||
| 5 (D5) | PB4 | PWM(定时器3发生) |
|
||||
| 6 (D6) | PB10 | PWM(定时器2发生) |
|
||||
| 7 (D7) | PA8 | |
|
||||
| 8 (D8) | PA9 | |
|
||||
| 9 (D9) | PC7 | PWM(定时器3发生) |
|
||||
| 10 (D10) | PB6 | SPI1-CS,被RT-Thread的SPI设备框架spi1总线接管,不可当做普通IO |
|
||||
| 11 (D11) | PA7 | SPI1-MOSI,被RT-Thread的SPI设备框架spi1总线接管,不可当做普通IO |
|
||||
| 12 (D12) | PA6 | SPI1-MISO,被RT-Thread的SPI设备框架spi1总线接管,不可当做普通IO |
|
||||
| 13 (D13) | PA5 | SPI1-SCK,被RT-Thread的SPI设备框架spi1总线接管,不可当做普通IO |
|
||||
| 14 (D14) | PB9 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 15 (D15) | PB8 | I2C1_SCL,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| 16 (D16) | PC13 | Nucleo板载用户按键(左侧蓝色) |
|
||||
| A0 | PA0 | ADC |
|
||||
| A1 | PA1 | ADC |
|
||||
| A2 | PA4 | ADC |
|
||||
| A3 | PB0 | ADC |
|
||||
| A4 | PC1 | ADC |
|
||||
| A5 | PC0 | ADC |
|
||||
| A6 | -- | 芯片内部参考电压 ADC |
|
||||
| A7 | -- | 芯片内部温度 ADC |
|
||||
|
||||
> 注意:
|
||||
>
|
||||
> 1. D10引脚是PWM反相位引脚,这是由STM32设计决定的,例如正常的PWM设定占空比是20%,它就是20%。但是对于D10引脚,设定占空比是20%,实际输出的占空比是80%。
|
||||
> 2. 驱动舵机和analogWrite函数要选择不同定时器发生的PWM信号引脚,由于STM32的定时器4个通道需要保持相同的频率,如果采用相同的定时器发生的PWM分别驱动舵机和analogWrite,可能会导致舵机失效。
|
||||
> 3. USART2是Nucleo板的默认串口,理论应对接到了Arduino引脚编号的D0和D1,但是其实际用于串口通信,因此不允许当做普通IO来使用和操作。如果需要将D0、D1与STM32 USART2的引脚相连,需要手动焊接锡桥SB62、SB63。
|
||||
> 4. Nucleo板的Arduino接口中AVDD(即AREF)默认是与VDD相连的,如果需要扩展板提供外部参考电压,需要将SB57锡桥挑开。
|
||||
|
||||
> 参考资料
|
||||
>
|
||||
> 【1】[STM32 Nucleo板官方手册](https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf)
|
||||
|
||||
## 3 I2C总线
|
||||
|
||||
STM32F401 Nucleo板的I2C总线是板上丝印的 `SCL/D15` 和 `SDA/D14` 引脚,这两个引脚是被RT-Thread I2C设备框架接管的,不需要直接操控这两个引脚,直接引用`#include <Wire.h>`(Arduino官方I2C头文件)即可使用。
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 283 KiB |
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-04-19 Meco Man first version
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <board.h>
|
||||
#include "pins_arduino.h"
|
||||
|
||||
/*
|
||||
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), 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}, /* RX */
|
||||
{D1}, /* TX */
|
||||
{D2, GET_PIN(A,10)},
|
||||
{D3, GET_PIN(B,3), "pwm2", 2}, /* PWM */
|
||||
{D4, GET_PIN(B,5)},
|
||||
{D5, GET_PIN(B,4), "pwm3", 1}, /* PWM */
|
||||
{D6, GET_PIN(B,10), "pwm2", 3}, /* PWM */
|
||||
{D7, GET_PIN(A,8)},
|
||||
{D8, GET_PIN(A,9)},
|
||||
{D9, GET_PIN(C,7), "pwm3", 2}, /* PWM */
|
||||
{D10}, /* SPI1-CS */
|
||||
{D11}, /* SPI1-MOSI */
|
||||
{D12}, /* SPI1-MISO */
|
||||
{D13}, /* SPI1-SCK */
|
||||
{D14}, /* I2C1-SDA */
|
||||
{D15}, /* I2C1-SCL */
|
||||
{D16, GET_PIN(C,13)}, /* user button */
|
||||
{A0, GET_PIN(A,0), "adc1", 0}, /* ADC */
|
||||
{A1, GET_PIN(A,1), "adc1", 1}, /* ADC */
|
||||
{A2, GET_PIN(A,4), "adc1", 4}, /* ADC */
|
||||
{A3, GET_PIN(B,0), "adc1", 8}, /* ADC */
|
||||
{A4, GET_PIN(C,1), "adc1", 11}, /* ADC */
|
||||
{A5, GET_PIN(C,0), "adc1", 10}, /* ADC */
|
||||
{A6, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
|
||||
{A7, RT_NULL, "adc1", 16} /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-04-19 Meco Man 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 A0 (17)
|
||||
#define A1 (18)
|
||||
#define A2 (19)
|
||||
#define A3 (20)
|
||||
#define A4 (21)
|
||||
#define A5 (22)
|
||||
#define A6 (23)
|
||||
#define A7 (24)
|
||||
|
||||
#define LED_BUILTIN D13 /* Default Built-in LED */
|
||||
|
||||
#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c1"
|
||||
|
||||
#endif /* Pins_Arduino_h */
|
||||
@@ -6,25 +6,16 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-11-06 SummerGift first version
|
||||
* 2022-04-19 Meco Man solve LED interferes with SPI
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <board.h>
|
||||
|
||||
/* defined the LD2 (user LED) pin: PB1 */
|
||||
#define LED2_PIN GET_PIN(A, 5)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* set LED0 pin mode to output */
|
||||
rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_pin_write(LED2_PIN, PIN_HIGH);
|
||||
rt_thread_mdelay(500);
|
||||
rt_pin_write(LED2_PIN, PIN_LOW);
|
||||
rt_thread_mdelay(500);
|
||||
rt_kprintf("Hello RT-Thread from main.c\n");
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,43 +1,70 @@
|
||||
#MicroXplorer Configuration settings - do not modify
|
||||
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_0
|
||||
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag
|
||||
ADC1.NbrOfConversionFlag=1
|
||||
ADC1.Rank-0\#ChannelRegularConversion=1
|
||||
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES
|
||||
ADC1.master=1
|
||||
File.Version=6
|
||||
KeepUserPlacement=false
|
||||
Mcu.CPN=STM32F401RET6
|
||||
Mcu.Family=STM32F4
|
||||
Mcu.IP0=NVIC
|
||||
Mcu.IP1=RCC
|
||||
Mcu.IP2=SPI1
|
||||
Mcu.IP3=SYS
|
||||
Mcu.IP4=USART2
|
||||
Mcu.IPNb=5
|
||||
Mcu.IP0=ADC1
|
||||
Mcu.IP1=NVIC
|
||||
Mcu.IP2=RCC
|
||||
Mcu.IP3=SPI1
|
||||
Mcu.IP4=SYS
|
||||
Mcu.IP5=TIM2
|
||||
Mcu.IP6=TIM3
|
||||
Mcu.IP7=USART2
|
||||
Mcu.IPNb=8
|
||||
Mcu.Name=STM32F401R(D-E)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PC14-OSC32_IN
|
||||
Mcu.Pin1=PC15-OSC32_OUT
|
||||
Mcu.Pin10=PA14
|
||||
Mcu.Pin11=VP_SYS_VS_Systick
|
||||
Mcu.Pin10=PA4
|
||||
Mcu.Pin11=PA5
|
||||
Mcu.Pin12=PA6
|
||||
Mcu.Pin13=PA7
|
||||
Mcu.Pin14=PB0
|
||||
Mcu.Pin15=PB10
|
||||
Mcu.Pin16=PC7
|
||||
Mcu.Pin17=PA13
|
||||
Mcu.Pin18=PA14
|
||||
Mcu.Pin19=PB3
|
||||
Mcu.Pin2=PH0 - OSC_IN
|
||||
Mcu.Pin20=PB4
|
||||
Mcu.Pin21=VP_ADC1_TempSens_Input
|
||||
Mcu.Pin22=VP_ADC1_Vref_Input
|
||||
Mcu.Pin23=VP_SYS_VS_Systick
|
||||
Mcu.Pin3=PH1 - OSC_OUT
|
||||
Mcu.Pin4=PA2
|
||||
Mcu.Pin5=PA3
|
||||
Mcu.Pin6=PA5
|
||||
Mcu.Pin7=PA6
|
||||
Mcu.Pin8=PA7
|
||||
Mcu.Pin9=PA13
|
||||
Mcu.PinsNb=12
|
||||
Mcu.Pin4=PC0
|
||||
Mcu.Pin5=PC1
|
||||
Mcu.Pin6=PA0-WKUP
|
||||
Mcu.Pin7=PA1
|
||||
Mcu.Pin8=PA2
|
||||
Mcu.Pin9=PA3
|
||||
Mcu.PinsNb=24
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F401RETx
|
||||
MxCube.Version=5.1.0
|
||||
MxDb.Version=DB.5.0.10
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
MxCube.Version=6.5.0
|
||||
MxDb.Version=DB.6.0.50
|
||||
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:true
|
||||
PA0-WKUP.Locked=true
|
||||
PA0-WKUP.Signal=ADCx_IN0
|
||||
PA1.Locked=true
|
||||
PA1.Signal=ADCx_IN1
|
||||
PA13.Mode=Serial_Wire
|
||||
PA13.Signal=SYS_JTMS-SWDIO
|
||||
PA14.Mode=Serial_Wire
|
||||
@@ -52,6 +79,8 @@ PA3.GPIO_PuPd=GPIO_PULLUP
|
||||
PA3.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
||||
PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA4.Locked=true
|
||||
PA4.Signal=ADCx_IN4
|
||||
PA5.Locked=true
|
||||
PA5.Mode=Full_Duplex_Master
|
||||
PA5.Signal=SPI1_SCK
|
||||
@@ -59,10 +88,24 @@ PA6.Mode=Full_Duplex_Master
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PB0.Locked=true
|
||||
PB0.Signal=ADCx_IN8
|
||||
PB10.Locked=true
|
||||
PB10.Signal=S_TIM2_CH3
|
||||
PB3.Locked=true
|
||||
PB3.Signal=S_TIM2_CH2
|
||||
PB4.Locked=true
|
||||
PB4.Signal=S_TIM3_CH1
|
||||
PC0.Locked=true
|
||||
PC0.Signal=ADCx_IN10
|
||||
PC1.Locked=true
|
||||
PC1.Signal=ADCx_IN11
|
||||
PC14-OSC32_IN.Mode=LSE-External-Oscillator
|
||||
PC14-OSC32_IN.Signal=RCC_OSC32_IN
|
||||
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
||||
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
||||
PC7.Locked=true
|
||||
PC7.Signal=S_TIM3_CH2
|
||||
PH0\ -\ OSC_IN.Mode=HSE-External-Clock-Source
|
||||
PH0\ -\ OSC_IN.Signal=RCC_OSC_IN
|
||||
PH1\ -\ OSC_OUT.Mode=HSE-External-Clock-Source
|
||||
@@ -77,7 +120,7 @@ ProjectManager.CustomerFirmwarePackage=
|
||||
ProjectManager.DefaultFWLocation=true
|
||||
ProjectManager.DeletePrevious=true
|
||||
ProjectManager.DeviceId=STM32F401RETx
|
||||
ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.24.0
|
||||
ProjectManager.FirmwarePackage=STM32Cube FW_F4 V1.27.0
|
||||
ProjectManager.FreePins=false
|
||||
ProjectManager.HalAssertFull=false
|
||||
ProjectManager.HeapSize=0x200
|
||||
@@ -90,11 +133,12 @@ ProjectManager.PreviousToolchain=
|
||||
ProjectManager.ProjectBuild=false
|
||||
ProjectManager.ProjectFileName=CubeMX_Config.ioc
|
||||
ProjectManager.ProjectName=CubeMX_Config
|
||||
ProjectManager.RegisterCallBack=
|
||||
ProjectManager.StackSize=0x400
|
||||
ProjectManager.TargetToolchain=MDK-ARM V5
|
||||
ProjectManager.ToolChainLocation=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI1_Init-SPI1-false-HAL-true,5-MX_ADC1_Init-ADC1-false-HAL-true,6-MX_TIM2_Init-TIM2-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true
|
||||
RCC.48MHZClocksFreq_Value=84000000
|
||||
RCC.AHBFreq_Value=84000000
|
||||
RCC.APB1CLKDivider=RCC_HCLK_DIV2
|
||||
@@ -123,12 +167,42 @@ RCC.VCOI2SOutputFreq_Value=192000000
|
||||
RCC.VCOInputFreq_Value=1000000
|
||||
RCC.VCOOutputFreq_Value=336000000
|
||||
RCC.VcooutputI2S=96000000
|
||||
SH.ADCx_IN0.0=ADC1_IN0,IN0
|
||||
SH.ADCx_IN0.ConfNb=1
|
||||
SH.ADCx_IN1.0=ADC1_IN1,IN1
|
||||
SH.ADCx_IN1.ConfNb=1
|
||||
SH.ADCx_IN10.0=ADC1_IN10,IN10
|
||||
SH.ADCx_IN10.ConfNb=1
|
||||
SH.ADCx_IN11.0=ADC1_IN11,IN11
|
||||
SH.ADCx_IN11.ConfNb=1
|
||||
SH.ADCx_IN4.0=ADC1_IN4,IN4
|
||||
SH.ADCx_IN4.ConfNb=1
|
||||
SH.ADCx_IN8.0=ADC1_IN8,IN8
|
||||
SH.ADCx_IN8.ConfNb=1
|
||||
SH.S_TIM2_CH2.0=TIM2_CH2,PWM Generation2 CH2
|
||||
SH.S_TIM2_CH2.ConfNb=1
|
||||
SH.S_TIM2_CH3.0=TIM2_CH3,PWM Generation3 CH3
|
||||
SH.S_TIM2_CH3.ConfNb=1
|
||||
SH.S_TIM3_CH1.0=TIM3_CH1,PWM Generation1 CH1
|
||||
SH.S_TIM3_CH1.ConfNb=1
|
||||
SH.S_TIM3_CH2.0=TIM3_CH2,PWM Generation2 CH2
|
||||
SH.S_TIM3_CH2.ConfNb=1
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM2.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||
TIM2.IPParameters=Channel-PWM Generation2 CH2,Channel-PWM Generation3 CH3
|
||||
TIM3.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
|
||||
TIM3.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||
TIM3.IPParameters=Channel-PWM Generation1 CH1,Channel-PWM Generation2 CH2
|
||||
USART2.IPParameters=VirtualMode
|
||||
USART2.VirtualMode=VM_ASYNC
|
||||
VP_ADC1_TempSens_Input.Mode=IN-TempSens
|
||||
VP_ADC1_TempSens_Input.Signal=ADC1_TempSens_Input
|
||||
VP_ADC1_Vref_Input.Mode=IN-Vrefint
|
||||
VP_ADC1_Vref_Input.Signal=ADC1_Vref_Input
|
||||
VP_SYS_VS_Systick.Mode=SysTick
|
||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||
board=custom
|
||||
|
||||
@@ -70,6 +70,8 @@ extern "C" {
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
@@ -87,5 +89,3 @@ void Error_Handler(void);
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,7 +39,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
@@ -80,5 +80,3 @@ void SysTick_Handler(void);
|
||||
#endif
|
||||
|
||||
#endif /* __STM32F4xx_IT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -77,7 +77,7 @@
|
||||
/* USER CODE END EV */
|
||||
|
||||
/******************************************************************************/
|
||||
/* Cortex-M4 Processor Interruption and Exception Handlers */
|
||||
/* Cortex-M4 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* @brief This function handles Non maskable interrupt.
|
||||
@@ -215,4 +215,3 @@ void SysTick_Handler(void)
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -14,6 +14,29 @@ menu "Onboard Peripheral Drivers"
|
||||
select BSP_USING_UART2
|
||||
default y
|
||||
|
||||
config BSP_USING_ARDUINO
|
||||
bool "Support Arduino"
|
||||
select PKG_USING_RTDUINO
|
||||
select BSP_USING_GPIO
|
||||
select BSP_USING_ADC
|
||||
select BSP_USING_ADC1
|
||||
select BSP_USING_PWM
|
||||
select BSP_USING_PWM2
|
||||
select BSP_USING_PWM2_CH2
|
||||
select BSP_USING_PWM2_CH3
|
||||
select BSP_USING_PWM3
|
||||
select BSP_USING_PWM3_CH1
|
||||
select BSP_USING_PWM3_CH2
|
||||
select BSP_USING_I2C
|
||||
select BSP_USING_I2C1
|
||||
select BSP_USING_SPI
|
||||
# select BSP_USING_SPI1
|
||||
imply RTDUINO_USING_SERVO
|
||||
imply RTDUINO_USING_WIRE
|
||||
imply RTDUINO_USING_ADAFRUIT
|
||||
imply RTUSING_USING_SPI
|
||||
default n
|
||||
|
||||
endmenu
|
||||
|
||||
menu "On-chip Peripheral Drivers"
|
||||
@@ -37,7 +60,50 @@ menu "On-chip Peripheral Drivers"
|
||||
depends on BSP_USING_UART2 && RT_SERIAL_USING_DMA
|
||||
default n
|
||||
endif
|
||||
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
bool "Enable ADC"
|
||||
default n
|
||||
select RT_USING_ADC
|
||||
if BSP_USING_ADC
|
||||
config BSP_USING_ADC1
|
||||
bool "Enable ADC1"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_PWM
|
||||
bool "Enable PWM"
|
||||
default n
|
||||
select RT_USING_PWM
|
||||
|
||||
if BSP_USING_PWM
|
||||
menuconfig BSP_USING_PWM2
|
||||
bool "Enable timer2 output PWM"
|
||||
default n
|
||||
if BSP_USING_PWM2
|
||||
config BSP_USING_PWM2_CH2
|
||||
bool "Enable PWM2 channel2"
|
||||
default n
|
||||
|
||||
config BSP_USING_PWM2_CH3
|
||||
bool "Enable PWM2 channel3"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_PWM3
|
||||
bool "Enable timer3 output PWM"
|
||||
default n
|
||||
if BSP_USING_PWM3
|
||||
config BSP_USING_PWM3_CH1
|
||||
bool "Enable PWM3 channel1"
|
||||
default n
|
||||
|
||||
config BSP_USING_PWM3_CH2
|
||||
bool "Enable PWM3 channel2"
|
||||
default n
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
default n
|
||||
@@ -59,22 +125,30 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_I2C1
|
||||
bool "Enable I2C1 BUS (software simulation)"
|
||||
menuconfig BSP_USING_I2C
|
||||
bool "Enable I2C BUS"
|
||||
default n
|
||||
select RT_USING_I2C
|
||||
select RT_USING_I2C_BITOPS
|
||||
select RT_USING_PIN
|
||||
if BSP_USING_I2C1
|
||||
config BSP_I2C1_SCL_PIN
|
||||
int "i2c1 scl pin number"
|
||||
range 1 216
|
||||
default 15
|
||||
config BSP_I2C1_SDA_PIN
|
||||
int "I2C1 sda pin number"
|
||||
range 1 216
|
||||
default 16
|
||||
|
||||
if BSP_USING_I2C
|
||||
config BSP_USING_I2C1
|
||||
bool "Enable I2C1 Bus (User I2C)"
|
||||
default n
|
||||
if BSP_USING_I2C1
|
||||
comment "Notice: PB9 --> 25; PB8 --> 24"
|
||||
config BSP_I2C1_SCL_PIN
|
||||
int "i2c1 SCL pin number"
|
||||
range 1 176
|
||||
default 24
|
||||
config BSP_I2C1_SDA_PIN
|
||||
int "i2c1 SDA pin number"
|
||||
range 1 176
|
||||
default 25
|
||||
endif
|
||||
endif
|
||||
|
||||
source "../libraries/HAL_Drivers/Kconfig"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -2,14 +2,15 @@ from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
CPPPATH = [cwd]
|
||||
src = ['main.c']
|
||||
|
||||
if GetDepend(['PKG_USING_RTDUINO']):
|
||||
src += ['arduino_main.cpp']
|
||||
|
||||
if GetDepend(['PKG_USING_NRF24L01']):
|
||||
src += ['nrf24l01_init.c']
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-12-10 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
uint8_t led = LED_BUILTIN;
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
/* put your setup code here, to run once: */
|
||||
pinMode(led, OUTPUT);
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
/* put your main code here, to run repeatedly: */
|
||||
digitalWrite(led, !digitalRead(led));
|
||||
delay(100);
|
||||
}
|
||||
+39
-35
@@ -20,41 +20,41 @@ Hardware Drivers Config --->
|
||||
|
||||
### 2.1 Arduino引脚排布统览
|
||||
|
||||
| Arduino引脚编号 | STM32引脚编号 | 备注 |
|
||||
| --------------------- | ------------- | ---------------------------------------------- |
|
||||
| 0 (D0) | -- | 该引脚在UNO板中为串口RX引脚,不能被当做普通IO |
|
||||
| 1 (D1) | -- | 该引脚在UNO板中为串口TX引脚,不能被当做普通IO |
|
||||
| 2 (D2) | PB9 | 普通IO |
|
||||
| 3 (D3) | PD15 | PWM(定时器4发生) |
|
||||
| 4 (D4) | PA8 | 普通IO |
|
||||
| 5 (D5) | PD14 | 普通IO |
|
||||
| 6 (D6) | PB11 | PWM(定时器2发生) |
|
||||
| 7 (D7) | PB14 | 普通IO |
|
||||
| 8 (D8) | PB12 | 普通IO |
|
||||
| 9 (D9) | PD12 | PWM(定时器4发生) |
|
||||
| 10 (D10) | PB10 | PWM(定时器2发生) |
|
||||
| 11 (D11) | PB8 | PWM(定时器4发生) |
|
||||
| 12 (D12) | PB15 | 普通IO |
|
||||
| 13 (D13) | PB13 | 普通IO |
|
||||
| 14 (D14) | PA1 | 振动电机-A |
|
||||
| 15 (D15) | PA0 | 振动电机-B |
|
||||
| 16 (D16) | PB2 | 蜂鸣器 |
|
||||
| 17 (D17) | PD10 | KEY0 |
|
||||
| 18 (D18) | PD9 | KEY1 |
|
||||
| 19 (D19) | PD8 | KEY2 |
|
||||
| 20 (D20) | PC13 | KEY-WKUP |
|
||||
| 21 (D21) | PE7 | 红色LED |
|
||||
| 22 (D22, LED_BUILTIN) | PE8 | 绿色LED,Arduino默认LED |
|
||||
| 23 (D23) | PE9 | 蓝色LED,具有PWM功能(定时器1发生) |
|
||||
| 24 (D24) | PB0 | 红外发送 |
|
||||
| 25 (D25) | PB1 | 红外接收 |
|
||||
| A0 | PC2 | ADC |
|
||||
| A1 | PC4 | ADC |
|
||||
| A2 | -- | 芯片内部参考电压 ADC |
|
||||
| A3 | -- | 芯片内部温度 ADC |
|
||||
| DAC0 | PA4 | 真模拟输出 DAC |
|
||||
| -- | PC7 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管 |
|
||||
| -- | PC6 | I2C1-SCL,被RT-Thread的I2C设备框架i2c1总线接管 |
|
||||
| Arduino引脚编号 | STM32引脚编号 | 备注 |
|
||||
| --------------------- | ------------- | ------------------------------------------------------------ |
|
||||
| 0 (D0) | -- | 该引脚在UNO板中为串口RX引脚,不可当做普通IO |
|
||||
| 1 (D1) | -- | 该引脚在UNO板中为串口TX引脚,不可当做普通IO |
|
||||
| 2 (D2) | PB9 | 普通IO |
|
||||
| 3 (D3) | PD15 | PWM(定时器4发生) |
|
||||
| 4 (D4) | PA8 | 普通IO |
|
||||
| 5 (D5) | PD14 | 普通IO |
|
||||
| 6 (D6) | PB11 | PWM(定时器2发生) |
|
||||
| 7 (D7) | PB14 | 普通IO |
|
||||
| 8 (D8) | PB12 | 普通IO |
|
||||
| 9 (D9) | PD12 | PWM(定时器4发生) |
|
||||
| 10 (D10) | PB10 | PWM(定时器2发生) |
|
||||
| 11 (D11) | PB8 | PWM(定时器4发生) |
|
||||
| 12 (D12) | PB15 | 普通IO |
|
||||
| 13 (D13) | PB13 | 普通IO |
|
||||
| 14 (D14) | PA1 | 振动电机-A |
|
||||
| 15 (D15) | PA0 | 振动电机-B |
|
||||
| 16 (D16) | PB2 | 蜂鸣器 |
|
||||
| 17 (D17) | PD10 | KEY0 |
|
||||
| 18 (D18) | PD9 | KEY1 |
|
||||
| 19 (D19) | PD8 | KEY2 |
|
||||
| 20 (D20) | PC13 | KEY-WKUP |
|
||||
| 21 (D21) | PE7 | 红色LED |
|
||||
| 22 (D22, LED_BUILTIN) | PE8 | 绿色LED,Arduino默认LED |
|
||||
| 23 (D23) | PE9 | 蓝色LED,具有PWM功能(定时器1发生) |
|
||||
| 24 (D24) | PB0 | 红外发送 |
|
||||
| 25 (D25) | PB1 | 红外接收 |
|
||||
| A0 | PC2 | ADC |
|
||||
| A1 | PC4 | ADC |
|
||||
| A2 | -- | 芯片内部参考电压 ADC |
|
||||
| A3 | -- | 芯片内部温度 ADC |
|
||||
| DAC0 | PA4 | 真模拟输出 DAC |
|
||||
| -- | PC7 | I2C1-SDA,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
| -- | PC6 | I2C1-SCL,被RT-Thread的I2C设备框架i2c1总线接管,不可当做普通IO |
|
||||
|
||||
> 注意:
|
||||
>
|
||||
@@ -117,6 +117,10 @@ I2C的引脚都是被RT-Thread I2C设备框架接管的,不需要直接操控
|
||||
|
||||
Arduino的 analogWrite 函数虽为模拟写,但是实际输出的是PWM数字信号,并非真正的模拟信号。这是由于Arduino早期使用的AVR单片机并不支持DAC的功能,因此这个习惯就被保留了下来。但是随着Arduino支持芯片的丰富,部分高级芯片已经内建了DAC(例如Arduino官方板MKR、Zero等),因此Arduino的 analogWrite 函数后续也支持了真模拟输出功能。
|
||||
|
||||
| 特殊功能 | Arduino引脚编号 | STM32引脚编号 |
|
||||
| ------------------------------- | --------------- | ------------- |
|
||||
| 真模拟输出 (True Analog Output) | DAC0 | PA4 |
|
||||
|
||||
在潘多拉板上,使用PA4来当做真模拟输出功能引脚,使用方法为:
|
||||
|
||||
```c
|
||||
@@ -0,0 +1,9 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
inc = [cwd]
|
||||
|
||||
group = DefineGroup('Arduino', src, depend = ['PKG_USING_RTDUINO'], CPPPATH = inc)
|
||||
|
||||
Return('group')
|
||||
+2
-2
@@ -48,7 +48,7 @@ const pin_map_t pin_map_table[]=
|
||||
{D25, GET_PIN(B,1)}, /* INFRARED RECEPTION */
|
||||
{A0, GET_PIN(C,2), "adc1", 3}, /* ADC */
|
||||
{A1, GET_PIN(C,4), "adc1", 13}, /* ADC */
|
||||
{A2, RT_NULL, "adc1", 0}, /* ADC, On-Chip: internal reference voltage */
|
||||
{A3, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal temperature sensor */
|
||||
{A2, RT_NULL, "adc1", 0}, /* ADC, On-Chip: internal reference voltage, ADC_CHANNEL_VREFINT */
|
||||
{A3, RT_NULL, "adc1", 17}, /* ADC, On-Chip: internal temperature sensor, ADC_CHANNEL_TEMPSENSOR */
|
||||
{DAC0, GET_PIN(A,4), "dac1", 1} /* DAC */
|
||||
};
|
||||
@@ -41,6 +41,10 @@ menu "Onboard Peripheral Drivers"
|
||||
select BSP_USING_I2C4
|
||||
select BSP_USING_DAC
|
||||
select BSP_USING_DAC1
|
||||
select BSP_USING_SPI
|
||||
# select BSP_USING_SPI2
|
||||
# select BSP_SPI2_TX_USING_DMA
|
||||
# select BSP_SPI2_RX_USING_DMA
|
||||
imply RTDUINO_USING_SERVO
|
||||
imply RTDUINO_USING_WIRE
|
||||
imply RTDUINO_USING_ADAFRUIT
|
||||
|
||||
Reference in New Issue
Block a user