Skip to content

Commit 01a6563

Browse files
authored
[stm32l475][arduino] 初步实现Arduino生态兼容 (#5367)
* [arduino] 初步实现Arduino生态兼容组件 * [stm32f475] 增加PC2 作为ADC1_IN3 * [stm32l475][port] 将路径Arduino改为arduino
1 parent 84ebf38 commit 01a6563

File tree

11 files changed

+218
-72
lines changed

11 files changed

+218
-72
lines changed

bsp/stm32/stm32l475-atk-pandora/applications/SConscript

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import os
33

44
cwd = GetCurrentDir()
55

6-
src = Split('''
7-
main.c
8-
''')
6+
src = ['main.c']
97

108
if GetDepend(['PKG_USING_NRF24L01']):
11-
src += Glob('nrf24l01_init.c')
9+
src += ['nrf24l01_init.c']
10+
11+
if GetDepend(['RT_USING_ARDUINO']):
12+
src += ['arduino_main.cpp']
1213

1314
CPPPATH = [cwd]
1415

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-12-10 Meco Man first version
9+
*/
10+
#include <Arduino.h>
11+
12+
void setup(void)
13+
{
14+
// put your setup code here, to run once:
15+
pinMode(LED_BUILTIN, OUTPUT);
16+
}
17+
18+
void loop(void)
19+
{
20+
// put your main code here, to run repeatedly:
21+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
22+
delay(200);
23+
}

bsp/stm32/stm32l475-atk-pandora/applications/nrf24l01_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2018, RT-Thread Development Team
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# files format check exclude path, please follow the instructions below to modify;
2+
# If you need to exclude an entire folder, add the folder path in dir_path;
3+
# If you need to exclude a file, add the path to the file in file_path.
4+
5+
dir_path:
6+
- CubeMX_Config

bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/STM32L475VE.ioc

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,66 +37,67 @@ Mcu.Name=STM32L475V(C-E-G)Tx
3737
Mcu.Package=LQFP100
3838
Mcu.Pin0=PE2
3939
Mcu.Pin1=PE3
40-
Mcu.Pin10=PA3
41-
Mcu.Pin11=PA4
42-
Mcu.Pin12=PA5
43-
Mcu.Pin13=PA6
44-
Mcu.Pin14=PA7
45-
Mcu.Pin15=PC5
46-
Mcu.Pin16=PE9
47-
Mcu.Pin17=PE10
48-
Mcu.Pin18=PE11
49-
Mcu.Pin19=PE12
40+
Mcu.Pin10=PA2
41+
Mcu.Pin11=PA3
42+
Mcu.Pin12=PA4
43+
Mcu.Pin13=PA5
44+
Mcu.Pin14=PA6
45+
Mcu.Pin15=PA7
46+
Mcu.Pin16=PC5
47+
Mcu.Pin17=PE9
48+
Mcu.Pin18=PE10
49+
Mcu.Pin19=PE11
5050
Mcu.Pin2=PE4
51-
Mcu.Pin20=PE13
52-
Mcu.Pin21=PE14
53-
Mcu.Pin22=PE15
54-
Mcu.Pin23=PB10
55-
Mcu.Pin24=PB11
56-
Mcu.Pin25=PB13
57-
Mcu.Pin26=PB14
58-
Mcu.Pin27=PB15
59-
Mcu.Pin28=PC8
60-
Mcu.Pin29=PC9
51+
Mcu.Pin20=PE12
52+
Mcu.Pin21=PE13
53+
Mcu.Pin22=PE14
54+
Mcu.Pin23=PE15
55+
Mcu.Pin24=PB10
56+
Mcu.Pin25=PB11
57+
Mcu.Pin26=PB13
58+
Mcu.Pin27=PB14
59+
Mcu.Pin28=PB15
60+
Mcu.Pin29=PC8
6161
Mcu.Pin3=PE5
62-
Mcu.Pin30=PA9
63-
Mcu.Pin31=PA10
64-
Mcu.Pin32=PA11
65-
Mcu.Pin33=PA12
66-
Mcu.Pin34=PA13 (JTMS-SWDIO)
67-
Mcu.Pin35=PA14 (JTCK-SWCLK)
68-
Mcu.Pin36=PC10
69-
Mcu.Pin37=PC11
70-
Mcu.Pin38=PC12
71-
Mcu.Pin39=PD2
62+
Mcu.Pin30=PC9
63+
Mcu.Pin31=PA9
64+
Mcu.Pin32=PA10
65+
Mcu.Pin33=PA11
66+
Mcu.Pin34=PA12
67+
Mcu.Pin35=PA13 (JTMS-SWDIO)
68+
Mcu.Pin36=PA14 (JTCK-SWCLK)
69+
Mcu.Pin37=PC10
70+
Mcu.Pin38=PC11
71+
Mcu.Pin39=PC12
7272
Mcu.Pin4=PE6
73-
Mcu.Pin40=PB3 (JTDO-TRACESWO)
74-
Mcu.Pin41=PB5
75-
Mcu.Pin42=PB7
76-
Mcu.Pin43=PB8
77-
Mcu.Pin44=VP_IWDG_VS_IWDG
78-
Mcu.Pin45=VP_LPTIM1_VS_LPTIM_counterModeInternalClock
79-
Mcu.Pin46=VP_RTC_VS_RTC_Activate
80-
Mcu.Pin47=VP_SAI1_VP_$IpInstance_SAIA_SAI_BASIC
81-
Mcu.Pin48=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
82-
Mcu.Pin49=VP_SYS_VS_Systick
73+
Mcu.Pin40=PD2
74+
Mcu.Pin41=PB3 (JTDO-TRACESWO)
75+
Mcu.Pin42=PB5
76+
Mcu.Pin43=PB7
77+
Mcu.Pin44=PB8
78+
Mcu.Pin45=VP_IWDG_VS_IWDG
79+
Mcu.Pin46=VP_LPTIM1_VS_LPTIM_counterModeInternalClock
80+
Mcu.Pin47=VP_RTC_VS_RTC_Activate
81+
Mcu.Pin48=VP_SAI1_VP_$IpInstance_SAIA_SAI_BASIC
82+
Mcu.Pin49=VP_SAI1_VP_$IpInstance_SAIB_SAI_BASIC
8383
Mcu.Pin5=PC14-OSC32_IN (PC14)
84-
Mcu.Pin50=VP_TIM1_VS_ClockSourceINT
85-
Mcu.Pin51=VP_TIM2_VS_ClockSourceINT
86-
Mcu.Pin52=VP_TIM4_VS_ClockSourceINT
87-
Mcu.Pin53=VP_TIM15_VS_ClockSourceINT
88-
Mcu.Pin54=VP_TIM16_VS_ClockSourceINT
89-
Mcu.Pin55=VP_TIM17_VS_ClockSourceINT
84+
Mcu.Pin50=VP_SYS_VS_Systick
85+
Mcu.Pin51=VP_TIM1_VS_ClockSourceINT
86+
Mcu.Pin52=VP_TIM2_VS_ClockSourceINT
87+
Mcu.Pin53=VP_TIM4_VS_ClockSourceINT
88+
Mcu.Pin54=VP_TIM15_VS_ClockSourceINT
89+
Mcu.Pin55=VP_TIM16_VS_ClockSourceINT
90+
Mcu.Pin56=VP_TIM17_VS_ClockSourceINT
9091
Mcu.Pin6=PC15-OSC32_OUT (PC15)
9192
Mcu.Pin7=PH0-OSC_IN (PH0)
9293
Mcu.Pin8=PH1-OSC_OUT (PH1)
93-
Mcu.Pin9=PA2
94-
Mcu.PinsNb=56
94+
Mcu.Pin9=PC2
95+
Mcu.PinsNb=57
9596
Mcu.ThirdPartyNb=0
9697
Mcu.UserConstants=
9798
Mcu.UserName=STM32L475VETx
98-
MxCube.Version=6.2.1
99-
MxDb.Version=DB.6.0.21
99+
MxCube.Version=6.4.0
100+
MxDb.Version=DB.6.0.40
100101
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
101102
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
102103
NVIC.ForceEnableDMAVector=true
@@ -171,6 +172,8 @@ PC14-OSC32_IN\ (PC14).Mode=LSE-External-Oscillator
171172
PC14-OSC32_IN\ (PC14).Signal=RCC_OSC32_IN
172173
PC15-OSC32_OUT\ (PC15).Mode=LSE-External-Oscillator
173174
PC15-OSC32_OUT\ (PC15).Signal=RCC_OSC32_OUT
175+
PC2.Locked=true
176+
PC2.Signal=ADCx_IN3
174177
PC5.Signal=ADCx_IN14
175178
PC8.Mode=SD_4_bits_Wide_bus
176179
PC8.Signal=SDMMC1_D0
@@ -309,6 +312,8 @@ SAI1.VirtualProtocol-SAI_A_BASIC=VM_BASIC_PROTOCOL
309312
SAI1.VirtualProtocol-SAI_B_BASIC=VM_BASIC_PROTOCOL
310313
SH.ADCx_IN14.0=ADC1_IN14,IN14-Single-Ended
311314
SH.ADCx_IN14.ConfNb=1
315+
SH.ADCx_IN3.0=ADC1_IN3,IN3-Single-Ended
316+
SH.ADCx_IN3.ConfNb=1
312317
SH.COMP_DAC11_group.0=DAC1_OUT1,DAC_OUT1
313318
SH.COMP_DAC11_group.ConfNb=1
314319
SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1

bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Src/main.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ PCD_HandleTypeDef hpcd_USB_OTG_FS;
101101

102102
/* Private function prototypes -----------------------------------------------*/
103103
void SystemClock_Config(void);
104+
void PeriphCommonClock_Config(void);
104105
static void MX_GPIO_Init(void);
105106
static void MX_USART1_UART_Init(void);
106107
static void MX_USART2_UART_Init(void);
@@ -154,6 +155,9 @@ int main(void)
154155
/* Configure the system clock */
155156
SystemClock_Config();
156157

158+
/* Configure the peripherals common clocks */
159+
PeriphCommonClock_Config();
160+
157161
/* USER CODE BEGIN SysInit */
158162

159163
/* USER CODE END SysInit */
@@ -205,8 +209,13 @@ void SystemClock_Config(void)
205209
{
206210
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
207211
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
208-
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
209212

213+
/** Configure the main internal regulator output voltage
214+
*/
215+
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
216+
{
217+
Error_Handler();
218+
}
210219
/** Configure LSE Drive Capability
211220
*/
212221
HAL_PWR_EnableBkUpAccess();
@@ -243,16 +252,22 @@ void SystemClock_Config(void)
243252
{
244253
Error_Handler();
245254
}
246-
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
247-
|RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_LPTIM1
248-
|RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_USB
255+
}
256+
257+
/**
258+
* @brief Peripherals Common Clock Configuration
259+
* @retval None
260+
*/
261+
void PeriphCommonClock_Config(void)
262+
{
263+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
264+
265+
/** Initializes the peripherals clock
266+
*/
267+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SAI1|RCC_PERIPHCLK_USB
249268
|RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_ADC;
250-
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
251-
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
252-
PeriphClkInit.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_PCLK;
253269
PeriphClkInit.Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLLSAI1;
254270
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
255-
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
256271
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
257272
PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLSAI1;
258273
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_HSE;
@@ -267,12 +282,6 @@ void SystemClock_Config(void)
267282
{
268283
Error_Handler();
269284
}
270-
/** Configure the main internal regulator output voltage
271-
*/
272-
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
273-
{
274-
Error_Handler();
275-
}
276285
}
277286

278287
/**
@@ -1190,4 +1199,3 @@ void assert_failed(uint8_t *file, uint32_t line)
11901199
}
11911200
#endif /* USE_FULL_ASSERT */
11921201

1193-
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

bsp/stm32/stm32l475-atk-pandora/board/CubeMX_Config/Src/stm32l4xx_hal_msp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
118118

119119
__HAL_RCC_GPIOC_CLK_ENABLE();
120120
/**ADC1 GPIO Configuration
121+
PC2 ------> ADC1_IN3
121122
PC5 ------> ADC1_IN14
122123
*/
123-
GPIO_InitStruct.Pin = GPIO_PIN_5;
124+
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_5;
124125
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
125126
GPIO_InitStruct.Pull = GPIO_NOPULL;
126127
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
@@ -149,9 +150,10 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
149150
__HAL_RCC_ADC_CLK_DISABLE();
150151

151152
/**ADC1 GPIO Configuration
153+
PC2 ------> ADC1_IN3
152154
PC5 ------> ADC1_IN14
153155
*/
154-
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_5);
156+
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_5);
155157

