Skip to content

Commit

Permalink
mimxrt/machine_pin.c: Clear IRQ flag when enabling or disabling IRQ.
Browse files Browse the repository at this point in the history
Preventing already pending IRQs to fire when not expected.

Signed-off-by: robert-hh <robert@hammelrath.com>
  • Loading branch information
robert-hh committed Aug 7, 2024
1 parent 655424a commit 4d39299
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ports/mimxrt/machine_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
if (args[ARG_handler].u_obj == mp_const_none) {
// remove the IRQ from the table, leave it to gc to free it.
GPIO_PortDisableInterrupts(self->gpio, 1U << self->pin);
GPIO_PortClearInterruptFlags(self->gpio, 1U << self->pin);
MP_STATE_PORT(machine_pin_irq_objects[index]) = NULL;
return mp_const_none;
}
Expand Down Expand Up @@ -445,6 +446,8 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
GPIO_PinSetInterruptConfig(self->gpio, self->pin, irq->trigger);
// Enable the specific Pin interrupt
GPIO_PortEnableInterrupts(self->gpio, 1U << self->pin);
// Clear previous IRQs
GPIO_PortClearInterruptFlags(self->gpio, 1U << self->pin);
// Enable LEVEL1 interrupt again
EnableIRQ(irq_num);
}
Expand Down

0 comments on commit 4d39299

Please sign in to comment.