drivers: nrf: add build asserts for memory-regions property

Add build asserts for "memory-regions" property in nrf drivers which is
required on targets with DMM for saadc, pdm, pwm, twim, twim_rtio, twis,
tdm, uarte, spim and spis. On targets where the property is not required
the assertion macro expands to nothing.

Signed-off-by: Michał Bainczyk <michal.bainczyk@nordicsemi.no>
This commit is contained in:
Michał Bainczyk 2025-07-14 15:30:25 +02:00 committed by Chris Friedt
parent ccf7f72e6c
commit 2e06c4ed20
11 changed files with 24 additions and 0 deletions

View File

@ -709,5 +709,7 @@ static DEVICE_API(adc, adc_nrfx_driver_api) = {
/* Validate configuration of all channels. */ /* Validate configuration of all channels. */
DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG) DT_FOREACH_CHILD(DT_DRV_INST(0), VALIDATE_CHANNEL_CONFIG)
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(DT_DRV_INST(0));
DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL, DEVICE_DT_INST_DEFINE(0, init_saadc, NULL, NULL, NULL, POST_KERNEL,
CONFIG_ADC_INIT_PRIORITY, &adc_nrfx_driver_api); CONFIG_ADC_INIT_PRIORITY, &adc_nrfx_driver_api);

View File

@ -730,6 +730,7 @@ static const struct _dmic_ops dmic_ops = {
.clk_src = PDM_CLK_SRC(idx), \ .clk_src = PDM_CLK_SRC(idx), \
.mem_reg = DMM_DEV_TO_REG(PDM(idx)), \ .mem_reg = DMM_DEV_TO_REG(PDM(idx)), \
}; \ }; \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(PDM(idx)); \
BUILD_ASSERT(PDM_CLK_SRC(idx) != ACLK || \ BUILD_ASSERT(PDM_CLK_SRC(idx) != ACLK || \
NRF_PDM_HAS_SELECTABLE_CLOCK, \ NRF_PDM_HAS_SELECTABLE_CLOCK, \
"Clock source ACLK is not available."); \ "Clock source ACLK is not available."); \

View File

