Skip to content

Commit 9ee5940

Browse files
authored
[arduino][stm32l475 pandora] fullly support analog output(PWM) and analog input(ADC) (#5690)
1 parent 4e1b175 commit 9ee5940

File tree

14 files changed

+257
-150
lines changed

14 files changed

+257
-150
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static void stm32_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
279279

280280
rt_inline rt_int32_t bit2bitno(rt_uint32_t bit)
281281
{
282-
int i;
282+
rt_uint8_t i;
283283
for (i = 0; i < 32; i++)
284284
{
285285
if ((0x01 << i) == bit)

bsp/stm32/stm32f072-st-nucleo/applications/arduino/pins_arduino.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,37 @@
1111
#include <board.h>
1212
#include "pins_arduino.h"
1313

14+
/*
15+
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
16+
[] means optional
17+
Digital pins must NOT give the device name and channel.
18+
Analog pins MUST give the device name and channel(ADC or PWM).
19+
Arduino Pin must keep in sequence.
20+
*/
1421
const pin_map_t pin_map_table[]=
1522
{
16-
/*
17-
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
18-
[] means optional
19-
Digital pins must NOT give the device name and channel.
20-
Analog pins MUST give the device name and channel(ADC or PWM).
21-
*/
22-
{0, GET_PIN(A,3)}, /* D0, RX */
23-
{1, GET_PIN(A,2)}, /* D1, TX */
24-
{2, GET_PIN(A,10)}, /* D2 */
25-
{3, GET_PIN(B,3), "pwm2", 2}, /* D3, PWM */
26-
{4, GET_PIN(B,5)}, /* D4 */
27-
{5, GET_PIN(B,4), "pwm3", 1}, /* D5, PWM */
28-
{6, GET_PIN(B,10), "pwm2", 3}, /* D6, PWM */
29-
{7, GET_PIN(A,8)}, /* D7 */
30-
{8, GET_PIN(A,9)}, /* D8 */
31-
{9, GET_PIN(C,7), "pwm3", 2}, /* D9, PWM */
32-
{10, GET_PIN(B,6)}, /* D10 */
33-
{11, GET_PIN(A,7)}, /* D11 */
34-
{12, GET_PIN(A,6)}, /* D12 */
35-
{13, GET_PIN(A,5)}, /* D13 */
36-
{14, GET_PIN(B,9)}, /* D14 */
37-
{15, GET_PIN(B,8)}, /* D15 */
38-
{16, GET_PIN(A,0), "adc1", 0}, /* A0 */
39-
{17, GET_PIN(A,1), "adc1", 1}, /* A1 */
40-
{18, GET_PIN(A,4), "adc1", 4}, /* A2 */
41-
{19, GET_PIN(B,0), "adc1", 8}, /* A3 */
42-
{20, GET_PIN(C,1), "adc1", 11}, /* A4 */
43-
{21, GET_PIN(C,0), "adc1", 10} /* A5 */
23+
{D0, GET_PIN(A,3)}, /* RX */
24+
{D1, GET_PIN(A,2)}, /* TX */
25+
{D2, GET_PIN(A,10)},
26+
{D3, GET_PIN(B,3), "pwm2", 2}, /* PWM */
27+
{D4, GET_PIN(B,5)}, /* D4 */
28+
{D5, GET_PIN(B,4), "pwm3", 1}, /* PWM */
29+
{D6, GET_PIN(B,10), "pwm2", 3}, /* PWM */
30+
{D7, GET_PIN(A,8)},
31+
{D8, GET_PIN(A,9)},
32+
{D9, GET_PIN(C,7), "pwm3", 2}, /* PWM */
33+
{D10, GET_PIN(B,6)},
34+
{D11, GET_PIN(A,7)},
35+
{D12, GET_PIN(A,6)},
36+
{D13, GET_PIN(A,5)},
37+
{D14, GET_PIN(B,9)},
38+
{D15, GET_PIN(B,8)},
39+
{A0, GET_PIN(A,0), "adc1", 0},
40+
{A1, GET_PIN(A,1), "adc1", 1},
41+
{A2, GET_PIN(A,4), "adc1", 4},
42+
{A3, GET_PIN(B,0), "adc1", 8},
43+
{A4, GET_PIN(C,1), "adc1", 11},
44+
{A5, GET_PIN(C,0), "adc1", 10}
4445
};
4546

4647
/* initialization for BSP; maybe a blank function */

bsp/stm32/stm32f072-st-nucleo/applications/arduino/pins_arduino.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@
1010
#ifndef Pins_Arduino_h
1111
#define Pins_Arduino_h
1212

13-
#define LED_BUILTIN 13 /* Built-in LED */
14-
15-
#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
16-
17-
#define ARDUINO_PINOUT_ADC_MAX 6 /* Arduino UNO has 6 ADC pins */
18-
#define ARDUINO_PINOUT_PWM_MAX 5 /* Arduino UNO has 5 PWM pins */
19-
20-
#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
21-
22-
/* pins alias */
13+
/* pins alias. Must keep in sequence */
2314
#define D0 (0)
2415
#define D1 (1)
2516
#define D2 (2)
@@ -43,4 +34,11 @@
4334
#define A4 (20)
4435
#define A5 (21)
4536

37+
#define LED_BUILTIN D13 /* Built-in LED */
38+
39+
#define ARDUINO_PINOUT_PWM_MAX 5 /* This Arduino variant has 5 PWM pins */
40+
#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
41+
42+
#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
43+
4644
#endif /* Pins_Arduino_h */

bsp/stm32/stm32l475-atk-pandora/applications/arduino/pins_arduino.c

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -11,34 +11,45 @@
1111
#include <board.h>
1212
#include "pins_arduino.h"
1313

14+
/*
15+
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
16+
[] means optional
17+
Digital pins must NOT give the device name and channel.
18+
Analog pins MUST give the device name and channel(ADC or PWM).
19+
Arduino Pin must keep in sequence.
20+
*/
1421
const pin_map_t pin_map_table[]=
1522
{
16-
/*
17-
{Arduino Pin, RT-Thread Pin [, Device Name(PWM or ADC), Channel]}
18-
[] means optional
19-
Digital pins must NOT give the device name and channel.
20-
Analog pins MUST give the device name and channel(ADC or PWM).
21-
*/
22-
{0}, /* D0, RX */
23-
{1}, /* D1, TX */
24-
{2, GET_PIN(D,10)}, /* D2, BSP:KEY0 */
25-
{3}, /* D3, PWM */
26-
{4, GET_PIN(D,9)}, /* D4, BSP:KEY1 */
27-
{5, GET_PIN(D,8)}, /* D5, BSP:KEY2 */
28-
{6}, /* D6, PWM */
29-
{7}, /* D7 */
30-
{8, GET_PIN(E,7)}, /* D8, BSP: RED-LED */
31-
{9}, /* D9, PWM */
32-
{10, GET_PIN(E,9), "pwm1", 1}, /* D10, PWM, BSP: BLUE-LED */
33-
{11, GET_PIN(B,8), "pwm4", 3}, /* D11, PWM */
34-
{12, GET_PIN(B,2)}, /* D12, BSP: BEEP */
35-
{13, GET_PIN(E,8)}, /* D13, LED_BUILTIN, BSP: GREEN-LED */
36-
{14, GET_PIN(C,2), "adc1", 3}, /* D14, A0 */
37-
{15}, /* A1 */
38-
{16}, /* A2 */
39-
{17}, /* A3 */
40-
{18}, /* A4 */
41-
{19} /* A5 */
23+
{D0}, /* RX */
24+
{D1}, /* TX */
25+
{D2, GET_PIN(B,9)},
26+
{D3, GET_PIN(D,15), "pwm4", 4}, /* PWM */
27+
{D4, GET_PIN(A,8)},
28+
{D5, GET_PIN(D,14)},
29+
{D6, GET_PIN(B,11), "pwm2", 4}, /* PWM */
30+
{D7, GET_PIN(B,14)},
31+
{D8, GET_PIN(B,12)},
32+
{D9, GET_PIN(D,12), "pwm4", 1}, /* PWM */
33+
{D10, GET_PIN(B,10), "pwm2", 3}, /* PWM */
34+
{D11, GET_PIN(B,8), "pwm4", 3}, /* PWM */
35+
{D12, GET_PIN(B,15)},
36+
{D13, GET_PIN(B,13)},
37+
{D14, GET_PIN(A,1)}, /* BSP: MOTOR-A */
38+
{D15, GET_PIN(A,0)}, /* BSP: MOTOR-B */
39+
{D16, GET_PIN(B,2)}, /* BSP: BEEP */
40+
{D17, GET_PIN(D,10)}, /* BSP: KEY0 */
41+
{D18, GET_PIN(D,9)}, /* BSP: KEY1 */
42+
{D19, GET_PIN(D,8)}, /* BSP: KEY2 */
43+
{D20, GET_PIN(C,13)}, /* BSP: KEY-WKUP */
44+
{D21, GET_PIN(E,7)}, /* BSP: RED-LED */
45+
{D22, GET_PIN(E,8)}, /* LED_BUILTIN, BSP: GREEN-LED */
46+
{D23, GET_PIN(E,9), "pwm1", 1}, /* PWM, BSP: BLUE-LED */
47+
{A0, GET_PIN(C,2), "adc1", 3},
48+
{A1, GET_PIN(C,4), "adc1", 13},
49+
{A2},
50+
{A3},
51+
{A4},
52+
{A5}
4253
};
4354

4455
/* initialization for BSP; maybe a blank function */
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2021, RT-Thread Development Team
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -10,15 +10,7 @@
1010
#ifndef Pins_Arduino_h
1111
#define Pins_Arduino_h
1212

13-
#define LED_BUILTIN 13 /* Built-in LED */
14-
15-
#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
16-
17-
#define ARDUINO_PINOUT_ADC_MAX 6 /* Arduino UNO has 6 ADC pins */
18-
#define ARDUINO_PINOUT_PWM_MAX 5 /* Arduino UNO has 5 PWM pins */
19-
20-
#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
21-
13+
/* pins alias. Must keep in sequence */
2214
#define D0 (0)
2315
#define D1 (1)
2416
#define D2 (2)
@@ -33,11 +25,28 @@
3325
#define D11 (11)
3426
#define D12 (12)
3527
#define D13 (13)
36-
#define A0 (14)
37-
#define A1 (15)
38-
#define A2 (16)
39-
#define A3 (17)
40-
#define A4 (18)
41-
#define A5 (19)
28+
#define D14 (14)
29+
#define D15 (15)
30+
#define D16 (16)
31+
#define D17 (17)
32+
#define D18 (18)
33+
#define D19 (19)
34+
#define D20 (20)
35+
#define D21 (21)
36+
#define D22 (22)
37+
#define D23 (23)
38+
#define A0 (24)
39+
#define A1 (25)
40+
#define A2 (26)
41+
#define A3 (27)
42+
#define A4 (28)
43+
#define A5 (29)
44+
45+
#define LED_BUILTIN D22 /* Built-in LED */
46+
47+
#define ARDUINO_PINOUT_PWM_MAX 6 /* This Arduino variant has 6 PWM pins */
48+
#define ARDUINO_PWM_HZ 500 /* Arduino UNO's PWM is around 500Hz */
49+
50+
#define ARDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
4251

4352
#endif /* Pins_Arduino_h */

0 commit comments

Comments
 (0)