Skip to content

Commit 90e3a08

Browse files
[sam] Do not run disabled interrupt handlers
On SAM: - all pins in a port share a single interrupt pin - the interrupt status flag for a pin is set even when it is disabled - The actual ISR does not look at the interrupt enable flags, it just runs the callback for every pin whos interrupt status flag is set. This meant that if: - an interrupt was attached and later detached, - then the interrupt condition occured, setting the flag and - then another (still attached) interrupt on a different pin in the same port occured, then the detached interrupt callback would also be called. By masking off the Interrupts Status Register using the Interrupt Mask Register, only actually enabled interrupt handlers are called. The incorrect behaviour has been verified using the following test sketch: /* To test: - Upload this sketch to the Arduino Due - Open the serial monitor at 115200 - Connect a jumper wire to ground and touch the other end to pins 25 and 26, alternating between them */ void int25() { Serial.println("INT25"); } void int26() { Serial.println("INT26"); } void setup() { Serial.begin(115200); pinMode(25, INPUT_PULLUP); pinMode(26, INPUT_PULLUP); attachInterrupt(25, int25, CHANGE); attachInterrupt(26, int26, CHANGE); detachInterrupt(26); } void loop() { }
1 parent ef95809 commit 90e3a08

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

hardware/arduino/sam/cores/arduino/WInterrupts.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extern "C" {
134134
#endif
135135

136136
void PIOA_Handler(void) {
137-
uint32_t isr = PIOA->PIO_ISR;
137+
uint32_t isr = PIOA->PIO_ISR & PIOA->PIO_IMR;
138138
uint32_t i;
139139
for (i=0; i<32; i++, isr>>=1) {
140140
if ((isr & 0x1) == 0)
@@ -145,7 +145,7 @@ void PIOA_Handler(void) {
145145
}
146146

147147
void PIOB_Handler(void) {
148-
uint32_t isr = PIOB->PIO_ISR;
148+
uint32_t isr = PIOB->PIO_ISR & PIOB->PIO_IMR;
149149
uint32_t i;
150150
for (i=0; i<32; i++, isr>>=1) {
151151
if ((isr & 0x1) == 0)
@@ -156,7 +156,7 @@ void PIOB_Handler(void) {
156156
}
157157

158158
void PIOC_Handler(void) {
159-
uint32_t isr = PIOC->PIO_ISR;
159+
uint32_t isr = PIOC->PIO_ISR & PIOC->PIO_IMR;
160160
uint32_t i;
161161
for (i=0; i<32; i++, isr>>=1) {
162162
if ((isr & 0x1) == 0)
@@ -167,7 +167,7 @@ void PIOC_Handler(void) {
167167
}
168168

169169
void PIOD_Handler(void) {
170-
uint32_t isr = PIOD->PIO_ISR;
170+
uint32_t isr = PIOD->PIO_ISR & PIOD->PIO_IMR;
171171
uint32_t i;
172172
for (i=0; i<32; i++, isr>>=1) {
173173
if ((isr & 0x1) == 0)

0 commit comments

Comments
 (0)