@ -253,6 +253,7 @@ static DEVICE_API(i2c, i2c_nrfx_twim_driver_api) = {
#define I2C_NRFX_TWIM_DEVICE(idx) \ #define I2C_NRFX_TWIM_DEVICE(idx) \
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(I2C(idx)); \
BUILD_ASSERT(I2C_FREQUENCY(idx) != \ BUILD_ASSERT(I2C_FREQUENCY(idx) != \
I2C_NRFX_TWIM_INVALID_FREQUENCY, \ I2C_NRFX_TWIM_INVALID_FREQUENCY, \
"Wrong I2C " #idx " frequency setting in dts"); \ "Wrong I2C " #idx " frequency setting in dts"); \

View File

@ -254,6 +254,7 @@ static int i2c_nrfx_twim_rtio_deinit(const struct device *dev)
#define I2C_NRFX_TWIM_RTIO_DEVICE(idx) \ #define I2C_NRFX_TWIM_RTIO_DEVICE(idx) \
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(I2C(idx)); \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(I2C(idx)); \
BUILD_ASSERT(I2C_FREQUENCY(idx) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \ BUILD_ASSERT(I2C_FREQUENCY(idx) != I2C_NRFX_TWIM_INVALID_FREQUENCY, \
"Wrong I2C " #idx " frequency setting in dts"); \ "Wrong I2C " #idx " frequency setting in dts"); \
static void irq_connect##idx(void) \ static void irq_connect##idx(void) \

View File

@ -325,6 +325,7 @@ static int shim_nrf_twis_deinit(const struct device *dev)
_CONCAT_4(shim_nrf_twis_, name, _, id) _CONCAT_4(shim_nrf_twis_, name, _, id)
#define SHIM_NRF_TWIS_DEVICE_DEFINE(id) \ #define SHIM_NRF_TWIS_DEVICE_DEFINE(id) \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(SHIM_NRF_TWIS_NODE(id)); \
static void SHIM_NRF_TWIS_NAME(id, irq_connect)(void) \ static void SHIM_NRF_TWIS_NAME(id, irq_connect)(void) \
{ \ { \
IRQ_CONNECT( \ IRQ_CONNECT( \

View File

@ -1192,6 +1192,7 @@ static DEVICE_API(i2s, tdm_nrf_drv_api) = {
BUILD_ASSERT((TDM_SCK_CLK_SRC(idx) != ACLK && TDM_MCK_CLK_SRC(idx) != ACLK) || \ BUILD_ASSERT((TDM_SCK_CLK_SRC(idx) != ACLK && TDM_MCK_CLK_SRC(idx) != ACLK) || \
DT_NODE_HAS_STATUS_OKAY(NODE_ACLK), \ DT_NODE_HAS_STATUS_OKAY(NODE_ACLK), \
"Clock source ACLK requires the audiopll node."); \ "Clock source ACLK requires the audiopll node."); \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(TDM(idx)); \
DEVICE_DT_DEFINE(TDM(idx), tdm_nrf_init##idx, NULL, &tdm_nrf_data##idx, &tdm_nrf_cfg##idx, \ DEVICE_DT_DEFINE(TDM(idx), tdm_nrf_init##idx, NULL, &tdm_nrf_data##idx, &tdm_nrf_cfg##idx, \
POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, &tdm_nrf_drv_api); POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, &tdm_nrf_drv_api);

View File

@ -496,6 +496,7 @@ static int pwm_nrfx_init(const struct device *dev)
#define PWM_NRFX_DEVICE(idx) \ #define PWM_NRFX_DEVICE(idx) \
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(PWM(idx)); \ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(PWM(idx)); \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(PWM(idx)); \
static struct pwm_nrfx_data pwm_nrfx_##idx##_data; \ static struct pwm_nrfx_data pwm_nrfx_##idx##_data; \
static uint16_t pwm_##idx##_seq_values[NRF_PWM_CHANNEL_COUNT] \ static uint16_t pwm_##idx##_seq_values[NRF_PWM_CHANNEL_COUNT] \
PWM_MEMORY_SECTION(idx); \ PWM_MEMORY_SECTION(idx); \

View File

@ -2714,6 +2714,7 @@ static int uarte_instance_init(const struct device *dev,
#define UART_NRF_UARTE_DEVICE(idx) \ #define UART_NRF_UARTE_DEVICE(idx) \
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(UARTE(idx)); \ NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(UARTE(idx)); \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(UARTE(idx)); \
UARTE_INT_DRIVEN(idx); \ UARTE_INT_DRIVEN(idx); \
PINCTRL_DT_DEFINE(UARTE(idx)); \ PINCTRL_DT_DEFINE(UARTE(idx)); \
IF_ENABLED(CONFIG_UART_##idx##_ASYNC, ( \ IF_ENABLED(CONFIG_UART_##idx##_ASYNC, ( \

View File

@ -912,6 +912,7 @@ static int spi_nrfx_deinit(const struct device *dev)
#define SPI_NRFX_SPIM_DEFINE(idx) \ #define SPI_NRFX_SPIM_DEFINE(idx) \
NRF_DT_CHECK_NODE_HAS_PINCTRL_SLEEP(SPIM(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) \ static void irq_connect##idx(void) \
{ \ { \
IRQ_CONNECT(DT_IRQN(SPIM(idx)), DT_IRQ(SPIM(idx), priority), \ IRQ_CONNECT(DT_IRQN(SPIM(idx)), DT_IRQ(SPIM(idx), priority), \

View File

@ -571,6 +571,7 @@ static int spi_nrfx_init(const struct device *dev)
} }
#define SPI_NRFX_SPIS_DEFINE(idx) \ #define SPI_NRFX_SPIS_DEFINE(idx) \
NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(SPIS(idx)); \
static void irq_connect##idx(void) \ static void irq_connect##idx(void) \
{ \ { \
IRQ_CONNECT(DT_IRQN(SPIS(idx)), DT_IRQ(SPIS(idx), priority), \ IRQ_CONNECT(DT_IRQN(SPIS(idx)), DT_IRQ(SPIS(idx), priority), \

View File

@ -236,6 +236,19 @@
DT_PINCTRL_HAS_NAME(node_id, sleep), \ DT_PINCTRL_HAS_NAME(node_id, sleep), \
DT_NODE_PATH(node_id) " defined without sleep state") DT_NODE_PATH(node_id) " defined without sleep state")
/**
* Error out the build if CONFIG_HAS_NORDIC_DMM=y and memory-regions property is not defined
* or the status of the selected memory region is not "okay"
*
* @param node Devicetree node.
*/
#define NRF_DT_CHECK_NODE_HAS_REQUIRED_MEMORY_REGIONS(node_id) \
IF_ENABLED(CONFIG_HAS_NORDIC_DMM, \
(BUILD_ASSERT(( \
DT_NODE_HAS_PROP(node_id, memory_regions) && \
DT_NODE_HAS_STATUS_OKAY(DT_PHANDLE_BY_IDX(node_id, memory_regions, 0))), \
DT_NODE_PATH(node_id) " defined without memory regions")))
/** @brief Get clock frequency that is used for the given node. /** @brief Get clock frequency that is used for the given node.
* *
* Macro checks if node has clock property and if yes then if clock has clock_frequency property * Macro checks if node has clock property and if yes then if clock has clock_frequency property