Skip to content

Commit a97e0db

Browse files
committed
Map LL GPIO pin definition to STM_PIN
For F1 LL_GPIO_PIN_X is not the same than GPIO_PIN_X Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 7eeb731 commit a97e0db

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

cores/arduino/stm32/digital_io.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
/* Includes ------------------------------------------------------------------*/
4040
#include "wiring_constants.h"
4141
#include "PinNames.h"
42+
#include "pinmap.h"
4243
#include "stm32yyxx_ll_gpio.h"
4344

4445
#ifdef __cplusplus
@@ -94,7 +95,7 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin)
9495
*/
9596
static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
9697
{
97-
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal);
98+
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn), ulVal);
9899
}
99100

100101
/**
@@ -105,7 +106,7 @@ static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
105106
static inline int digitalReadFast(PinName pn)
106107
{
107108
uint8_t level = 0;
108-
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
109+
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn));
109110
return (level) ? HIGH : LOW;
110111
}
111112

@@ -117,7 +118,7 @@ static inline int digitalReadFast(PinName pn)
117118
*/
118119
static inline void digitalToggleFast(PinName pn)
119120
{
120-
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
121+
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_LL_GPIO_PIN(pn));
121122
}
122123

123124
#ifdef __cplusplus

cores/arduino/stm32/pinmap.c

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@
1616
//Based on mbed-os/hal/mbed_pinmap_common.c
1717

1818
#include "pinmap.h"
19+
#include "stm32yyxx_ll_gpio.h"
20+
21+
/* Map STM_PIN to LL */
22+
const uint32_t pin_map_ll[16] = {
23+
LL_GPIO_PIN_0,
24+
LL_GPIO_PIN_1,
25+
LL_GPIO_PIN_2,
26+
LL_GPIO_PIN_3,
27+
LL_GPIO_PIN_4,
28+
LL_GPIO_PIN_5,
29+
LL_GPIO_PIN_6,
30+
LL_GPIO_PIN_7,
31+
LL_GPIO_PIN_8,
32+
LL_GPIO_PIN_9,
33+
LL_GPIO_PIN_10,
34+
LL_GPIO_PIN_11,
35+
LL_GPIO_PIN_12,
36+
LL_GPIO_PIN_13,
37+
LL_GPIO_PIN_14,
38+
LL_GPIO_PIN_15
39+
};
1940

2041
void* pinmap_find_peripheral(PinName pin, const PinMap* map) {
2142
while (map->pin != NC) {

cores/arduino/stm32/pinmap.h

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
extern "C" {
2828
#endif
2929

30+
extern const uint32_t pin_map_ll[16];
31+
32+
#define STM_LL_GPIO_PIN(X) (pin_map_ll[STM_PIN(X)])
33+
3034
// No peripheral
3135
#define NP 0U
3236

0 commit comments

Comments
 (0)