This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 448276c70daafb818fc401adea7aa9e546baff48
Author: AlmAck <[email protected]>
AuthorDate: Sat Aug 29 19:00:22 2026 +0200

    arch/arm/nrf53: fix inverted GPIOTE per-instance channel index
    
    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 <[email protected]>
---
 arch/arm/src/nrf53/nrf53_gpiote.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/src/nrf53/nrf53_gpiote.c 
b/arch/arm/src/nrf53/nrf53_gpiote.c
index 3f5a6fb7679..139e4f8945b 100644
--- a/arch/arm/src/nrf53/nrf53_gpiote.c
+++ b/arch/arm/src/nrf53/nrf53_gpiote.c
@@ -405,7 +405,7 @@ void nrf53_gpiote_set_ch_event(uint32_t pinset, int channel,
   inst = 0;
 #endif
 
-  rchan = (inst == 1) ? channel : (channel - GPIOTE_PER_CHANNEL);
+  rchan = (inst == 1) ? (channel - GPIOTE_PER_CHANNEL) : channel;
 
   /* NOTE: GPIOTE module has priority over GPIO module
    *       so GPIO configuration will be ignored
@@ -567,7 +567,7 @@ void nrf53_gpiote_set_task(uint32_t pinset, int channel,
   inst = 0;
 #endif
 
-  rchan = (inst == 1) ? channel : (channel - GPIOTE_PER_CHANNEL);
+  rchan = (inst == 1) ? (channel - GPIOTE_PER_CHANNEL) : channel;
 
   /* Select GPIOTE pin */
 

Reply via email to