Skip to content

Commit a98c380

Browse files
committed
[NUCLEO_F401RE] Add INTERRUPT_IN to all pins
1 parent 4e907a0 commit a98c380

File tree

1 file changed

+46
-19
lines changed
  • libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE

1 file changed

+46
-19
lines changed

libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F401RE/gpio_irq_api.c

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@
4040
#define EDGE_FALL (2)
4141
#define EDGE_BOTH (3)
4242

43-
#define CHANNEL_NUM (4)
43+
#define CHANNEL_NUM (7)
4444

45-
static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0};
46-
static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0};
47-
static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0};
45+
static uint32_t channel_ids[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0};
46+
static uint32_t channel_gpio[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0};
47+
static uint32_t channel_pin[CHANNEL_NUM] = {0, 0, 0, 0, 0, 0, 0};
4848

4949
static gpio_irq_handler irq_handler;
5050

5151
static void handle_interrupt_in(uint32_t irq_index) {
5252
// Retrieve the gpio and pin that generate the irq
5353
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
5454
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
55-
55+
5656
// Clear interrupt flag
5757
if (__HAL_GPIO_EXTI_GET_FLAG(pin) != RESET)
5858
{
@@ -71,45 +71,72 @@ static void handle_interrupt_in(uint32_t irq_index) {
7171
}
7272

7373
// The irq_index is passed to the function
74-
static void gpio_irq0(void) {handle_interrupt_in(0);}
75-
static void gpio_irq1(void) {handle_interrupt_in(1);}
76-
static void gpio_irq2(void) {handle_interrupt_in(2);}
77-
static void gpio_irq3(void) {handle_interrupt_in(3);}
74+
static void gpio_irq0(void) {handle_interrupt_in(0);} // EXTI line 0
75+
static void gpio_irq1(void) {handle_interrupt_in(1);} // EXTI line 1
76+
static void gpio_irq2(void) {handle_interrupt_in(2);} // EXTI line 2
77+
static void gpio_irq3(void) {handle_interrupt_in(3);} // EXTI line 3
78+
static void gpio_irq4(void) {handle_interrupt_in(4);} // EXTI line 4
79+
static void gpio_irq5(void) {handle_interrupt_in(5);} // EXTI lines 5 to 9
80+
static void gpio_irq6(void) {handle_interrupt_in(6);} // EXTI lines 10 to 15
7881

7982
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
8083

8184
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id) {
8285
IRQn_Type irq_n = (IRQn_Type)0;
8386
uint32_t vector = 0;
8487
uint32_t irq_index;
85-
88+
8689
if (pin == NC) return -1;
8790

8891
uint32_t port_index = STM_PORT(pin);
8992
uint32_t pin_index = STM_PIN(pin);
9093

9194
// Select irq number and interrupt routine
92-
switch (pin) {
93-
case PC_13: // User button
94-
irq_n = EXTI15_10_IRQn;
95+
switch (pin_index) {
96+
case 0:
97+
irq_n = EXTI0_IRQn;
9598
vector = (uint32_t)&gpio_irq0;
9699
irq_index = 0;
97100
break;
98-
case PB_3:
99-
irq_n = EXTI3_IRQn;
101+
case 1:
102+
irq_n = EXTI1_IRQn;
100103
vector = (uint32_t)&gpio_irq1;
101104
irq_index = 1;
102105
break;
103-
case PB_4:
104-
irq_n = EXTI4_IRQn;
106+
case 2:
107+
irq_n = EXTI2_IRQn;
105108
vector = (uint32_t)&gpio_irq2;
106109
irq_index = 2;
107110
break;
108-
case PB_5:
109-
irq_n = EXTI9_5_IRQn;
111+
case 3:
112+
irq_n = EXTI3_IRQn;
110113
vector = (uint32_t)&gpio_irq3;
111114
irq_index = 3;
112115
break;
116+
case 4:
117+
irq_n = EXTI4_IRQn;
118+
vector = (uint32_t)&gpio_irq4;
119+
irq_index = 4;
120+
break;
121+
case 5:
122+
case 6:
123+
case 7:
124+
case 8:
125+
case 9:
126+
irq_n = EXTI9_5_IRQn;
127+
vector = (uint32_t)&gpio_irq5;
128+
irq_index = 5;
129+
break;
130+
case 10:
131+
case 11:
132+
case 12:
133+
case 13:
134+
case 14:
135+
case 15:
136+
irq_n = EXTI15_10_IRQn;
137+
vector = (uint32_t)&gpio_irq6;
138+
irq_index = 6;
139+
break;
113140
default:
114141
error("InterruptIn error: pin not supported.\n");
115142
return -1;

0 commit comments

Comments
 (0)