From 44dfe5fd30a9ab35ac01b90987944e8d3ca1df26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Tue, 9 Sep 2025 10:34:08 +0200 Subject: [PATCH 1/4] [nrf fromlist] drivers: spi: spi_nrfx_spim: use standard instantiation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Used API for standard instantiation and replaced nrfx_err_t error values with errno. Upstream PR #: 96792 Signed-off-by: Michał Stasiak --- drivers/spi/spi_nrfx_spim.c | 183 ++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 101 deletions(-) diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 447c0e54fba..43eae6c1079 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#define DT_DRV_COMPAT nordic_nrf_spim + #include #include #include @@ -41,36 +43,21 @@ LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL); #define SPI_BUFFER_IN_RAM 1 #endif -/* - * We use NODELABEL here because the nrfx API requires us to call - * functions which are named according to SoC peripheral instance - * being operated on. Since DT_INST() makes no guarantees about that, - * it won't work. - */ -#define SPIM(idx) DT_NODELABEL(spi##idx) -#define SPIM_PROP(idx, prop) DT_PROP(SPIM(idx), prop) -#define SPIM_HAS_PROP(idx, prop) DT_NODE_HAS_PROP(SPIM(idx), prop) - -/* Execute macro f(x) for all instances. */ -#define SPIM_FOR_EACH_INSTANCE(f, sep, off_code, ...) \ - NRFX_FOREACH_PRESENT(SPIM, f, sep, off_code, __VA_ARGS__) - /* Only CPUAPP and CPURAD can control clocks and power domains, so if a fast instance is * used by other cores, treat the SPIM like a normal one. This presumes the CPUAPP or CPURAD * have requested the clocks and power domains needed by the fast instance to be ACTIVE before * other cores use the fast instance. */ #if CONFIG_SOC_NRF54H20_CPUAPP || CONFIG_SOC_NRF54H20_CPURAD -#define INSTANCE_IS_FAST(unused, prefix, idx, _) \ - UTIL_AND( \ - UTIL_AND( \ - IS_ENABLED(CONFIG_HAS_HW_NRF_SPIM##prefix##idx), \ - NRF_DT_IS_FAST(SPIM(idx)) \ - ), \ - IS_ENABLED(CONFIG_CLOCK_CONTROL) \ +#define INSTANCE_IS_FAST(inst) \ + UTIL_AND( \ + NRF_DT_INST_IS_FAST(inst), \ + IS_ENABLED(CONFIG_CLOCK_CONTROL) \ ) -#if SPIM_FOR_EACH_INSTANCE(INSTANCE_IS_FAST, (||), (0)) +#define INSTANCE_IS_FAST_OR(inst) INSTANCE_IS_FAST(inst) || + +#if (DT_INST_FOREACH_STATUS_OKAY(INSTANCE_IS_FAST_OR) 0) #define SPIM_ANY_FAST 1 /* If fast instances are used then system managed device PM cannot be used because * it may call PM actions from locked context and fast SPIM PM actions can only be @@ -80,12 +67,12 @@ BUILD_ASSERT(!IS_ENABLED(CONFIG_PM_DEVICE_SYSTEM_MANAGED)); #endif #endif -#define SPIM_PINS_CROSS_DOMAIN(unused, prefix, idx, _) \ - COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(SPIM(prefix##idx)), \ - (SPIM_PROP(idx, cross_domain_pins_supported)), \ - (0)) +#define SPIM_PINS_CROSS_DOMAIN(inst) \ + DT_INST_PROP(inst, cross_domain_pins_supported) -#if NRFX_FOREACH_PRESENT(SPIM, SPIM_PINS_CROSS_DOMAIN, (||), (0)) +#define SPIM_PINS_CROSS_DOMAIN_OR(inst) SPIM_PINS_CROSS_DOMAIN(inst) || + +#if (DT_INST_FOREACH_STATUS_OKAY(SPIM_PINS_CROSS_DOMAIN_OR) 0) #include /* Certain SPIM instances support usage of cross domain pins in form of dedicated pins on * a port different from the default one. @@ -103,6 +90,7 @@ BUILD_ASSERT(!IS_ENABLED(CONFIG_PM_DEVICE_SYSTEM_MANAGED)); struct spi_nrfx_data { + nrfx_spim_t spim; struct spi_context ctx; const struct device *dev; size_t chunk_len; @@ -123,7 +111,6 @@ struct spi_nrfx_data { }; struct spi_nrfx_config { - nrfx_spim_t spim; uint32_t max_freq; nrfx_spim_config_t def_config; void (*irq_connect)(void); @@ -221,8 +208,7 @@ static bool spim_has_cross_domain_connection(const struct spi_nrfx_config *confi static inline void finalize_spi_transaction(const struct device *dev, bool deactivate_cs) { struct spi_nrfx_data *dev_data = dev->data; - const struct spi_nrfx_config *dev_config = dev->config; - void *reg = dev_config->spim.p_reg; + void *reg = dev_data->spim.p_reg; if (deactivate_cs) { spi_context_cs_control(&dev_data->ctx, false); @@ -301,7 +287,7 @@ static int configure(const struct device *dev, struct spi_context *ctx = &dev_data->ctx; uint32_t max_freq = dev_config->max_freq; nrfx_spim_config_t config; - nrfx_err_t result; + int result; uint32_t sck_pin; if (dev_data->initialized && spi_context_configured(ctx, spi_cfg)) { @@ -359,22 +345,22 @@ static int configure(const struct device *dev, config.mode = get_nrf_spim_mode(spi_cfg->operation); config.bit_order = get_nrf_spim_bit_order(spi_cfg->operation); - sck_pin = nrfy_spim_sck_pin_get(dev_config->spim.p_reg); + sck_pin = nrfy_spim_sck_pin_get(dev_data->spim.p_reg); if (sck_pin != NRF_SPIM_PIN_NOT_CONNECTED) { nrfy_gpio_pin_write(sck_pin, spi_cfg->operation & SPI_MODE_CPOL ? 1 : 0); } if (dev_data->initialized) { - nrfx_spim_uninit(&dev_config->spim); + nrfx_spim_uninit(&dev_data->spim); dev_data->initialized = false; } - result = nrfx_spim_init(&dev_config->spim, &config, + result = nrfx_spim_init(&dev_data->spim, &config, event_handler, (void *)dev); - if (result != NRFX_SUCCESS) { - LOG_ERR("Failed to initialize nrfx driver: %08x", result); - return -EIO; + if (result < 0) { + LOG_ERR("Failed to initialize nrfx driver: %d", result); + return result; } dev_data->initialized = true; @@ -496,7 +482,6 @@ static void transfer_next_chunk(const struct device *dev) if (chunk_len > 0) { nrfx_spim_xfer_desc_t xfer; - nrfx_err_t result; const uint8_t *tx_buf = ctx->tx_buf; uint8_t *rx_buf = ctx->rx_buf; @@ -506,7 +491,7 @@ static void transfer_next_chunk(const struct device *dev) #ifdef SPI_BUFFER_IN_RAM if (spi_context_tx_buf_on(ctx) && - !nrf_dma_accessible_check(&dev_config->spim.p_reg, tx_buf)) { + !nrf_dma_accessible_check(&dev_data->spim.p_reg, tx_buf)) { if (chunk_len > CONFIG_SPI_NRFX_RAM_BUFFER_SIZE) { chunk_len = CONFIG_SPI_NRFX_RAM_BUFFER_SIZE; @@ -517,7 +502,7 @@ static void transfer_next_chunk(const struct device *dev) } if (spi_context_rx_buf_on(ctx) && - !nrf_dma_accessible_check(&dev_config->spim.p_reg, rx_buf)) { + !nrf_dma_accessible_check(&dev_data->spim.p_reg, rx_buf)) { if (chunk_len > CONFIG_SPI_NRFX_RAM_BUFFER_SIZE) { chunk_len = CONFIG_SPI_NRFX_RAM_BUFFER_SIZE; @@ -556,11 +541,10 @@ static void transfer_next_chunk(const struct device *dev) } #endif if (error == 0) { - result = nrfx_spim_xfer(&dev_config->spim, &xfer, 0); - if (result == NRFX_SUCCESS) { + error = nrfx_spim_xfer(&dev_data->spim, &xfer, 0); + if (error == 0) { return; } - error = -EIO; #ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58 anomaly_58_workaround_clear(dev_data); #endif @@ -632,7 +616,7 @@ static int transceive(const struct device *dev, { struct spi_nrfx_data *dev_data = dev->data; const struct spi_nrfx_config *dev_config = dev->config; - void *reg = dev_config->spim.p_reg; + void *reg = dev_data->spim.p_reg; int error; pm_device_runtime_get(dev); @@ -678,7 +662,7 @@ static int transceive(const struct device *dev, /* Abort the current transfer by deinitializing * the nrfx driver. */ - nrfx_spim_uninit(&dev_config->spim); + nrfx_spim_uninit(&dev_data->spim); dev_data->initialized = false; /* Make sure the transaction is finished (it may be @@ -795,7 +779,7 @@ static void spim_suspend(const struct device *dev) struct spi_nrfx_data *dev_data = dev->data; if (dev_data->initialized) { - nrfx_spim_uninit(&dev_config->spim); + nrfx_spim_uninit(&dev_data->spim); dev_data->initialized = false; } @@ -897,100 +881,97 @@ static int spi_nrfx_deinit(const struct device *dev) return 0; } -#define SPI_NRFX_SPIM_EXTENDED_CONFIG(idx) \ +#define SPI_NRFX_SPIM_EXTENDED_CONFIG(inst) \ IF_ENABLED(NRFX_SPIM_EXTENDED_ENABLED, \ (.dcx_pin = NRF_SPIM_PIN_NOT_CONNECTED, \ - COND_CODE_1(SPIM_PROP(idx, rx_delay_supported), \ - (.rx_delay = SPIM_PROP(idx, rx_delay),), \ + COND_CODE_1(DT_INST_PROP(inst, rx_delay_supported), \ + (.rx_delay = DT_INST_PROP(inst, rx_delay),), \ ()) \ )) /* Get initialization priority of an instance. Instances that requires clock control * which is using nrfs (IPC) are initialized later. */ -#define SPIM_INIT_PRIORITY(idx) \ - COND_CODE_1(INSTANCE_IS_FAST(_, /*empty*/, idx, _), \ +#define SPIM_INIT_PRIORITY(inst) \ + COND_CODE_1(INSTANCE_IS_FAST(inst), \ (UTIL_INC(CONFIG_CLOCK_CONTROL_NRF_HSFLL_GLOBAL_INIT_PRIORITY)), \ (CONFIG_SPI_INIT_PRIORITY)) -#define SPI_NRFX_SPIM_DEFINE(idx) \ - NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(SPIM(idx)); \ - NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(SPIM(idx)); \ - static void irq_connect##idx(void) \ - { \ - IRQ_CONNECT(DT_IRQN(SPIM(idx)), DT_IRQ(SPIM(idx), priority), \ - nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \ - } \ +#define SPI_NRFX_SPIM_DEFINE(inst) \ + NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(DT_DRV_INST(inst)); \ + NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(inst)); \ IF_ENABLED(SPI_BUFFER_IN_RAM, \ - (static uint8_t spim_##idx##_tx_buffer \ + (static uint8_t spim_##inst##_tx_buffer \ [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \ - DMM_MEMORY_SECTION(SPIM(idx)); \ - static uint8_t spim_##idx##_rx_buffer \ + DMM_MEMORY_SECTION(DT_DRV_INST(inst)); \ + static uint8_t spim_##inst##_rx_buffer \ [CONFIG_SPI_NRFX_RAM_BUFFER_SIZE] \ - DMM_MEMORY_SECTION(SPIM(idx));)) \ - static struct spi_nrfx_data spi_##idx##_data = { \ + DMM_MEMORY_SECTION(DT_DRV_INST(inst));)) \ + static struct spi_nrfx_data spi_##inst##_data = { \ + .spim = NRFX_SPIM_INSTANCE(DT_INST_REG_ADDR(inst)), \ IF_ENABLED(CONFIG_MULTITHREADING, \ - (SPI_CONTEXT_INIT_LOCK(spi_##idx##_data, ctx),)) \ + (SPI_CONTEXT_INIT_LOCK(spi_##inst##_data, ctx),)) \ IF_ENABLED(CONFIG_MULTITHREADING, \ - (SPI_CONTEXT_INIT_SYNC(spi_##idx##_data, ctx),)) \ - SPI_CONTEXT_CS_GPIOS_INITIALIZE(SPIM(idx), ctx) \ + (SPI_CONTEXT_INIT_SYNC(spi_##inst##_data, ctx),)) \ + SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx) \ IF_ENABLED(SPI_BUFFER_IN_RAM, \ - (.tx_buffer = spim_##idx##_tx_buffer, \ - .rx_buffer = spim_##idx##_rx_buffer,)) \ - .dev = DEVICE_DT_GET(SPIM(idx)), \ + (.tx_buffer = spim_##inst##_tx_buffer, \ + .rx_buffer = spim_##inst##_rx_buffer,)) \ + .dev = DEVICE_DT_GET(DT_DRV_INST(inst)), \ .busy = false, \ }; \ - PINCTRL_DT_DEFINE(SPIM(idx)); \ - static const struct spi_nrfx_config spi_##idx##z_config = { \ - .spim = { \ - .p_reg = (NRF_SPIM_Type *)DT_REG_ADDR(SPIM(idx)), \ - .drv_inst_idx = NRFX_SPIM##idx##_INST_IDX, \ - }, \ - .max_freq = SPIM_PROP(idx, max_frequency), \ + static void irq_connect##inst(void) \ + { \ + IRQ_CONNECT(DT_INST_IRQN(inst), DT_INST_IRQ(inst, priority), \ + nrfx_spim_irq_handler, &spi_##inst##_data.spim, 0); \ + } \ + PINCTRL_DT_INST_DEFINE(inst); \ + static const struct spi_nrfx_config spi_##inst##z_config = { \ + .max_freq = DT_INST_PROP(inst, max_frequency), \ .def_config = { \ .skip_gpio_cfg = true, \ .skip_psel_cfg = true, \ .ss_pin = NRF_SPIM_PIN_NOT_CONNECTED, \ - .orc = SPIM_PROP(idx, overrun_character), \ - SPI_NRFX_SPIM_EXTENDED_CONFIG(idx) \ + .orc = DT_INST_PROP(inst, overrun_character), \ + SPI_NRFX_SPIM_EXTENDED_CONFIG(inst) \ }, \ - .irq_connect = irq_connect##idx, \ - .pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPIM(idx)), \ - .max_chunk_len = BIT_MASK(SPIM_PROP(idx, easydma_maxcnt_bits)),\ + .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)), \ COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \ (.anomaly_58_workaround = \ - SPIM_PROP(idx, anomaly_58_workaround),), \ + DT_INST_PROP(inst, anomaly_58_workaround),), \ ()) \ - .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPIM(idx), wake_gpios, \ + .wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(DT_DRV_INST(inst), \ + wake_gpios, \ WAKE_PIN_NOT_USED), \ - .wake_gpiote = WAKE_GPIOTE_INSTANCE(SPIM(idx)), \ + .wake_gpiote = WAKE_GPIOTE_INSTANCE(DT_DRV_INST(inst)), \ IF_ENABLED(SPIM_ANY_FAST, \ (.clk_dev = DEVICE_DT_GET_OR_NULL( \ - DT_CLOCKS_CTLR(SPIM(idx))), \ + DT_CLOCKS_CTLR(DT_DRV_INST(inst))), \ .clk_spec = { \ .frequency = NRF_CLOCK_CONTROL_FREQUENCY_MAX, \ },)) \ - IF_ENABLED(SPIM_PINS_CROSS_DOMAIN(_, /*empty*/, idx, _), \ + IF_ENABLED(SPIM_PINS_CROSS_DOMAIN(inst), \ (.cross_domain = true, \ .default_port = \ - DT_PROP_OR(DT_PHANDLE(SPIM(idx), \ + DT_PROP_OR(DT_INST_PHANDLE(inst, \ default_gpio_port), port, -1),)) \ - .mem_reg = DMM_DEV_TO_REG(SPIM(idx)), \ + .mem_reg = DMM_DEV_TO_REG(DT_DRV_INST(inst)), \ }; \ - BUILD_ASSERT(!SPIM_HAS_PROP(idx, wake_gpios) || \ - !(DT_GPIO_FLAGS(SPIM(idx), wake_gpios) & GPIO_ACTIVE_LOW),\ + BUILD_ASSERT(!DT_INST_NODE_HAS_PROP(inst, wake_gpios) || \ + !(DT_GPIO_FLAGS(DT_DRV_INST(inst), wake_gpios) & \ + GPIO_ACTIVE_LOW), \ "WAKE line must be configured as active high"); \ - PM_DEVICE_DT_DEFINE(SPIM(idx), spim_nrfx_pm_action); \ - SPI_DEVICE_DT_DEINIT_DEFINE(SPIM(idx), \ + PM_DEVICE_DT_INST_DEFINE(inst, spim_nrfx_pm_action); \ + SPI_DEVICE_DT_INST_DEINIT_DEFINE(inst, \ spi_nrfx_init, \ spi_nrfx_deinit, \ - PM_DEVICE_DT_GET(SPIM(idx)), \ - &spi_##idx##_data, \ - &spi_##idx##z_config, \ - POST_KERNEL, SPIM_INIT_PRIORITY(idx), \ + PM_DEVICE_DT_INST_GET(inst), \ + &spi_##inst##_data, \ + &spi_##inst##z_config, \ + POST_KERNEL, SPIM_INIT_PRIORITY(inst), \ &spi_nrfx_driver_api) -#define COND_NRF_SPIM_DEVICE(unused, prefix, i, _) \ - IF_ENABLED(CONFIG_HAS_HW_NRF_SPIM##prefix##i, (SPI_NRFX_SPIM_DEFINE(prefix##i);)) - -SPIM_FOR_EACH_INSTANCE(COND_NRF_SPIM_DEVICE, (), (), _) +DT_INST_FOREACH_STATUS_OKAY(SPI_NRFX_SPIM_DEFINE) From 090e92f592b17ca12edbb21ba1cf91c9078a9e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Tue, 30 Sep 2025 14:12:34 +0200 Subject: [PATCH 2/4] [nrf fromlist] modules: hal_nordic: remove SPIM symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed Kconfig symbols for each SPIM instance which are no longer needed. Upstream PR #: 96792 Signed-off-by: Michał Stasiak --- drivers/spi/Kconfig.nrfx | 24 +----- modules/hal_nordic/nrfx/Kconfig | 115 ------------------------- modules/hal_nordic/nrfx/nrfx_kconfig.h | 70 --------------- soc/nordic/common/Kconfig.peripherals | 69 --------------- soc/nordic/nrf52/Kconfig | 2 +- 5 files changed, 2 insertions(+), 278 deletions(-) diff --git a/drivers/spi/Kconfig.nrfx b/drivers/spi/Kconfig.nrfx index e609a6c4933..a0918fcd011 100644 --- a/drivers/spi/Kconfig.nrfx +++ b/drivers/spi/Kconfig.nrfx @@ -22,29 +22,7 @@ config SPI_NRFX_SPI config SPI_NRFX_SPIM def_bool y depends on DT_HAS_NORDIC_NRF_SPIM_ENABLED - select NRFX_SPIM0 if HAS_HW_NRF_SPIM0 - select NRFX_SPIM1 if HAS_HW_NRF_SPIM1 - select NRFX_SPIM2 if HAS_HW_NRF_SPIM2 - select NRFX_SPIM3 if HAS_HW_NRF_SPIM3 - select NRFX_SPIM4 if HAS_HW_NRF_SPIM4 - select NRFX_SPIM00 if HAS_HW_NRF_SPIM00 - select NRFX_SPIM01 if HAS_HW_NRF_SPIM01 - select NRFX_SPIM20 if HAS_HW_NRF_SPIM20 - select NRFX_SPIM21 if HAS_HW_NRF_SPIM21 - select NRFX_SPIM22 if HAS_HW_NRF_SPIM22 - select NRFX_SPIM23 if HAS_HW_NRF_SPIM23 - select NRFX_SPIM24 if HAS_HW_NRF_SPIM24 - select NRFX_SPIM30 if HAS_HW_NRF_SPIM30 - select NRFX_SPIM120 if HAS_HW_NRF_SPIM120 - select NRFX_SPIM121 if HAS_HW_NRF_SPIM121 - select NRFX_SPIM130 if HAS_HW_NRF_SPIM130 - select NRFX_SPIM131 if HAS_HW_NRF_SPIM131 - select NRFX_SPIM132 if HAS_HW_NRF_SPIM132 - select NRFX_SPIM133 if HAS_HW_NRF_SPIM133 - select NRFX_SPIM134 if HAS_HW_NRF_SPIM134 - select NRFX_SPIM135 if HAS_HW_NRF_SPIM135 - select NRFX_SPIM136 if HAS_HW_NRF_SPIM136 - select NRFX_SPIM137 if HAS_HW_NRF_SPIM137 + select NRFX_SPIM config SPI_NRFX_SPIS def_bool y diff --git a/modules/hal_nordic/nrfx/Kconfig b/modules/hal_nordic/nrfx/Kconfig index 523931be649..b0b10a84109 100644 --- a/modules/hal_nordic/nrfx/Kconfig +++ b/modules/hal_nordic/nrfx/Kconfig @@ -528,121 +528,6 @@ config NRFX_SPI2 config NRFX_SPIM bool -config NRFX_SPIM0 - bool "SPIM0 driver instance" - depends on $(dt_nodelabel_exists,spi0) && !SOC_SERIES_NRF51X - select NRFX_SPIM - -config NRFX_SPIM1 - bool "SPIM1 driver instance" - depends on $(dt_nodelabel_exists,spi1) && !SOC_SERIES_NRF51X - select NRFX_SPIM - -config NRFX_SPIM2 - bool "SPIM2 driver instance" - depends on $(dt_nodelabel_exists,spi2) - select NRFX_SPIM - -config NRFX_SPIM3 - bool "SPIM3 driver instance" - depends on $(dt_nodelabel_exists,spi3) - select NRFX_SPIM - -config NRFX_SPIM4 - bool "SPIM4 driver instance" - depends on $(dt_nodelabel_exists,spi4) - select NRFX_SPIM - -config NRFX_SPIM00 - bool "SPIM00 driver instance" - depends on $(dt_nodelabel_exists,spi00) - select NRFX_SPIM - -config NRFX_SPIM01 - bool "SPIM01 driver instance" - depends on $(dt_nodelabel_exists,spi01) - select NRFX_SPIM - -config NRFX_SPIM20 - bool "SPIM20 driver instance" - depends on $(dt_nodelabel_exists,spi20) - select NRFX_SPIM - -config NRFX_SPIM21 - bool "SPIM21 driver instance" - depends on $(dt_nodelabel_exists,spi21) - select NRFX_SPIM - -config NRFX_SPIM22 - bool "SPIM22 driver instance" - depends on $(dt_nodelabel_exists,spi22) - select NRFX_SPIM - -config NRFX_SPIM23 - bool "SPIM23 driver instance" - depends on $(dt_nodelabel_exists,spi23) - select NRFX_SPIM - -config NRFX_SPIM24 - bool "SPIM24 driver instance" - depends on $(dt_nodelabel_exists,spi24) - select NRFX_SPIM - -config NRFX_SPIM30 - bool "SPIM30 driver instance" - depends on $(dt_nodelabel_exists,spi30) - select NRFX_SPIM - -config NRFX_SPIM120 - bool "SPIM120 driver instance" - depends on $(dt_nodelabel_exists,spi120) - select NRFX_SPIM - -config NRFX_SPIM121 - bool "SPIM121 driver instance" - depends on $(dt_nodelabel_exists,spi121) - select NRFX_SPIM - -config NRFX_SPIM130 - bool "SPIM130 driver instance" - depends on $(dt_nodelabel_exists,spi130) - select NRFX_SPIM - -config NRFX_SPIM131 - bool "SPIM131 driver instance" - depends on $(dt_nodelabel_exists,spi131) - select NRFX_SPIM - -config NRFX_SPIM132 - bool "SPIM132 driver instance" - depends on $(dt_nodelabel_exists,spi132) - select NRFX_SPIM - -config NRFX_SPIM133 - bool "SPIM133 driver instance" - depends on $(dt_nodelabel_exists,spi133) - select NRFX_SPIM - -config NRFX_SPIM134 - bool "SPIM134 driver instance" - depends on $(dt_nodelabel_exists,spi134) - select NRFX_SPIM - -config NRFX_SPIM135 - bool "SPIM135 driver instance" - depends on $(dt_nodelabel_exists,spi135) - select NRFX_SPIM - -config NRFX_SPIM136 - bool "SPIM136 driver instance" - depends on $(dt_nodelabel_exists,spi136) - select NRFX_SPIM - -config NRFX_SPIM137 - bool "SPIM137 driver instance" - depends on $(dt_nodelabel_exists,spi137) - select NRFX_SPIM - config NRFX_SPIS bool diff --git a/modules/hal_nordic/nrfx/nrfx_kconfig.h b/modules/hal_nordic/nrfx/nrfx_kconfig.h index 4f0d594a212..72fc3113fa2 100644 --- a/modules/hal_nordic/nrfx/nrfx_kconfig.h +++ b/modules/hal_nordic/nrfx/nrfx_kconfig.h @@ -486,24 +486,9 @@ #ifdef CONFIG_NRFX_SPIM_LOG #define NRFX_SPIM_CONFIG_LOG_ENABLED 1 #endif -#ifdef CONFIG_NRFX_SPIM0 -#define NRFX_SPIM0_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM1 -#define NRFX_SPIM1_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM2 -#define NRFX_SPIM2_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM3 -#define NRFX_SPIM3_ENABLED 1 #ifdef CONFIG_NRF52_ANOMALY_198_WORKAROUND #define NRFX_SPIM3_NRF52840_ANOMALY_198_WORKAROUND_ENABLED 1 #endif -#endif -#ifdef CONFIG_NRFX_SPIM4 -#define NRFX_SPIM4_ENABLED 1 -#endif #define NRFX_SPIM_DT_HAS_RX_DELAY(node) DT_PROP(node, rx_delay_supported) + @@ -513,61 +498,6 @@ #endif #endif -#ifdef CONFIG_NRFX_SPIM00 -#define NRFX_SPIM00_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM01 -#define NRFX_SPIM01_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM20 -#define NRFX_SPIM20_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM21 -#define NRFX_SPIM21_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM22 -#define NRFX_SPIM22_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM23 -#define NRFX_SPIM23_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM24 -#define NRFX_SPIM24_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM30 -#define NRFX_SPIM30_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM120 -#define NRFX_SPIM120_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM121 -#define NRFX_SPIM121_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM130 -#define NRFX_SPIM130_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM131 -#define NRFX_SPIM131_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM132 -#define NRFX_SPIM132_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM133 -#define NRFX_SPIM133_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM134 -#define NRFX_SPIM134_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM135 -#define NRFX_SPIM135_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM136 -#define NRFX_SPIM136_ENABLED 1 -#endif -#ifdef CONFIG_NRFX_SPIM137 -#define NRFX_SPIM137_ENABLED 1 -#endif - #ifdef CONFIG_NRFX_SPIS #define NRFX_SPIS_ENABLED 1 #endif diff --git a/soc/nordic/common/Kconfig.peripherals b/soc/nordic/common/Kconfig.peripherals index fa7fd2a411a..f88ef2cc601 100644 --- a/soc/nordic/common/Kconfig.peripherals +++ b/soc/nordic/common/Kconfig.peripherals @@ -255,75 +255,6 @@ config HAS_HW_NRF_SPI1 config HAS_HW_NRF_SPI2 def_bool $(dt_nodelabel_enabled_with_compat,spi2,$(DT_COMPAT_NORDIC_NRF_SPI)) -config HAS_HW_NRF_SPIM0 - def_bool $(dt_nodelabel_enabled_with_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM1 - def_bool $(dt_nodelabel_enabled_with_compat,spi1,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM2 - def_bool $(dt_nodelabel_enabled_with_compat,spi2,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM3 - def_bool $(dt_nodelabel_enabled_with_compat,spi3,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM4 - def_bool $(dt_nodelabel_enabled_with_compat,spi4,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM00 - def_bool $(dt_nodelabel_enabled_with_compat,spi00,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM01 - def_bool $(dt_nodelabel_enabled_with_compat,spi01,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM20 - def_bool $(dt_nodelabel_enabled_with_compat,spi20,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM21 - def_bool $(dt_nodelabel_enabled_with_compat,spi21,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM22 - def_bool $(dt_nodelabel_enabled_with_compat,spi22,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM23 - def_bool $(dt_nodelabel_enabled_with_compat,spi23,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM24 - def_bool $(dt_nodelabel_enabled_with_compat,spi24,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM30 - def_bool $(dt_nodelabel_enabled_with_compat,spi30,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM120 - def_bool $(dt_nodelabel_enabled_with_compat,spi120,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM121 - def_bool $(dt_nodelabel_enabled_with_compat,spi121,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM130 - def_bool $(dt_nodelabel_enabled_with_compat,spi130,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM131 - def_bool $(dt_nodelabel_enabled_with_compat,spi131,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM132 - def_bool $(dt_nodelabel_enabled_with_compat,spi132,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM133 - def_bool $(dt_nodelabel_enabled_with_compat,spi133,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM134 - def_bool $(dt_nodelabel_enabled_with_compat,spi134,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM135 - def_bool $(dt_nodelabel_enabled_with_compat,spi135,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM136 - def_bool $(dt_nodelabel_enabled_with_compat,spi136,$(DT_COMPAT_NORDIC_NRF_SPIM)) - -config HAS_HW_NRF_SPIM137 - def_bool $(dt_nodelabel_enabled_with_compat,spi137,$(DT_COMPAT_NORDIC_NRF_SPIM)) - config HAS_HW_NRF_SPIS0 def_bool $(dt_nodelabel_enabled_with_compat,spi0,$(DT_COMPAT_NORDIC_NRF_SPIS)) diff --git a/soc/nordic/nrf52/Kconfig b/soc/nordic/nrf52/Kconfig index 65d613a59cd..4b80670a822 100644 --- a/soc/nordic/nrf52/Kconfig +++ b/soc/nordic/nrf52/Kconfig @@ -96,7 +96,7 @@ config NRF52_ANOMALY_198_WORKAROUND bool "Anomaly 198 workaround" default y depends on SOC_NRF52840 - depends on NRFX_SPIM3 + depends on NRFX_SPIM help This anomaly applies to IC revisions "Engineering B" up to "3", the most recent one. From c8bff1dd23caf71eef674a7066fc27de44a31721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Tue, 30 Sep 2025 14:17:47 +0200 Subject: [PATCH 3/4] [nrf fromlist] samples: nordic: nrfx_prs: align to spi_nrfx_spim rework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed error codes, driver instantiation and removed unnecessary symbols. Upstream PR #: 96792 Signed-off-by: Michał Stasiak --- samples/boards/nordic/nrfx_prs/prj.conf | 2 +- samples/boards/nordic/nrfx_prs/src/main.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/samples/boards/nordic/nrfx_prs/prj.conf b/samples/boards/nordic/nrfx_prs/prj.conf index 3c8ea985f56..87fbfd9e781 100644 --- a/samples/boards/nordic/nrfx_prs/prj.conf +++ b/samples/boards/nordic/nrfx_prs/prj.conf @@ -1,7 +1,7 @@ # This is needed for using SPIM2 and UARTE2 via nrfx drivers and for switching # between those peripherals, as they share the same ID and hence cannot be used # simultaneously. -CONFIG_NRFX_SPIM2=y +CONFIG_NRFX_SPIM=y CONFIG_NRFX_UARTE2=y CONFIG_NRFX_PRS_BOX_2=y diff --git a/samples/boards/nordic/nrfx_prs/src/main.c b/samples/boards/nordic/nrfx_prs/src/main.c index e9e63e574d2..804aee378b3 100644 --- a/samples/boards/nordic/nrfx_prs/src/main.c +++ b/samples/boards/nordic/nrfx_prs/src/main.c @@ -28,7 +28,7 @@ */ #define SPI_DEV_NODE DT_NODELABEL(spi1) -static nrfx_spim_t spim = NRFX_SPIM_INSTANCE(2); +static nrfx_spim_t spim = NRFX_SPIM_INSTANCE(NRF_SPIM2); static nrfx_uarte_t uarte = NRFX_UARTE_INSTANCE(2); static bool spim_initialized; static bool uarte_initialized; @@ -121,7 +121,6 @@ static void spim_handler(const nrfx_spim_evt_t *p_event, void *p_context) static bool switch_to_spim(void) { int ret; - nrfx_err_t err; uint32_t sck_pin; PINCTRL_DT_DEFINE(SPIM_NODE); @@ -162,9 +161,9 @@ static bool switch_to_spim(void) nrfy_gpio_pin_write(sck_pin, (spim_config.mode <= NRF_SPIM_MODE_1) ? 0 : 1); } - err = nrfx_spim_init(&spim, &spim_config, spim_handler, NULL); - if (err != NRFX_SUCCESS) { - printk("nrfx_spim_init() failed: 0x%08x\n", err); + ret = nrfx_spim_init(&spim, &spim_config, spim_handler, NULL); + if (ret != 0) { + printk("nrfx_spim_init() failed: %d", ret); return false; } @@ -176,7 +175,7 @@ static bool switch_to_spim(void) static bool spim_transfer(const uint8_t *tx_data, size_t tx_data_len, uint8_t *rx_buf, size_t rx_buf_size) { - nrfx_err_t err; + int err; nrfx_spim_xfer_desc_t xfer_desc = { .p_tx_buffer = tx_data, .tx_length = tx_data_len, @@ -185,8 +184,8 @@ static bool spim_transfer(const uint8_t *tx_data, size_t tx_data_len, }; err = nrfx_spim_xfer(&spim, &xfer_desc, 0); - if (err != NRFX_SUCCESS) { - printk("nrfx_spim_xfer() failed: 0x%08x\n", err); + if (err != 0) { + printk("nrfx_spim_xfer() failed: %d\n", err); return false; } From 9d6f7cbeda19be2596d8751c62640eb403da7fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Stasiak?= Date: Tue, 30 Sep 2025 12:56:52 +0200 Subject: [PATCH 4/4] [nrf fromlist] modules: hal_nordic: add new errno error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addded macro responsible for translating new errno error codes to strings. Upstream PR #: 96792 Signed-off-by: Michał Stasiak --- modules/hal_nordic/nrfx/nrfx_glue.c | 22 ++++++++++++++++++++++ modules/hal_nordic/nrfx/nrfx_log.h | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/modules/hal_nordic/nrfx/nrfx_glue.c b/modules/hal_nordic/nrfx/nrfx_glue.c index 4e7fc94e11d..dd972ee039d 100644 --- a/modules/hal_nordic/nrfx/nrfx_glue.c +++ b/modules/hal_nordic/nrfx/nrfx_glue.c @@ -45,3 +45,25 @@ char const *nrfx_error_string_get(nrfx_err_t code) default: return "unknown"; } } + +char const *nrfx_new_error_string_get(int code) +{ + #define NRFX_NEW_ERROR_STRING_CASE(code) case code: return #code + switch (-code) + { + NRFX_NEW_ERROR_STRING_CASE(0); + NRFX_NEW_ERROR_STRING_CASE(ECANCELED); + NRFX_NEW_ERROR_STRING_CASE(ENOMEM); + NRFX_NEW_ERROR_STRING_CASE(ENOTSUP); + NRFX_NEW_ERROR_STRING_CASE(EINVAL); + NRFX_NEW_ERROR_STRING_CASE(EINPROGRESS); + NRFX_NEW_ERROR_STRING_CASE(E2BIG); + NRFX_NEW_ERROR_STRING_CASE(ETIMEDOUT); + NRFX_NEW_ERROR_STRING_CASE(EPERM); + NRFX_NEW_ERROR_STRING_CASE(EFAULT); + NRFX_NEW_ERROR_STRING_CASE(EACCES); + NRFX_NEW_ERROR_STRING_CASE(EBUSY); + NRFX_NEW_ERROR_STRING_CASE(EALREADY); + default: return "unknown"; + } +} diff --git a/modules/hal_nordic/nrfx/nrfx_log.h b/modules/hal_nordic/nrfx/nrfx_log.h index 682388d7dd1..973ca672b53 100644 --- a/modules/hal_nordic/nrfx/nrfx_log.h +++ b/modules/hal_nordic/nrfx/nrfx_log.h @@ -128,6 +128,16 @@ LOG_MODULE_REGISTER(NRFX_MODULE_PREFIX, NRFX_MODULE_LOG_LEVEL); #define NRFX_LOG_ERROR_STRING_GET(error_code) nrfx_error_string_get(error_code) extern char const *nrfx_error_string_get(nrfx_err_t code); +/** + * @brief Macro for getting the textual representation of a given errno error code. + * + * @param[in] error_code Errno error code. + * + * @return String containing the textual representation of the errno error code. + */ +#define NRFX_NEW_LOG_ERROR_STRING_GET(error_code) nrfx_new_error_string_get(error_code) +extern char const *nrfx_new_error_string_get(int code); + /** @} */ #ifdef __cplusplus