Skip to content

Commit 7eeb731

Browse files
committed
get_GPIO_Port return NULL if wrong PortName
This will cause hard fault if used so check if NC can be removed Signed-off-by: Frederic.Pillon <[email protected]>
1 parent cd7979d commit 7eeb731

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

cores/arduino/stm32/PortNames.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ typedef enum {
7676
#define MAX_NB_PORT (LastPort-FirstPort+1)
7777

7878
/* Return GPIO base address */
79-
#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)GPIOA_BASE)
79+
#define get_GPIO_Port(p) ((p < MAX_NB_PORT) ? GPIOPort[p] : (GPIO_TypeDef *)NULL)
8080
/* Enable GPIO clock and return GPIO base address */
8181
GPIO_TypeDef *set_GPIO_Port_Clock(uint32_t port_idx);
8282

cores/arduino/stm32/digital_io.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ static inline void digital_io_toggle(GPIO_TypeDef *port, uint32_t pin)
9494
*/
9595
static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
9696
{
97-
if (pn != NC) {
98-
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal);
99-
}
97+
digital_io_write(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn), ulVal);
10098
}
10199

102100
/**
@@ -107,9 +105,7 @@ static inline void digitalWriteFast(PinName pn, uint32_t ulVal)
107105
static inline int digitalReadFast(PinName pn)
108106
{
109107
uint8_t level = 0;
110-
if (pn != NC) {
111-
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
112-
}
108+
level = digital_io_read(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
113109
return (level) ? HIGH : LOW;
114110
}
115111

@@ -121,9 +117,7 @@ static inline int digitalReadFast(PinName pn)
121117
*/
122118
static inline void digitalToggleFast(PinName pn)
123119
{
124-
if (pn != NC) {
125-
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
126-
}
120+
digital_io_toggle(get_GPIO_Port(STM_PORT(pn)), STM_GPIO_PIN(pn));
127121
}
128122

129123
#ifdef __cplusplus

0 commit comments

Comments
 (0)