Skip to content

Commit fa40ba6

Browse files
committed
Enhance get_GPIO_Port speed
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 199358d commit fa40ba6

File tree

2 files changed

+19
-49
lines changed

2 files changed

+19
-49
lines changed

cores/arduino/stm32/PortNames.c

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,73 +28,40 @@
2828
*******************************************************************************
2929
*/
3030
#include "PortNames.h"
31-
#include "stm32_def.h"
3231

33-
// Return GPIO base address
34-
GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx) {
35-
GPIO_TypeDef* gpioPort = 0;
36-
switch (port_idx) {
37-
case PortA:
38-
gpioPort = (GPIO_TypeDef *)GPIOA_BASE;
39-
break;
40-
case PortB:
41-
gpioPort = (GPIO_TypeDef *)GPIOB_BASE;
42-
break;
32+
GPIO_TypeDef * GPIOPort[MAX_NB_PORT] = {
33+
(GPIO_TypeDef *)GPIOA_BASE,
34+
(GPIO_TypeDef *)GPIOB_BASE
4335
#if defined GPIOC_BASE
44-
case PortC:
45-
gpioPort = (GPIO_TypeDef *)GPIOC_BASE;
46-
break;
36+
,(GPIO_TypeDef *)GPIOC_BASE
4737
#endif
4838
#if defined GPIOD_BASE
49-
case PortD:
50-
gpioPort = (GPIO_TypeDef *)GPIOD_BASE;
51-
break;
39+
,(GPIO_TypeDef *)GPIOD_BASE
5240
#endif
5341
#if defined GPIOE_BASE
54-
case PortE:
55-
gpioPort = (GPIO_TypeDef *)GPIOE_BASE;
56-
break;
42+
,(GPIO_TypeDef *)GPIOE_BASE
5743
#endif
5844
#if defined GPIOF_BASE
59-
case PortF:
60-
gpioPort = (GPIO_TypeDef *)GPIOF_BASE;
61-
break;
45+
,(GPIO_TypeDef *)GPIOF_BASE
6246
#endif
6347
#if defined GPIOG_BASE
64-
case PortG:
65-
gpioPort = (GPIO_TypeDef *)GPIOG_BASE;
66-
break;
48+
,(GPIO_TypeDef *)GPIOG_BASE
6749
#endif
6850
#if defined GPIOH_BASE
69-
case PortH:
70-
gpioPort = (GPIO_TypeDef *)GPIOH_BASE;
71-
break;
51+
,(GPIO_TypeDef *)GPIOH_BASE
7252
#endif
7353
#if defined GPIOI_BASE
74-
case PortI:
75-
gpioPort = (GPIO_TypeDef *)GPIOI_BASE;
76-
break;
54+
,(GPIO_TypeDef *)GPIOI_BASE
7755
#endif
7856
#if defined GPIOJ_BASE
79-
case PortJ:
80-
gpioPort = (GPIO_TypeDef *)GPIOJ_BASE;
81-
break;
57+
,(GPIO_TypeDef *)GPIOJ_BASE
8258
#endif
8359
#if defined GPIOK_BASE
84-
case PortK:
85-
gpioPort = (GPIO_TypeDef *)GPIOK_BASE;
86-
break;
60+
,(GPIO_TypeDef *)GPIOK_BASE
8761
#endif
88-
default:
89-
// wrong port number
90-
//TBD: error management
91-
gpioPort = 0;
92-
break;
93-
}
94-
return gpioPort;
95-
}
62+
};
9663

97-
// Enable GPIO clock and return GPIO base address
64+
/* Enable GPIO clock and return GPIO base address */
9865
GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
9966
GPIO_TypeDef* gpioPort = 0;
10067
switch (port_idx) {
@@ -173,4 +140,3 @@ GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx) {
173140
}
174141
return gpioPort;
175142
}
176-

cores/arduino/stm32/PortNames.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
extern "C" {
3737
#endif
3838

39+
extern GPIO_TypeDef *GPIOPort[];
40+
3941
typedef enum {
4042
FirstPort = 0x00,
4143
PortA = FirstPort,
@@ -73,7 +75,9 @@ typedef enum {
7375

7476
#define MAX_NB_PORT (LastPort-FirstPort+1)
7577

76-
GPIO_TypeDef *get_GPIO_Port(uint32_t port_idx);
78+
/* Return GPIO base address */
79+
#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)GPIOA_BASE)
80+
/* Enable GPIO clock and return GPIO base address */
7781
GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx);
7882

7983
#ifdef __cplusplus

0 commit comments

Comments
 (0)