Skip to content

Commit 91d0a6d

Browse files
committed
InterruptIn : STM32: Implemented error catching for multiple gpio irq line
The multiple InterruptIn object with same pin_index sharing same IRQ line. So the second object will overwrite the first one. To catch this as error, implemented an error catching functionality.
1 parent d83494f commit 91d0a6d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

targets/TARGET_STM/gpio_irq_api.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ typedef struct gpio_channel {
5353
} gpio_channel_t;
5454

5555
static gpio_irq_handler irq_handler;
56+
static uint16_t irq_channel_used = 0x00;
5657

5758
static gpio_channel_t channels[CHANNEL_NUM] = {
5859
#ifdef EXTI_IRQ0_NUM_LINES
@@ -331,6 +332,14 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
331332
uint32_t pin_index = STM_PIN(pin);
332333
irq_index = pin_lines_desc[pin_index].irq_index;
333334

335+
if (irq_channel_used & (1<<pin_index)) {
336+
error("InterruptIn error: irq channel conflict\n");
337+
return -1;
338+
}
339+
else {
340+
irq_channel_used |= (1<<pin_index);
341+
}
342+
334343
switch (irq_index) {
335344
#ifdef EXTI_IRQ0_NUM_LINES
336345
case 0:
@@ -457,6 +466,8 @@ void gpio_irq_free(gpio_irq_t *obj)
457466
gpio_channel->channel_gpio[gpio_idx] = 0;
458467
gpio_channel->channel_pin[gpio_idx] = 0;
459468

469+
irq_channel_used &= ~(1<<(STM_PIN(obj->pin)));
470+
460471
core_util_critical_section_exit();
461472
}
462473

0 commit comments

Comments
 (0)