arduino / arduino/ArduinoCore-samd

attachInterrupt() should clear EIC INTFLAG or prior events will cause an interrupt

Open
#348 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
502
Forks
740
PR merge metrics
No merged PRs in 30d

Description

Consider the following pseudocode:
attachInterrupt()....enable interrupts on a pin on falling edge
...
ISR: deal with an interrupt and clear INTFLAG
...
detachInterrupt()...disable interrupt on the pin
...
there is a falling edge on the pin while interrupts are disabled
...
attachInterrupt()...enable interrupts again

An interrupt will be generated, even if the interrupt flag was cleared in the ISR!

This doesn't happen if the interrupt flag is cleared immediately before attachInterrupt() is called:
e.g. for EXTINT[6]
`REG_EIC_INTFLAG = EIC_INTFLAG_EXTINT6; // Clear the EXTINT6 flag`

It seems to make sense to modify attachInterrupt() to clear the interrupt flag before enabling the interrupt, and/or add a function to clear the interrupt that doesn't require the user to go into the spec sheet and Google and figure everything out by themselves.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the attachInterrupt() implementation and review how the SAMD21 EIC interrupt is enabled, using the EXTINT[6] example and EIC_INTFLAG behavior described in the issue. Reproduce the detach/edge/reattach sequence and verify that reattaching does not generate an interrupt from an event that occurred while interrupts were disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.