From ea758b20bb6a5735c39c4f5ff6820104382bf9f4 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 30 Oct 2025 13:28:39 +0100 Subject: [PATCH 01/10] [nrf fromlist] soc: nordic: common: add helper macro for GPIOTE node extraction Analogously to existing macro for extracting GPIOTE instance property. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- soc/nordic/common/soc_nrf_common.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/soc/nordic/common/soc_nrf_common.h b/soc/nordic/common/soc_nrf_common.h index 12ac373fd6eb..c963b6512188 100644 --- a/soc/nordic/common/soc_nrf_common.h +++ b/soc/nordic/common/soc_nrf_common.h @@ -149,6 +149,18 @@ (NRF_DT_GPIOS_TO_PSEL(node_id, prop)), \ (default_value)) +/** + * @brief Convert a devicetree GPIO phandle+specifier to GPIOTE node. + */ +#define NRF_DT_GPIOTE_NODE_BY_IDX(node_id, prop, idx) \ + DT_PHANDLE(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx), gpiote_instance) + +/** + * @brief Equivalent to NRF_DT_GPIOTE_NODE_BY_IDX(node_id, prop, 0) + */ +#define NRF_DT_GPIOTE_NODE(node_id, prop) \ + NRF_DT_GPIOTE_NODE_BY_IDX(node_id, prop, 0) + /** * @brief Convert a devicetree GPIO phandle+specifier to GPIOTE instance number. * @@ -185,9 +197,7 @@ * NRF_DT_GPIOTE_INST_BY_IDX(DT_NODELABEL(foo), rx_gpios, 1) // = 20 */ #define NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, idx) \ - DT_PROP(DT_PHANDLE(DT_GPIO_CTLR_BY_IDX(node_id, prop, idx), \ - gpiote_instance), \ - instance) + DT_PROP(NRF_DT_GPIOTE_NODE_BY_IDX(node_id, prop, idx), instance) /** * @brief Equivalent to NRF_DT_GPIOTE_INST_BY_IDX(node_id, prop, 0) From 8d7ce1a6b18a7655e011edb9085ba63d6d3ff20a Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Wed, 29 Oct 2025 19:16:54 +0100 Subject: [PATCH 02/10] [nrf fromlist] soc: nordic: common: add nrfx gpiote instantiation component GPIOTE driver instances are no longer defined within nrfx. Add a component supplementing missing functionality, as GPIOTE driver instances are often shared across the system. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- soc/nordic/common/CMakeLists.txt | 1 + soc/nordic/common/gpiote_nrfx.c | 15 +++++++++++++++ soc/nordic/common/gpiote_nrfx.h | 22 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 soc/nordic/common/gpiote_nrfx.c create mode 100644 soc/nordic/common/gpiote_nrfx.h diff --git a/soc/nordic/common/CMakeLists.txt b/soc/nordic/common/CMakeLists.txt index 04f0c1a3219c..69361ff5d253 100644 --- a/soc/nordic/common/CMakeLists.txt +++ b/soc/nordic/common/CMakeLists.txt @@ -40,3 +40,4 @@ endif() zephyr_library_sources_ifdef(CONFIG_NRF_SYS_EVENT nrf_sys_event.c) zephyr_library_sources_ifdef(CONFIG_MRAM_LATENCY mram_latency.c) +zephyr_library_sources(gpiote_nrfx.c) diff --git a/soc/nordic/common/gpiote_nrfx.c b/soc/nordic/common/gpiote_nrfx.c new file mode 100644 index 000000000000..93c111c00a47 --- /dev/null +++ b/soc/nordic/common/gpiote_nrfx.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "gpiote_nrfx.h" + +#define GPIOTE_NRFX_INST_DEF(instname, reg) \ + nrfx_gpiote_t instname = NRFX_GPIOTE_INSTANCE(reg); +#define GPIOTE_NRFX_INST_DEFINE(node_id) \ + GPIOTE_NRFX_INST_DEF(GPIOTE_NRFX_INST_BY_NODE(node_id), DT_REG_ADDR(node_id)) + +DT_FOREACH_STATUS_OKAY(nordic_nrf_gpiote, GPIOTE_NRFX_INST_DEFINE) diff --git a/soc/nordic/common/gpiote_nrfx.h b/soc/nordic/common/gpiote_nrfx.h new file mode 100644 index 000000000000..7785eea5ea82 --- /dev/null +++ b/soc/nordic/common/gpiote_nrfx.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef SOC_NORDIC_COMMON_GPIOTE_NRFX_H_ +#define SOC_NORDIC_COMMON_GPIOTE_NRFX_H_ + +#include + +#define GPIOTE_NRFX_INST_BY_REG_CONCAT(reg) g_nrfx_gpiote##reg +#define GPIOTE_NRFX_INST_BY_REG(reg) GPIOTE_NRFX_INST_BY_REG_CONCAT(reg) +#define GPIOTE_NRFX_INST_BY_NODE(node) GPIOTE_NRFX_INST_BY_REG(DT_REG_ADDR(node)) + +#define GPIOTE_NRFX_INST_DECL(instname) \ + extern nrfx_gpiote_t instname; +#define GPIOTE_NRFX_INST_DECLARE(node_id) \ + GPIOTE_NRFX_INST_DECL(GPIOTE_NRFX_INST_BY_NODE(node_id)) + +DT_FOREACH_STATUS_OKAY(nordic_nrf_gpiote, GPIOTE_NRFX_INST_DECLARE) + +#endif /* SOC_NORDIC_COMMON_GPIOTE_NRFX_H_ */ From c20c846c8f9958418bc4e943638bf526677856db Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Wed, 15 Oct 2025 22:06:41 +0200 Subject: [PATCH 03/10] [nrf fromlist] drivers: gpio: nrf: align to nrfx_gpiote extracted control block Align GPIOTE shim to changes in nrfx instantiation. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- drivers/gpio/gpio_nrfx.c | 120 +++++++++++++------------ include/zephyr/drivers/gpio/gpio_nrf.h | 27 ++++++ 2 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 include/zephyr/drivers/gpio/gpio_nrf.h diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index 6ccb378e161d..e752d6caa77b 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -7,8 +7,10 @@ #define DT_DRV_COMPAT nordic_nrf_gpio #include +#include #include #include +#include #include #include #include @@ -52,9 +54,9 @@ struct gpio_nrfx_cfg { /* gpio_driver_config needs to be first */ struct gpio_driver_config common; NRF_GPIO_Type *port; + nrfx_gpiote_t *gpiote; uint32_t edge_sense; uint8_t port_num; - nrfx_gpiote_t gpiote; #if GPIO_HAS_PAD_GROUP const struct device *pad_group; #endif @@ -73,9 +75,16 @@ static inline const struct gpio_nrfx_cfg *get_port_cfg(const struct device *port return port->config; } +void * gpio_nrf_gpiote_by_port_get(const struct device *port) +{ + const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); + + return cfg->gpiote; +} + static bool has_gpiote(const struct gpio_nrfx_cfg *cfg) { - return cfg->gpiote.p_reg != NULL; + return cfg->gpiote != NULL; } static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags) @@ -93,7 +102,7 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, gpio_flags_t flags) { int ret = 0; - nrfx_err_t err = NRFX_SUCCESS; + int err = 0; uint8_t ch; bool free_ch = false; const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); @@ -159,13 +168,13 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, * to be freed when the pin is reconfigured or disconnected. */ if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { - err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch); - free_ch = (err == NRFX_SUCCESS); + err = nrfx_gpiote_channel_get(cfg->gpiote, abs_pin, &ch); + free_ch = (err == 0); } if ((flags & (GPIO_INPUT | GPIO_OUTPUT)) == GPIO_DISCONNECTED) { /* Ignore the error code. The pin may not have been used. */ - (void)nrfx_gpiote_pin_uninit(&cfg->gpiote, abs_pin); + (void)nrfx_gpiote_pin_uninit(cfg->gpiote, abs_pin); } else { /* Remove previously configured trigger when pin is reconfigured. */ if (IS_ENABLED(CONFIG_GPIO_NRFX_INTERRUPT)) { @@ -176,11 +185,9 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, .p_trigger_config = &trigger_config, }; - err = nrfx_gpiote_input_configure(&cfg->gpiote, + err = nrfx_gpiote_input_configure(cfg->gpiote, abs_pin, &input_pin_config); - if (err != NRFX_SUCCESS) { - ret = -EINVAL; - + if (err < 0) { goto end; } } @@ -194,19 +201,18 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, .pull = pull, }; - err = nrfx_gpiote_output_configure(&cfg->gpiote, + err = nrfx_gpiote_output_configure(cfg->gpiote, abs_pin, &output_config, NULL); } else { nrfx_gpiote_input_pin_config_t input_pin_config = { .p_pull_config = &pull, }; - err = nrfx_gpiote_input_configure(&cfg->gpiote, + err = nrfx_gpiote_input_configure(cfg->gpiote, abs_pin, &input_pin_config); } - if (err != NRFX_SUCCESS) { - ret = -EINVAL; + if (err < 0) { goto end; } } @@ -218,8 +224,8 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin, goto end; } #endif - err = nrfx_gpiote_channel_free(&cfg->gpiote, ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); + err = nrfx_gpiote_channel_free(cfg->gpiote, ch); + __ASSERT_NO_MSG(err == 0); } end: @@ -393,7 +399,7 @@ static nrfx_gpiote_trigger_t get_trigger(enum gpio_int_mode mode, NRFX_GPIOTE_TRIGGER_LOTOHI; } -static nrfx_err_t chan_alloc(const struct gpio_nrfx_cfg *cfg, gpio_pin_t pin, uint8_t *ch) +static int chan_alloc(const struct gpio_nrfx_cfg *cfg, gpio_pin_t pin, uint8_t *ch) { #ifdef GPIOTE_FEATURE_FLAG if (cfg->flags & GPIOTE_FLAG_FIXED_CHAN) { @@ -403,25 +409,25 @@ static nrfx_err_t chan_alloc(const struct gpio_nrfx_cfg *cfg, gpio_pin_t pin, ui * - P1: channel => pin - 4, e.g. P1.4 => channel 0, P1.5 => channel 1 * - P2: channel => pin % 8, e.g. P2.0 => channel 0, P2.8 => channel 0 */ - nrfx_err_t err = NRFX_SUCCESS; + int err = 0; if (cfg->port_num == 1) { if (pin < 4) { - err = NRFX_ERROR_INVALID_PARAM; + err = -EINVAL; } else { *ch = pin - 4; } } else if (cfg->port_num == 2) { *ch = pin & 0x7; } else { - err = NRFX_ERROR_INVALID_PARAM; + err = -EINVAL; } return err; } #endif - return nrfx_gpiote_channel_alloc(&cfg->gpiote, ch); + return nrfx_gpiote_channel_alloc(cfg->gpiote, ch); } static int gpio_nrfx_pin_interrupt_configure(const struct device *port, @@ -431,7 +437,7 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, { const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); uint32_t abs_pin = NRF_GPIO_PIN_MAP(cfg->port_num, pin); - nrfx_err_t err; + int err; uint8_t ch; if (!has_gpiote(cfg)) { @@ -439,7 +445,7 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, } if (mode == GPIO_INT_MODE_DISABLED) { - nrfx_gpiote_trigger_disable(&cfg->gpiote, abs_pin); + nrfx_gpiote_trigger_disable(cfg->gpiote, abs_pin); return 0; } @@ -457,11 +463,11 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, if (!(BIT(pin) & cfg->edge_sense) && (mode == GPIO_INT_MODE_EDGE) && (nrf_gpio_pin_dir_get(abs_pin) == NRF_GPIO_PIN_DIR_INPUT)) { - err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch); - if (err == NRFX_ERROR_INVALID_PARAM) { + err = nrfx_gpiote_channel_get(cfg->gpiote, abs_pin, &ch); + if (err == -EINVAL) { err = chan_alloc(cfg, pin, &ch); - if (err != NRFX_SUCCESS) { - return -ENOMEM; + if (err < 0) { + return err; } } @@ -475,19 +481,19 @@ static int gpio_nrfx_pin_interrupt_configure(const struct device *port, /* If edge mode with channel was previously used and we are changing to sense or * level triggered, we must free the channel. */ - err = nrfx_gpiote_channel_get(&cfg->gpiote, abs_pin, &ch); - if (err == NRFX_SUCCESS) { - err = nrfx_gpiote_channel_free(&cfg->gpiote, ch); - __ASSERT_NO_MSG(err == NRFX_SUCCESS); + err = nrfx_gpiote_channel_get(cfg->gpiote, abs_pin, &ch); + if (err == 0) { + err = nrfx_gpiote_channel_free(cfg->gpiote, ch); + __ASSERT_NO_MSG(err == 0); } } - err = nrfx_gpiote_input_configure(&cfg->gpiote, abs_pin, &input_pin_config); - if (err != NRFX_SUCCESS) { - return -EINVAL; + err = nrfx_gpiote_input_configure(cfg->gpiote, abs_pin, &input_pin_config); + if (err < 0) { + return err; } - nrfx_gpiote_trigger_enable(&cfg->gpiote, abs_pin, true); + nrfx_gpiote_trigger_enable(cfg->gpiote, abs_pin, true); return 0; } @@ -576,9 +582,12 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin, } #endif /* CONFIG_GPIO_NRFX_INTERRUPT */ -#define GPIOTE_IRQ_HANDLER_CONNECT(node_id) \ - IRQ_CONNECT(DT_IRQN(node_id), DT_IRQ(node_id, priority), nrfx_isr, \ - NRFX_CONCAT(nrfx_gpiote_, DT_PROP(node_id, instance), _irq_handler), 0); +#define GPIOTE_IRQ_HANDLER_CONNECT(node_id) \ + IRQ_CONNECT(DT_IRQN(node_id), \ + DT_IRQ(node_id, priority), \ + nrfx_gpiote_irq_handler, \ + &GPIOTE_NRFX_INST_BY_NODE(node_id), \ + 0); static int gpio_nrfx_pm_suspend(const struct device *port) { @@ -626,23 +635,23 @@ static int gpio_nrfx_pm_hook(const struct device *port, enum pm_device_action ac static int gpio_nrfx_init(const struct device *port) { const struct gpio_nrfx_cfg *cfg = get_port_cfg(port); - nrfx_err_t err; + int err; if (!has_gpiote(cfg)) { goto pm_init; } - if (nrfx_gpiote_init_check(&cfg->gpiote)) { + if (nrfx_gpiote_init_check(cfg->gpiote)) { goto pm_init; } - err = nrfx_gpiote_init(&cfg->gpiote, 0 /*not used*/); - if (err != NRFX_SUCCESS) { + err = nrfx_gpiote_init(cfg->gpiote, 0 /*not used*/); + if (err != 0) { return -EIO; } #ifdef CONFIG_GPIO_NRFX_INTERRUPT - nrfx_gpiote_global_callback_set(&cfg->gpiote, nrfx_gpio_handler, NULL); + nrfx_gpiote_global_callback_set(cfg->gpiote, nrfx_gpio_handler, NULL); DT_FOREACH_STATUS_OKAY(nordic_nrf_gpiote, GPIOTE_IRQ_HANDLER_CONNECT); #endif /* CONFIG_GPIO_NRFX_INTERRUPT */ @@ -669,24 +678,24 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = { #endif }; -#define GPIOTE_INST(id) DT_PROP(GPIOTE_PHANDLE(id), instance) - -#define GPIOTE_INSTANCE(id) \ - COND_CODE_1(DT_INST_NODE_HAS_PROP(id, gpiote_instance), \ - (NRFX_GPIOTE_INSTANCE(GPIOTE_INST(id))), \ - ({ .p_reg = NULL })) - /* Device instantiation is done with node labels because 'port_num' is * the peripheral number by SoC numbering. We therefore cannot use * DT_INST APIs here without wider changes. */ +#define HAS_GPIOTE(id) DT_INST_NODE_HAS_PROP(id, gpiote_instance) + #define GPIOTE_CHECK(id) \ - COND_CODE_1(DT_INST_NODE_HAS_PROP(id, gpiote_instance), \ - (BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(GPIOTE_PHANDLE(id)), \ + COND_CODE_1(HAS_GPIOTE(id), \ + (BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(GPIOTE_PHANDLE(id)), \ "Please enable GPIOTE instance for used GPIO port!")), \ ()) +#define GPIOTE_REF(id) \ + COND_CODE_1(HAS_GPIOTE(id), \ + (&GPIOTE_NRFX_INST_BY_NODE(GPIOTE_PHANDLE(id))), \ + (NULL)) + #if GPIO_HAS_PAD_GROUP #define GPIO_NRF_PAD_GROUP_INIT(id) \ .pad_group = DEVICE_DT_GET(DT_INST_CHILD(id, pad_group)), @@ -696,15 +705,16 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = { #define GPIO_NRF_DEVICE(id) \ GPIOTE_CHECK(id); \ + static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \ static const struct gpio_nrfx_cfg gpio_nrfx_p##id##_cfg = { \ .common = { \ .port_pin_mask = \ GPIO_PORT_PIN_MASK_FROM_DT_INST(id), \ }, \ .port = _CONCAT(NRF_P, DT_INST_PROP(id, port)), \ - .port_num = DT_INST_PROP(id, port), \ + .gpiote = GPIOTE_REF(id), \ .edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0), \ - .gpiote = GPIOTE_INSTANCE(id), \ + .port_num = DT_INST_PROP(id, port), \ GPIO_NRF_PAD_GROUP_INIT(id) \ IF_ENABLED(GPIOTE_FEATURE_FLAG, \ (.flags = \ @@ -715,8 +725,6 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = { ) \ }; \ \ - static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \ - \ PM_DEVICE_DT_INST_DEFINE(id, gpio_nrfx_pm_hook); \ \ DEVICE_DT_INST_DEFINE(id, gpio_nrfx_init, \ diff --git a/include/zephyr/drivers/gpio/gpio_nrf.h b/include/zephyr/drivers/gpio/gpio_nrf.h new file mode 100644 index 000000000000..8802e8a1702e --- /dev/null +++ b/include/zephyr/drivers/gpio/gpio_nrf.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_NRF_H +#define ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_NRF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Get pointer to GPIOTE driver instance + * associated with specified port device node. + * + * @param port Pointer to port device node. + * + * @return Pointer to GPIOTE driver instance. NULL if not found. + */ +void * gpio_nrf_gpiote_by_port_get(const struct device *port); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_DRIVERS_GPIO_GPIO_NRF_H */ From 7b66264022360f40ca0e1caaa8add68d7333eab2 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Tue, 28 Oct 2025 18:14:07 +0100 Subject: [PATCH 04/10] [nrf fromlist] drivers: spi: nrf: align to nrfx_gpiote with extracted control block GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- drivers/spi/spi_nrfx_common.c | 14 +++++++------- drivers/spi/spi_nrfx_common.h | 16 +++++++++------- drivers/spi/spi_nrfx_spi.c | 8 ++++---- drivers/spi/spi_nrfx_spim.c | 10 +++++----- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi_nrfx_common.c b/drivers/spi/spi_nrfx_common.c index 04a11c2367a9..17fd3f52ba33 100644 --- a/drivers/spi/spi_nrfx_common.c +++ b/drivers/spi/spi_nrfx_common.c @@ -7,7 +7,7 @@ #include "spi_nrfx_common.h" #include -int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin) +int spi_nrfx_wake_init(nrfx_gpiote_t *gpiote, uint32_t wake_pin) { nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLDOWN; uint8_t ch; @@ -20,23 +20,23 @@ int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin) .p_trigger_config = &trigger_config, .p_handler_config = NULL, }; - nrfx_err_t res; + int res; res = nrfx_gpiote_channel_alloc(gpiote, &ch); - if (res != NRFX_SUCCESS) { - return -ENODEV; + if (res < 0) { + return res; } res = nrfx_gpiote_input_configure(gpiote, wake_pin, &input_config); - if (res != NRFX_SUCCESS) { + if (res < 0) { nrfx_gpiote_channel_free(gpiote, ch); - return -EIO; + return res; } return 0; } -int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin) +int spi_nrfx_wake_request(nrfx_gpiote_t *gpiote, uint32_t wake_pin) { nrf_gpiote_event_t trigger_event = nrfx_gpiote_in_event_get(gpiote, wake_pin); uint32_t start_cycles; diff --git a/drivers/spi/spi_nrfx_common.h b/drivers/spi/spi_nrfx_common.h index 0cf17e2a0356..9a0894410783 100644 --- a/drivers/spi/spi_nrfx_common.h +++ b/drivers/spi/spi_nrfx_common.h @@ -9,16 +9,18 @@ #include #include +#include +#include #define WAKE_PIN_NOT_USED UINT32_MAX -#define WAKE_GPIOTE_INSTANCE(node_id) \ - COND_CODE_1(DT_NODE_HAS_PROP(node_id, wake_gpios), \ - (NRFX_GPIOTE_INSTANCE( \ - NRF_DT_GPIOTE_INST(node_id, wake_gpios))), \ - ({0})) +#define WAKE_GPIOTE_NODE(node_id) \ + COND_CODE_1(DT_NODE_HAS_PROP(node_id, wake_gpios), \ + (&GPIOTE_NRFX_INST_BY_NODE(DT_PHANDLE(DT_PHANDLE(node_id, wake_gpios), \ + gpiote_instance))), \ + (NULL)) -int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin); -int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin); +int spi_nrfx_wake_init(nrfx_gpiote_t *gpiote, uint32_t wake_pin); +int spi_nrfx_wake_request(nrfx_gpiote_t *gpiote, uint32_t wake_pin); #endif /* ZEPHYR_DRIVERS_SPI_NRFX_COMMON_H_ */ diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index 7608f3ab9487..b32a80edb917 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -31,8 +31,8 @@ struct spi_nrfx_config { nrfx_spi_config_t def_config; void (*irq_connect)(void); const struct pinctrl_dev_config *pcfg; + nrfx_gpiote_t *wake_gpiote; uint32_t wake_pin; - nrfx_gpiote_t wake_gpiote; }; static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context); @@ -241,7 +241,7 @@ static int transceive(const struct device *dev, dev_data->busy = true; if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - error = spi_nrfx_wake_request(&dev_config->wake_gpiote, + error = spi_nrfx_wake_request(dev_config->wake_gpiote, dev_config->wake_pin); if (error == -ETIMEDOUT) { LOG_WRN("Waiting for WAKE acknowledgment timed out"); @@ -395,7 +395,7 @@ static int spi_nrfx_init(const struct device *dev) } if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin); + err = spi_nrfx_wake_init(dev_config->wake_gpiote, dev_config->wake_pin); if (err == -ENODEV) { LOG_ERR("Failed to allocate GPIOTE channel for WAKE"); return err; @@ -458,9 +458,9 @@ static int spi_nrfx_init(const struct device *dev) }, \ .irq_connect = irq_connect##idx, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPI(idx)), \ + .wake_gpiote = WAKE_GPIOTE_NODE(SPI(idx)), \ .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPI(idx), wake_gpios, \ WAKE_PIN_NOT_USED), \ - .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPI(idx)), \ }; \ BUILD_ASSERT(!DT_NODE_HAS_PROP(SPI(idx), wake_gpios) || \ !(DT_GPIO_FLAGS(SPI(idx), wake_gpios) & GPIO_ACTIVE_LOW), \ diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 585a90fec0d6..bb5f8c419e67 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -102,8 +102,8 @@ struct spi_nrfx_config { void (*irq_connect)(void); uint16_t max_chunk_len; const struct pinctrl_dev_config *pcfg; + nrfx_gpiote_t *wake_gpiote; uint32_t wake_pin; - nrfx_gpiote_t wake_gpiote; #ifdef SPIM_ANY_FAST const struct device *clk_dev; struct nrf_clock_spec clk_spec; @@ -512,7 +512,7 @@ static int transceive(const struct device *dev, dev_data->busy = true; if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - error = spi_nrfx_wake_request(&dev_config->wake_gpiote, + error = spi_nrfx_wake_request(dev_config->wake_gpiote, dev_config->wake_pin); if (error == -ETIMEDOUT) { LOG_WRN("Waiting for WAKE acknowledgment timed out"); @@ -709,7 +709,7 @@ static int spi_nrfx_init(const struct device *dev) (void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP); if (dev_config->wake_pin != WAKE_PIN_NOT_USED) { - err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin); + err = spi_nrfx_wake_init(dev_config->wake_gpiote, dev_config->wake_pin); if (err == -ENODEV) { LOG_ERR("Failed to allocate GPIOTE channel for WAKE"); return err; @@ -808,13 +808,13 @@ static int spi_nrfx_deinit(const struct device *dev) SPI_NRFX_SPIM_EXTENDED_CONFIG(inst) \ }, \ .irq_connect = irq_connect##inst, \ - .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ .max_chunk_len = BIT_MASK( \ DT_INST_PROP(inst, easydma_maxcnt_bits)), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ + .wake_gpiote = WAKE_GPIOTE_NODE(DT_DRV_INST(inst)), \ .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(DT_DRV_INST(inst), \ wake_gpios, \ WAKE_PIN_NOT_USED), \ - .wake_gpiote = WAKE_GPIOTE_INSTANCE(DT_DRV_INST(inst)), \ IF_ENABLED(SPIM_ANY_FAST, \ (.clk_dev = DEVICE_DT_GET_OR_NULL( \ DT_CLOCKS_CTLR(DT_DRV_INST(inst))), \ From 8ef6af30d46997e5e7538cbac00ed6fda2565b38 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Wed, 29 Oct 2025 19:15:51 +0100 Subject: [PATCH 05/10] [nrf fromlist] drivers: pwm: pwm_nrf_sw: align to nrfx_gpiote with extracted cb GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- drivers/pwm/pwm_nrf_sw.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/pwm/pwm_nrf_sw.c b/drivers/pwm/pwm_nrf_sw.c index 6b286d30f24d..d4ec8e321175 100644 --- a/drivers/pwm/pwm_nrf_sw.c +++ b/drivers/pwm/pwm_nrf_sw.c @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -62,7 +63,7 @@ struct pwm_config { NRF_RTC_Type *rtc; NRF_TIMER_Type *timer; }; - nrfx_gpiote_t gpiote[PWM_0_MAP_SIZE]; + nrfx_gpiote_t * gpiote[PWM_0_MAP_SIZE]; uint8_t psel_ch[PWM_0_MAP_SIZE]; uint8_t initially_inverted; uint8_t map_size; @@ -164,7 +165,7 @@ static int pwm_nrf_sw_set_cycles(const struct device *dev, uint32_t channel, } } - gpiote = config->gpiote[channel].p_reg; + gpiote = config->gpiote[channel]->p_reg; psel_ch = config->psel_ch[channel]; gpiote_ch = data->gpiote_ch[channel]; ppi_chs = data->ppi_h[channel]; @@ -349,7 +350,6 @@ static int pwm_nrf_sw_init(const struct device *dev) uint32_t src_d = nrfx_gppi_domain_id_get((USE_RTC ? (uint32_t)rtc : (uint32_t)timer)); for (uint32_t i = 0; i < config->map_size; i++) { - nrfx_err_t err; uint32_t dst_d = nrfx_gppi_domain_id_get((uint32_t)config->gpiote[i].p_reg); int rv; @@ -373,14 +373,13 @@ static int pwm_nrf_sw_init(const struct device *dev) } nrfx_gppi_channels_disable(src_d, data->ppi_ch_mask[i]); - err = nrfx_gpiote_channel_alloc(&config->gpiote[i], - &data->gpiote_ch[i]); - if (err != NRFX_SUCCESS) { + rv = nrfx_gpiote_channel_alloc(config->gpiote[i], &data->gpiote_ch[i]); + if (rv < 0) { /* Do not free allocated resource. It is a fatal condition, * system requires reconfiguration. */ LOG_ERR("Failed to allocate GPIOTE channel"); - return -ENOMEM; + return rv; } /* Set initial state of the output pins. */ @@ -418,7 +417,7 @@ static int pwm_nrf_sw_init(const struct device *dev) ? BIT(_idx) : 0) | #define GPIOTE_AND_COMMA(_node_id, _prop, _idx) \ - NRFX_GPIOTE_INSTANCE(NRF_DT_GPIOTE_INST_BY_IDX(_node_id, _prop, _idx)), + &GPIOTE_NRFX_INST_BY_NODE(NRF_DT_GPIOTE_NODE_BY_IDX(_node_id, _prop, _idx)) static const struct pwm_config pwm_nrf_sw_0_config = { COND_CODE_1(USE_RTC, (.rtc), (.timer)) = GENERATOR_ADDR, From e4ca5582f475835addefd1bc2c5aa61f8660085a Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Wed, 29 Oct 2025 20:22:07 +0100 Subject: [PATCH 06/10] [nrf fromlist] drivers: display: nrf_led_matrix: align to nrfx_gpiote with extracted cb GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- drivers/display/display_nrf_led_matrix.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/display/display_nrf_led_matrix.c b/drivers/display/display_nrf_led_matrix.c index e70d4842d400..51f2f3ea73f5 100644 --- a/drivers/display/display_nrf_led_matrix.c +++ b/drivers/display/display_nrf_led_matrix.c @@ -13,8 +13,8 @@ #include #endif #include +#include #include -#include #include #include LOG_MODULE_REGISTER(nrf_led_matrix, CONFIG_DISPLAY_LOG_LEVEL); @@ -89,7 +89,7 @@ struct display_drv_config { #if USE_PWM NRF_PWM_Type *pwm; #else - nrfx_gpiote_t gpiote; + nrfx_gpiote_t *gpiote; #endif uint8_t rows[ROW_COUNT]; uint8_t cols[COL_COUNT]; @@ -325,7 +325,7 @@ static void prepare_pixel_pulse(const struct device *dev, /* First timer channel is used for timing the period of pulses. */ nrf_timer_cc_set(dev_config->timer, 1 + channel_idx, pulse); - dev_config->gpiote.p_reg->CONFIG[dev_data->gpiote_ch[channel_idx]] = gpiote_cfg; + dev_config->gpiote->p_reg->CONFIG[dev_data->gpiote_ch[channel_idx]] = gpiote_cfg; #endif /* USE_PWM */ } @@ -355,7 +355,7 @@ static void timer_irq_handler(void *arg) } #else for (int i = 0; i < GROUP_SIZE; ++i) { - dev_config->gpiote.p_reg->CONFIG[dev_data->gpiote_ch[i]] = 0; + dev_config->gpiote->p_reg->CONFIG[dev_data->gpiote_ch[i]] = 0; } #endif @@ -435,27 +435,26 @@ static int instance_init(const struct device *dev) nrf_pwm_loop_set(dev_config->pwm, 0); nrf_pwm_shorts_set(dev_config->pwm, NRF_PWM_SHORT_SEQEND0_STOP_MASK); #else - nrfx_err_t err; nrfx_gppi_handle_t ppi_handle; int rv; for (int i = 0; i < GROUP_SIZE; ++i) { uint8_t *gpiote_ch = &dev_data->gpiote_ch[i]; - err = nrfx_gpiote_channel_alloc(&dev_config->gpiote, gpiote_ch); - if (err != NRFX_SUCCESS) { + rv = nrfx_gpiote_channel_alloc(dev_config->gpiote, gpiote_ch); + if (rv != 0) { LOG_ERR("Failed to allocate GPIOTE channel."); /* Do not bother with freeing resources allocated * so far. The application needs to be reconfigured * anyway. */ - return -ENOMEM; + return rv; } rv = nrfx_gppi_conn_alloc( nrf_timer_event_address_get(dev_config->timer, nrf_timer_compare_event_get(1 + i)), - nrf_gpiote_event_address_get(dev_config->gpiote.p_reg, + nrf_gpiote_event_address_get(dev_config->gpiote->p_reg, nrf_gpiote_out_task_get(*gpiote_ch)), &ppi_handle); if (rv < 0) { @@ -535,13 +534,14 @@ DT_FOREACH_PROP_ELEM(MATRIX_NODE, col_gpios, CHECK_GPIOTE_INST) [GET_DT_ROW_IDX(idx) * COL_COUNT + \ GET_DT_COL_IDX(idx)] = idx, +//NRFX_GPIOTE_INSTANCE(NRF_DT_GPIOTE_INST_BY_IDX(MATRIX_NODE, col_gpios, 0)), + static const struct display_drv_config instance_config = { .timer = (NRF_TIMER_Type *)DT_REG_ADDR(TIMER_NODE), #if USE_PWM .pwm = (NRF_PWM_Type *)DT_REG_ADDR(PWM_NODE), #else - .gpiote = NRFX_GPIOTE_INSTANCE( - NRF_DT_GPIOTE_INST_BY_IDX(MATRIX_NODE, col_gpios, 0)), + .gpiote = &GPIOTE_NRFX_INST_BY_NODE(NRF_DT_GPIOTE_NODE(MATRIX_NODE, col_gpios)), #endif .rows = { DT_FOREACH_PROP_ELEM(MATRIX_NODE, row_gpios, GET_PIN_INFO) }, .cols = { DT_FOREACH_PROP_ELEM(MATRIX_NODE, col_gpios, GET_PIN_INFO) }, From 2bc620141764dfab99d48e25b61be96c7324f3f4 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 30 Oct 2025 20:25:38 +0100 Subject: [PATCH 07/10] [nrf fromlist] samples: uac2_explicit_feedback: align to nrfx_gpiote with extracted cb GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- .../uac2_explicit_feedback/src/feedback_nrf.c | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/samples/subsys/usb/uac2_explicit_feedback/src/feedback_nrf.c b/samples/subsys/usb/uac2_explicit_feedback/src/feedback_nrf.c index 4b7bbc6a0c32..c33d95063fd6 100644 --- a/samples/subsys/usb/uac2_explicit_feedback/src/feedback_nrf.c +++ b/samples/subsys/usb/uac2_explicit_feedback/src/feedback_nrf.c @@ -9,6 +9,7 @@ #include "feedback.h" #include +#include #include #include #include @@ -59,8 +60,7 @@ static inline void feedback_target_init(void) #error "Unsupported target" #endif -static const nrfx_gpiote_t gpiote = - NRFX_GPIOTE_INSTANCE(FEEDBACK_GPIOTE_INSTANCE_NUMBER); +#define FEEDBACK_GPIOTE_NODE DT_NODELABEL(UTIL_CAT(gpiote, FEEDBACK_GPIOTE_INSTANCE_NUMBER)) static nrfx_timer_t feedback_timer_instance = NRFX_TIMER_INSTANCE(NRF_TIMER_INST_GET(FEEDBACK_TIMER_INSTANCE_NUMBER)); @@ -117,11 +117,11 @@ static struct feedback_ctx { }; } fb_ctx; -static nrfx_err_t feedback_edge_counter_setup(void) +static int feedback_edge_counter_setup(void) { - nrfx_err_t err; uint8_t feedback_gpiote_channel; nrfx_gppi_handle_t feedback_gppi_handle; + nrfx_gpiote_t *gpiote = &GPIOTE_NRFX_INST_BY_NODE(FEEDBACK_GPIOTE_NODE); nrfx_gpiote_trigger_config_t trigger_config = { .trigger = NRFX_GPIOTE_TRIGGER_TOGGLE, .p_in_channel = &feedback_gpiote_channel, @@ -133,13 +133,13 @@ static nrfx_err_t feedback_edge_counter_setup(void) }; int rv; - err = nrfx_gpiote_channel_alloc(&gpiote, &feedback_gpiote_channel); - if (err != NRFX_SUCCESS) { - return err; + rv = nrfx_gpiote_channel_alloc(gpiote, &feedback_gpiote_channel); + if (rv != 0) { + return rv; } - nrfx_gpiote_input_configure(&gpiote, FEEDBACK_PIN, &input_pin_config); - nrfx_gpiote_trigger_enable(&gpiote, FEEDBACK_PIN, false); + nrfx_gpiote_input_configure(gpiote, FEEDBACK_PIN, &input_pin_config); + nrfx_gpiote_trigger_enable(gpiote, FEEDBACK_PIN, false); /* Configure TIMER in COUNTER mode */ const nrfx_timer_config_t cfg = { @@ -150,14 +150,14 @@ static nrfx_err_t feedback_edge_counter_setup(void) .p_context = NULL, }; - err = nrfx_timer_init(&feedback_timer_instance, &cfg, NULL); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx timer init error (sample clk feedback) - Return value: %d", err); - return err; + rv = nrfx_timer_init(&feedback_timer_instance, &cfg, NULL); + if (rv != 0) { + LOG_ERR("nrfx timer init error (sample clk feedback) - Return value: %d", rv); + return rv; } /* Subscribe TIMER COUNT task to GPIOTE IN event */ - uint32_t eep = nrfx_gpiote_in_event_address_get(&gpiote, FEEDBACK_PIN); + uint32_t eep = nrfx_gpiote_in_event_address_get(gpiote, FEEDBACK_PIN); uint32_t tep = nrfx_timer_task_address_get(&feedback_timer_instance, NRF_TIMER_TASK_COUNT); rv = nrfx_gppi_conn_alloc(eep, tep, &feedback_gppi_handle); @@ -168,12 +168,12 @@ static nrfx_err_t feedback_edge_counter_setup(void) nrfx_gppi_conn_enable(feedback_gppi_handle); - return NRFX_SUCCESS; + return 0; } -static nrfx_err_t feedback_relative_timer_setup(void) +static int feedback_relative_timer_setup(void) { - nrfx_err_t err; + int err; const nrfx_timer_config_t cfg = { .frequency = NRFX_MHZ_TO_HZ(16UL), .mode = NRF_TIMER_MODE_TIMER, @@ -183,7 +183,7 @@ static nrfx_err_t feedback_relative_timer_setup(void) }; err = nrfx_timer_init(&feedback_timer_instance, &cfg, NULL); - if (err != NRFX_SUCCESS) { + if (err != 0) { LOG_ERR("nrfx timer init error (relative timer) - Return value: %d", err); } @@ -192,7 +192,6 @@ static nrfx_err_t feedback_relative_timer_setup(void) struct feedback_ctx *feedback_init(void) { - nrfx_err_t err; nrfx_gppi_handle_t usbd_sof_gppi_handle; nrfx_gppi_handle_t i2s_framestart_gppi_handle; int rv; @@ -202,12 +201,12 @@ struct feedback_ctx *feedback_init(void) feedback_reset_ctx(&fb_ctx, false); if (IS_ENABLED(CONFIG_APP_USE_I2S_LRCLK_EDGES_COUNTER)) { - err = feedback_edge_counter_setup(); + rv = feedback_edge_counter_setup(); } else { - err = feedback_relative_timer_setup(); + rv = feedback_relative_timer_setup(); } - if (err != NRFX_SUCCESS) { + if (rv != 0) { return &fb_ctx; } From 6de7e9d682d0d6da8283237629e22038d158d94b Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 30 Oct 2025 20:27:22 +0100 Subject: [PATCH 08/10] [nrf fromlist] subsys: bluetooth: nordic: align to nrfx_gpiote with extracted cb GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 29 ++++++++++--------- .../hal/nrf5/radio/radio_nrf5_dppi_gpiote.h | 8 ++--- .../hal/nrf5/radio/radio_nrf5_ppi_gpiote.h | 8 ++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 90a0945f5a19..561f3468d687 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -11,6 +11,7 @@ #include #include +#include #include "util/mem.h" @@ -66,8 +67,8 @@ BUILD_ASSERT(!HAL_RADIO_GPIO_LNA_OFFSET_MISSING, #endif /* FEM_NODE */ #if defined(HAL_RADIO_GPIO_HAVE_PA_PIN) || defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) -static const nrfx_gpiote_t gpiote_palna = NRFX_GPIOTE_INSTANCE( - NRF_DT_GPIOTE_INST(FEM_NODE, HAL_RADIO_GPIO_PA_PROP)); +static nrfx_gpiote_t * const gpiote_palna = + &GPIOTE_NRFX_INST_BY_NODE(NRF_DT_GPIOTE_NODE(FEM_NODE, HAL_RADIO_GPIO_PA_PROP)); static uint8_t gpiote_ch_palna; BUILD_ASSERT(NRF_DT_GPIOTE_INST(FEM_NODE, HAL_RADIO_GPIO_PA_PROP) == @@ -77,8 +78,8 @@ BUILD_ASSERT(NRF_DT_GPIOTE_INST(FEM_NODE, HAL_RADIO_GPIO_PA_PROP) == #endif #if defined(HAL_RADIO_FEM_IS_NRF21540) -static const nrfx_gpiote_t gpiote_pdn = NRFX_GPIOTE_INSTANCE( - NRF_DT_GPIOTE_INST(FEM_NODE, pdn_gpios)); +static nrfx_gpiote_t * const gpiote_pdn = + &GPIOTE_NRFX_INST_BY_NODE(NRF_DT_GPIOTE_NODE(FEM_NODE, pdn_gpios)); static uint8_t gpiote_ch_pdn; #endif @@ -1930,13 +1931,13 @@ uint32_t radio_tmr_sample_get(void) int radio_gpio_pa_lna_init(void) { #if defined(HAL_RADIO_GPIO_HAVE_PA_PIN) || defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) - if (nrfx_gpiote_channel_alloc(&gpiote_palna, &gpiote_ch_palna) != NRFX_SUCCESS) { + if (nrfx_gpiote_channel_alloc(gpiote_palna, &gpiote_ch_palna) != NRFX_SUCCESS) { return -ENOMEM; } #endif #if defined(NRF_GPIO_PDN_PIN) - if (nrfx_gpiote_channel_alloc(&gpiote_pdn, &gpiote_ch_pdn) != NRFX_SUCCESS) { + if (nrfx_gpiote_channel_alloc(gpiote_pdn, &gpiote_ch_pdn) != NRFX_SUCCESS) { return -ENOMEM; } #endif @@ -1947,18 +1948,18 @@ int radio_gpio_pa_lna_init(void) void radio_gpio_pa_lna_deinit(void) { #if defined(HAL_RADIO_GPIO_HAVE_PA_PIN) || defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) - (void)nrfx_gpiote_channel_free(&gpiote_palna, gpiote_ch_palna); + (void)nrfx_gpiote_channel_free(gpiote_palna, gpiote_ch_palna); #endif #if defined(NRF_GPIO_PDN_PIN) - (void)nrfx_gpiote_channel_free(&gpiote_pdn, gpiote_ch_pdn); + (void)nrfx_gpiote_channel_free(gpiote_pdn, gpiote_ch_pdn); #endif } #if defined(HAL_RADIO_GPIO_HAVE_PA_PIN) void radio_gpio_pa_setup(void) { - gpiote_palna.p_reg->CONFIG[gpiote_ch_palna] = + gpiote_palna->p_reg->CONFIG[gpiote_ch_palna] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | (NRF_GPIO_PA_PSEL << @@ -1978,7 +1979,7 @@ void radio_gpio_pa_setup(void) #if defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) void radio_gpio_lna_setup(void) { - gpiote_palna.p_reg->CONFIG[gpiote_ch_palna] = + gpiote_palna->p_reg->CONFIG[gpiote_ch_palna] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | (NRF_GPIO_LNA_PSEL << @@ -1998,7 +1999,7 @@ void radio_gpio_pdn_setup(void) { /* Note: the pdn-gpios property is optional. */ #if defined(NRF_GPIO_PDN) - gpiote_pdn.p_reg->CONFIG[gpiote_ch_pdn] = + gpiote_pdn->p_reg->CONFIG[gpiote_ch_pdn] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | (NRF_GPIO_PDN_PSEL << @@ -2052,12 +2053,12 @@ void radio_gpio_pa_lna_disable(void) BIT(HAL_DISABLE_PALNA_PPI) | BIT(HAL_ENABLE_FEM_PPI) | BIT(HAL_DISABLE_FEM_PPI)); - gpiote_palna.p_reg->CONFIG[gpiote_ch_palna] = 0; - gpiote_pdn.p_reg->CONFIG[gpiote_ch_pdn] = 0; + gpiote_palna->p_reg->CONFIG[gpiote_ch_palna] = 0; + gpiote_pdn->p_reg->CONFIG[gpiote_ch_pdn] = 0; #else hal_radio_nrf_ppi_channels_disable(BIT(HAL_ENABLE_PALNA_PPI) | BIT(HAL_DISABLE_PALNA_PPI)); - gpiote_palna.p_reg->CONFIG[gpiote_ch_palna] = 0; + gpiote_palna->p_reg->CONFIG[gpiote_ch_palna] = 0; #endif } #endif /* HAL_RADIO_GPIO_HAVE_PA_PIN || HAL_RADIO_GPIO_HAVE_LNA_PIN */ diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_gpiote.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_gpiote.h index 428bcb869687..4e3729ad7748 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_gpiote.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi_gpiote.h @@ -18,7 +18,7 @@ static inline void hal_palna_ppi_setup(void) nrf_gpiote_task_t task; task = nrf_gpiote_out_task_get(gpiote_ch_palna); - nrf_gpiote_subscribe_set(gpiote_palna.p_reg, task, HAL_DISABLE_PALNA_PPI); + nrf_gpiote_subscribe_set(gpiote_palna->p_reg, task, HAL_DISABLE_PALNA_PPI); #endif } #endif /* defined(HAL_RADIO_GPIO_HAVE_PA_PIN) || defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) */ @@ -44,14 +44,14 @@ static inline void hal_gpiote_tasks_setup(NRF_GPIOTE_Type *gpiote, static inline void hal_pa_ppi_setup(void) { - hal_gpiote_tasks_setup(gpiote_palna.p_reg, gpiote_ch_palna, + hal_gpiote_tasks_setup(gpiote_palna->p_reg, gpiote_ch_palna, IS_ENABLED(HAL_RADIO_GPIO_PA_POL_INV), HAL_ENABLE_PALNA_PPI, HAL_DISABLE_PALNA_PPI); } static inline void hal_lna_ppi_setup(void) { - hal_gpiote_tasks_setup(gpiote_palna.p_reg, gpiote_ch_palna, + hal_gpiote_tasks_setup(gpiote_palna->p_reg, gpiote_ch_palna, IS_ENABLED(HAL_RADIO_GPIO_LNA_POL_INV), HAL_ENABLE_PALNA_PPI, HAL_DISABLE_PALNA_PPI); } @@ -63,7 +63,7 @@ static inline void hal_fem_ppi_setup(void) nrf_radio_publish_set(NRF_RADIO, NRF_RADIO_EVENT_DISABLED, HAL_DISABLE_FEM_PPI); - hal_gpiote_tasks_setup(gpiote_pdn.p_reg, gpiote_ch_pdn, + hal_gpiote_tasks_setup(gpiote_pdn->p_reg, gpiote_ch_pdn, IS_ENABLED(HAL_RADIO_GPIO_NRF21540_PDN_POL_INV), HAL_ENABLE_FEM_PPI, HAL_DISABLE_FEM_PPI); } diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_gpiote.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_gpiote.h index 268bae5aef17..b3fecbef87b8 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_gpiote.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_ppi_gpiote.h @@ -13,12 +13,12 @@ static inline void hal_palna_ppi_setup(void) NRF_PPI, HAL_ENABLE_PALNA_PPI, (uint32_t)&(EVENT_TIMER->EVENTS_COMPARE[2]), - (uint32_t)&(gpiote_palna.p_reg->TASKS_OUT[gpiote_ch_palna])); + (uint32_t)&(gpiote_palna->p_reg->TASKS_OUT[gpiote_ch_palna])); nrf_ppi_channel_endpoint_setup( NRF_PPI, HAL_DISABLE_PALNA_PPI, (uint32_t)&(NRF_RADIO->EVENTS_DISABLED), - (uint32_t)&(gpiote_palna.p_reg->TASKS_OUT[gpiote_ch_palna])); + (uint32_t)&(gpiote_palna->p_reg->TASKS_OUT[gpiote_ch_palna])); } #endif /* defined(HAL_RADIO_GPIO_HAVE_PA_PIN) || defined(HAL_RADIO_GPIO_HAVE_LNA_PIN) */ @@ -40,12 +40,12 @@ static inline void hal_fem_ppi_setup(void) NRF_PPI, HAL_ENABLE_FEM_PPI, (uint32_t)&(EVENT_TIMER->EVENTS_COMPARE[3]), - (uint32_t)&(gpiote_pdn.p_reg->TASKS_OUT[gpiote_ch_pdn])); + (uint32_t)&(gpiote_pdn->p_reg->TASKS_OUT[gpiote_ch_pdn])); nrf_ppi_channel_endpoint_setup( NRF_PPI, HAL_DISABLE_FEM_PPI, (uint32_t)&(NRF_RADIO->EVENTS_DISABLED), - (uint32_t)&(gpiote_pdn.p_reg->TASKS_OUT[gpiote_ch_pdn])); + (uint32_t)&(gpiote_pdn->p_reg->TASKS_OUT[gpiote_ch_pdn])); } #endif /* HAL_RADIO_FEM_IS_NRF21540 */ From 2ce126ad540132e48c0420e4abbe6043790b41ce Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Thu, 30 Oct 2025 20:35:52 +0100 Subject: [PATCH 09/10] [nrf fromlist] samples: boards: nordic: nrfx: align to nrfx_gpiote with extracted cb GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik --- samples/boards/nordic/nrfx/src/main.c | 39 +++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/samples/boards/nordic/nrfx/src/main.c b/samples/boards/nordic/nrfx/src/main.c index 1205bc2dcd72..bc0506cd2b5d 100644 --- a/samples/boards/nordic/nrfx/src/main.c +++ b/samples/boards/nordic/nrfx/src/main.c @@ -36,34 +36,33 @@ int main(void) { LOG_INF("nrfx_gpiote sample on %s", CONFIG_BOARD); - nrfx_err_t err; int rv; uint8_t in_channel, out_channel; nrfx_gppi_handle_t ppi_handle; - const nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(GPIOTE_INST); + static nrfx_gpiote_t gpiote = NRFX_GPIOTE_INSTANCE(NRF_GPIOTE_INST_GET(GPIOTE_INST)); /* Connect GPIOTE instance IRQ to irq handler */ - IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), nrfx_isr, - NRFX_CONCAT(nrfx_gpiote_, GPIOTE_INST, _irq_handler), 0); + IRQ_CONNECT(DT_IRQN(GPIOTE_NODE), DT_IRQ(GPIOTE_NODE, priority), nrfx_gpiote_irq_handler, + &gpiote, 0); /* Initialize GPIOTE (the interrupt priority passed as the parameter * here is ignored, see nrfx_glue.h). */ - err = nrfx_gpiote_init(&gpiote, 0); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_gpiote_init error: 0x%08X", err); + rv = nrfx_gpiote_init(&gpiote, 0); + if (rv != 0) { + LOG_ERR("nrfx_gpiote_init error: %d", rv); return 0; } - err = nrfx_gpiote_channel_alloc(&gpiote, &in_channel); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to allocate in_channel, error: 0x%08X", err); + rv = nrfx_gpiote_channel_alloc(&gpiote, &in_channel); + if (rv != 0) { + LOG_ERR("Failed to allocate in_channel, error: %d", rv); return 0; } - err = nrfx_gpiote_channel_alloc(&gpiote, &out_channel); - if (err != NRFX_SUCCESS) { - LOG_ERR("Failed to allocate out_channel, error: 0x%08X", err); + rv = nrfx_gpiote_channel_alloc(&gpiote, &out_channel); + if (rv != 0) { + LOG_ERR("Failed to allocate out_channel, error: %d", rv); return 0; } @@ -84,10 +83,10 @@ int main(void) .p_handler_config = &handler_config }; - err = nrfx_gpiote_input_configure(&gpiote, INPUT_PIN, &input_config); + rv = nrfx_gpiote_input_configure(&gpiote, INPUT_PIN, &input_config); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_gpiote_input_configure error: 0x%08X", err); + if (rv != 0) { + LOG_ERR("nrfx_gpiote_input_configure error: %d", rv); return 0; } @@ -104,11 +103,11 @@ int main(void) .polarity = NRF_GPIOTE_POLARITY_TOGGLE, .init_val = 1, }; - err = nrfx_gpiote_output_configure(&gpiote, OUTPUT_PIN, + rv = nrfx_gpiote_output_configure(&gpiote, OUTPUT_PIN, &output_config, &task_config); - if (err != NRFX_SUCCESS) { - LOG_ERR("nrfx_gpiote_output_configure error: 0x%08X", err); + if (rv != 0) { + LOG_ERR("nrfx_gpiote_output_configure error: %d", rv); return 0; } @@ -125,7 +124,7 @@ int main(void) nrfx_gpiote_out_task_address_get(&gpiote, OUTPUT_PIN), &ppi_handle); if (rv < 0) { - LOG_ERR("nrfx_gppi_conn_alloc error: 0x%08X", rv); + LOG_ERR("nrfx_gppi_conn_alloc error: %d", rv); return 0; } From fd6783b5a2fee453665f19a11806445f62a8fa82 Mon Sep 17 00:00:00 2001 From: Nikodem Kastelik Date: Fri, 31 Oct 2025 11:29:16 +0100 Subject: [PATCH 10/10] [nrf fromlist] tests: boards: nrf: i2c_slave: fix incorrect error code Errno codes are returned now. Upstream PR #: 98569 Signed-off-by: Nikodem Kastelik --- tests/boards/nrf/i2c/i2c_slave/src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/boards/nrf/i2c/i2c_slave/src/main.c b/tests/boards/nrf/i2c/i2c_slave/src/main.c index 37552b705ec1..dccc39762c30 100644 --- a/tests/boards/nrf/i2c/i2c_slave/src/main.c +++ b/tests/boards/nrf/i2c/i2c_slave/src/main.c @@ -80,7 +80,7 @@ static void *test_setup(void) }; int ret; - zassert_equal(NRFX_SUCCESS, nrfx_twis_init(&twis, &config, i2s_slave_handler), + zassert_equal(0, nrfx_twis_init(&twis, &config, i2s_slave_handler), "TWIS initialization failed"); PINCTRL_DT_DEFINE(NODE_TWIS);