Skip to content

Commit 87adf11

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt/machine_pin: Clear IRQ flag when enabling or disabling IRQ.
Preventing already pending IRQs to fire when not expected. Signed-off-by: robert-hh <[email protected]>
1 parent 36108a4 commit 87adf11

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ports/mimxrt/machine_pin.c

+3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
407407
if (args[ARG_handler].u_obj == mp_const_none) {
408408
// remove the IRQ from the table, leave it to gc to free it.
409409
GPIO_PortDisableInterrupts(self->gpio, 1U << self->pin);
410+
GPIO_PortClearInterruptFlags(self->gpio, 1U << self->pin);
410411
MP_STATE_PORT(machine_pin_irq_objects[index]) = NULL;
411412
return mp_const_none;
412413
}
@@ -445,6 +446,8 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
445446
GPIO_PinSetInterruptConfig(self->gpio, self->pin, irq->trigger);
446447
// Enable the specific Pin interrupt
447448
GPIO_PortEnableInterrupts(self->gpio, 1U << self->pin);
449+
// Clear previous IRQs
450+
GPIO_PortClearInterruptFlags(self->gpio, 1U << self->pin);
448451
// Enable LEVEL1 interrupt again
449452
EnableIRQ(irq_num);
450453
}

0 commit comments

Comments
 (0)