Skip to content

Commit 55c1b9f

Browse files
committed
Remove sequence points / barriers ...
when programming the GPIOTE peripheral. the memory barrier is still used once in the ISR, to prevent spurious interrupts caused by delay writing over the (16MHz) AHB bus.
1 parent c3c8ac3 commit 55c1b9f

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

cores/nRF5/WInterrupts.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,18 @@ int attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
132132
return 0; // no channel available
133133
}
134134

135-
uint32_t tmp = NRF_GPIOTE->CONFIG[ch];
136-
tmp &= oldRegMask;
137-
tmp |= newRegBits; // for existing channel, effectively updates only the polarity
138135
channelMap[ch] = pin; // harmless for existing channel
139136
callbacksInt[ch] = callback; // caller might be updating this for existing channel
140137
callbackDeferred[ch] = deferred; // caller might be updating this for existing channel
138+
139+
uint32_t tmp = NRF_GPIOTE->CONFIG[ch];
140+
tmp &= oldRegMask;
141+
tmp |= newRegBits; // for existing channel, effectively updates only the polarity
141142
NRF_GPIOTE->CONFIG[ch] = tmp;
142143

143144
// For a new channel, additionally ensure no old events existed, and enable the interrupt
144145
if (newChannel) {
145-
// Why the memory barrier and NOPs?
146-
// See page 4 at https://web.archive.org/web/20190823222657/http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
147-
// and recall the AHB runs at 16MHz, so may take 4 cycles before peripheral register is actually updated.
148-
__DSB(); __NOP();__NOP();__NOP();__NOP();
149146
NRF_GPIOTE->EVENTS_IN[ch] = 0;
150-
__DSB(); __NOP();__NOP();__NOP();__NOP();
151147
NRF_GPIOTE->INTENSET = (1 << ch);
152148
}
153149

@@ -168,13 +164,8 @@ void detachInterrupt(uint32_t pin)
168164

169165
for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
170166
if ((uint32_t)channelMap[ch] == pin) {
171-
// Why the memory barrier and NOPs?
172-
// See page 4 at https://web.archive.org/web/20190823222657/http://infocenter.arm.com/help/topic/com.arm.doc.dai0321a/DAI0321A_programming_guide_memory_barriers_for_m_profile.pdf
173-
// and recall the AHB runs at 16MHz, so may take 4 cycles before peripheral register is actually updated.
174167
NRF_GPIOTE->INTENCLR = (1 << ch);
175-
__DSB(); __NOP();__NOP();__NOP();__NOP();
176168
NRF_GPIOTE->CONFIG[ch] = 0;
177-
__DSB(); __NOP();__NOP();__NOP();__NOP();
178169
NRF_GPIOTE->EVENTS_IN[ch] = 0; // clear any final events
179170

180171
// now cleanup the rest of the use of the channel

0 commit comments

Comments
 (0)