156158
/* USER CODE BEGIN ADC1_MspDeInit 1 */
157159

bsp/stm32/stm32l475-atk-pandora/board/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ menu "Onboard Peripheral Drivers"
1515
select BSP_USING_UART1
1616
default y
1717

18+
config BSP_USING_ARDUINO_UNO
19+
bool "Support Arduino UNO"
20+
select RT_USING_ARDUINO
21+
select RT_USING_ARDUINO_UNO_LAYOUT
22+
select BSP_USING_PWM
23+
select BSP_USING_PWM1
24+
select BSP_USING_PWM1_CH1
25+
select BSP_USING_PWM4
26+
select BSP_USING_PWM4_CH3
27+
select BSP_USING_ADC
28+
select BSP_USING_ADC1
29+
default n
30+
1831
config BSP_USING_KEY
1932
bool "Enable onboard keys"
2033
select RT_USING_PIN
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = []
5+
inc = [cwd]
6+
7+
if GetDepend('RT_USING_ARDUINO_UNO_LAYOUT'):
8+
src += ['arduino_layout.c']
9+
10+
group = DefineGroup('Arduino', src, depend = ['RT_USING_ARDUINO'], CPPPATH = inc)
11+
12+
Return('group')
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-12-10 Meco Man first version
9+
*/
10+
#include <Arduino.h>
11+
#include <board.h>
12+
13+
const pin_map_t pin_map_table[ARDUINO_LAYOUT_PIN_MAX]=
14+
{
15+
/*
16+
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
17+
[] means optional
18+
Digital pins must NOT give the device name and channel.
19+
Analog pins MUST give the device name and channel(ADC or PWM).
20+
*/
21+
{0}, /* D0, RX */
22+
{1}, /* D1, TX */
23+
{2, GET_PIN(D,10)}, /* D2, BSP:KEY0 */
24+
{3}, /* D3, PWM */
25+
{4, GET_PIN(D,9)}, /* D4, BSP:KEY1 */
26+
{5, GET_PIN(D,8)}, /* D5, BSP:KEY2 */
27+
{6}, /* D6, PWM */
28+
{7}, /* D7 */
29+
{8, GET_PIN(E,7)}, /* D8, BSP: RED-LED */
30+
{9}, /* D9, PWM */
31+
{10, GET_PIN(E,9), "pwm1", 1}, /* D10, PWM, BSP: BLUE-LED */
32+
{11, GET_PIN(B,8), "pwm4", 3}, /* D11, PWM */
33+
{12, GET_PIN(B,2)}, /* D12, BSP: BEEP */
34+
{13, GET_PIN(E,8)}, /* D13, LED_BUILTIN, BSP: GREEN-LED */
35+
{14, GET_PIN(C,2), "adc1", 3}, /* D14, A0 */
36+
{15}, /* D15, A1 */
37+
{16}, /* D16, A2 */
38+
{17}, /* D17, A3 */
39+
{18}, /* D18, A4 */
40+
{19} /* D19, A5 */
41+
};
42+
43+
/* initialization for BSP; maybe a blank function */
44+
void initVariant(void)
45+
{
46+
/* Nothing needs to initialize for this BSP */
47+
}

0 commit comments

Comments
 (0)