Skip to content

Commit cdcd8f4

Browse files
committed
Update gpio_irq_api.c
More irq's and user button bugfix copied from NUCLEO_F103RB commit ab7cc12 by bcostm
1 parent 6b044ad commit cdcd8f4

File tree

1 file changed

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

1 file changed

+46
-19
lines changed

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

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

42-
#define CHANNEL_NUM (4)
42+
#define CHANNEL_NUM (7)
4343

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

4848
static gpio_irq_handler irq_handler;
4949

5050
static void handle_interrupt_in(uint32_t irq_index) {
5151
// Retrieve the gpio and pin that generate the irq
5252
GPIO_TypeDef *gpio = (GPIO_TypeDef *)(channel_gpio[irq_index]);
5353
uint32_t pin = (uint32_t)(1 << channel_pin[irq_index]);
54-
54+
5555
// Clear interrupt flag
5656
if (EXTI_GetITStatus(pin) != RESET)
5757
{
@@ -70,10 +70,13 @@ static void handle_interrupt_in(uint32_t irq_index) {
7070
}
7171

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

7881
extern uint32_t Set_GPIO_Clock(uint32_t port_idx);
7982

@@ -88,29 +91,53 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
8891
uint32_t pin_index = STM_PIN(pin);
8992

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

0 commit comments

Comments
 (0)