arch/arm/nrf53: fix inverted GPIOTE per-instance channel index - #20002
Merged
Conversation
xiaoxiang781216
previously approved these changes
Aug 30, 2026
Contributor
|
Hi @AlmAck please fix and rebase |
The driver presents a single channel space of GPIOTE_CHANNELS entries across the application core's two GPIOTE peripherals, and splits it: inst = (channel < GPIOTE_PER_CHANNEL) ? 0 : 1; rchan = (inst == 1) ? channel : (channel - GPIOTE_PER_CHANNEL); rchan is the channel index within the selected instance, used to build the per-channel register offsets, so it must be rchan = channel - GPIOTE_PER_CHANNEL * inst The ternary has the two arms the other way round: a channel on instance 0 gets rchan = channel - GPIOTE_PER_CHANNEL, which is negative, and a channel on instance 1 gets an index still offset by a full instance. The interrupt handler in this same file already applies that mapping in the opposite direction, converting a per-instance channel back to the global one: off = i + GPIOTE_PER_CHANNEL * inst; so the two were inconsistent, and it is the rchan sites that were wrong. Per the nRF5340 Product Specification, 'GPIOTE - GPIO tasks and events', the application core has two GPIOTE instances, GPIOTE0 (secure, base 0x5000D000) and GPIOTE1 (non-secure, base 0x4002F000), each with eight channels and its own CONFIG[n] array at offset 0x510 + 4n for n = 0..7. This matches GPIOTE_PER_CHANNEL == 8, the two base addresses in hardware/nrf53_memorymap_cpuapp.h, and NRF53_GPIOTE_CONFIG_OFFSET() in hardware/nrf53_gpiote.h, so rchan is required to be in 0..7 and a negative value cannot address a CONFIG register. With a negative rchan the CONFIG register write for a channel on instance 0 lands below the instance base instead of in CONFIG[n], so the channel is never configured and its GPIOTE interrupt is never enabled. On nrf5340-dk this makes the board buttons dead. Both call sites are corrected. Signed-off-by: AlmAck <gluca86@gmail.com>
Pre-existing violations in this file, reported by checkpatch because the preceding commit touches it: nrf53_gpiote.c:185: Missing blank line after declarations nrf53_gpiote.c:213: Bad alignment nrf53_gpiote.c:216: Bad alignment nrf53_gpiote.c:259: Bad right brace alignment Add the blank line after the declarations in the channel-callback block, indent the two `break;` statements into their case bodies, and align the brace closing the per-port `for` loop with its opening at line 209 (it sat at seven spaces, so neither the loop's eight nor anything else). Whitespace only — no functional change, brace count unchanged. Signed-off-by: AlmAck <gluca86@gmail.com>
AlmAck
force-pushed
the
fix/nrf53-gpiote-rchan
branch
from
August 30, 2026 18:07
9f1c849 to
16f8775
Compare
Contributor
Author
those bad alignment are not part of my original PR, i added them too as requested. probably an entire check on those files is required separately to avoid mixing PR content. |
xiaoxiang781216
approved these changes
Aug 30, 2026
acassis
approved these changes
Aug 30, 2026
simbit18
approved these changes
Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The driver presents a single channel space of
GPIOTE_CHANNELSentriesacross the application core's two GPIOTE peripherals, and splits it:
rchanis the channel index within the selected instance, used tobuild the per-channel register offsets, so it must be
The ternary has the two arms the other way round: a channel on instance
0 gets
rchan = channel - GPIOTE_PER_CHANNEL, which is negative, and achannel on instance 1 gets an index still offset by a full instance.
Corroboration
The interrupt handler in this same file already applies that mapping in
the opposite direction, converting a per-instance channel back to the
global one:
The two were inconsistent, and it is the
rchansites that disagreedwith the rest of the driver.
Per the nRF5340 Product Specification, GPIOTE - GPIO tasks and events,
the application core has two GPIOTE instances:
0x5000D000CONFIG[n], n = 0..70x4002F000CONFIG[n], n = 0..7CONFIG[n]sits at offset0x510 + 4n. That matchesGPIOTE_PER_CHANNEL == 8in the driver, the two base addresses inhardware/nrf53_memorymap_cpuapp.h, andNRF53_GPIOTE_CONFIG_OFFSET()in
hardware/nrf53_gpiote.h- sorchanis required to be in 0..7 anda negative value cannot address a CONFIG register.
Both call sites are corrected.
Impact
Any nRF5340 board using GPIOTE. For a channel on instance 0 the CONFIG
register write lands at a computed-negative offset and the GPIOTE
interrupt is never enabled, so the event never fires - on nrf5340-dk
this makes the board buttons dead.
Testing
Suggested reproduction to capture:
CONFIG_ARCH_BUTTONS=yandCONFIG_INPUT_BUTTONS,registering the board button lower-half as
/dev/buttons.poll(POLLIN)on/dev/buttonsnever returns andno press is observed - the GPIOTE interrupt is never enabled for
channels on instance 0.