Skip to content

Commit 9b0e346

Browse files
committed
[nrf fromtree] drivers: gpio_nrfx: Free channel when changing mode
Fix an issue where calling gpio_pin_interrupt_configure with edge mode and later calling it with level mode, did not release the allocated gpiote channel. Repeating the above sequence caused us to run out of gpiote channels. Signed-off-by: Markus Lassila <[email protected]> (cherry picked from commit 581f756)
1 parent eb12c85 commit 9b0e346

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/gpio/gpio_nrfx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,15 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port,
444444
}
445445

446446
trigger_config.p_in_channel = &ch;
447+
} else {
448+
/* If edge mode with channel was previously used and we are changing to sense or
449+
* level triggered, we must free the channel.
450+
*/
451+
err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch);
452+
if (err == NRFX_SUCCESS) {
453+
err = nrfx_gpiote_channel_free(&cfg->gpiote, ch);
454+
__ASSERT_NO_MSG(err == NRFX_SUCCESS);
455+
}
447456
}
448457

449458
err = nrfx_gpiote_input_configure(&cfg->gpiote, abs_pin, &input_pin_config);

0 commit comments

Comments
 (0)