Skip to content
31 changes: 15 additions & 16 deletions drivers/clock_control/clock_stm32_mco.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,20 @@ static int stm32_mco_init(const struct device *dev)
return pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
}

#define STM32_MCO_INIT(inst) \
\
PINCTRL_DT_INST_DEFINE(inst); \
\
const static struct stm32_mco_config stm32_mco_config_##inst = { \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.pclken = STM32_DT_INST_CLOCKS(inst), \
IF_ENABLED(HAS_PRESCALER, \
(.prescaler = DT_PROP(DT_DRV_INST(inst), prescaler),)) \
}; \
\
DEVICE_DT_INST_DEFINE(inst, stm32_mco_init, NULL, \
NULL, \
&stm32_mco_config_##inst, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
NULL);
#define STM32_MCO_INIT(inst) \
\
PINCTRL_DT_INST_DEFINE(inst); \
Comment on lines +73 to +74
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\
PINCTRL_DT_INST_DEFINE(inst); \
PINCTRL_DT_INST_DEFINE(inst); \

Unless there's a rationale for the empty line I missed?

\
const static struct stm32_mco_config stm32_mco_config_##inst = { \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.pclken = STM32_DT_INST_CLOCKS(inst), \
IF_ENABLED(HAS_PRESCALER, \
(.prescaler = DT_PROP(DT_DRV_INST(inst), prescaler),)) \
}; \
\
DEVICE_DT_INST_DEFINE(inst, stm32_mco_init, NULL, NULL, \
&stm32_mco_config_##inst, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
NULL);

DT_INST_FOREACH_STATUS_OKAY(STM32_MCO_INIT);
20 changes: 10 additions & 10 deletions drivers/clock_control/clock_stm32_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ static int stm32_clk_mux_init(const struct device *dev)
return 0;
}

#define STM32_MUX_CLK_INIT(id) \
\
static const struct stm32_clk_mux_config stm32_clk_mux_cfg_##id = { \
.pclken = STM32_CLOCK_INFO(0, DT_DRV_INST(id)) \
}; \
\
DEVICE_DT_INST_DEFINE(id, stm32_clk_mux_init, NULL, \
NULL, &stm32_clk_mux_cfg_##id, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS,\
NULL);
#define STM32_MUX_CLK_INIT(id) \
\
Comment on lines +37 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#define STM32_MUX_CLK_INIT(id) \
\
#define STM32_MUX_CLK_INIT(id) \

static const struct stm32_clk_mux_config stm32_clk_mux_cfg_##id = { \
.pclken = STM32_CLOCK_INFO(0, DT_DRV_INST(id)) \
}; \
\
DEVICE_DT_INST_DEFINE(id, stm32_clk_mux_init, NULL, \
NULL, &stm32_clk_mux_cfg_##id, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS,\
NULL);

DT_INST_FOREACH_STATUS_OKAY(STM32_MUX_CLK_INIT)
15 changes: 7 additions & 8 deletions drivers/disk/sdmmc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,19 +931,18 @@ void stm32_sdmmc_get_card_csd(const struct device *dev, uint32_t csd[4])
STM32_DMA_CHANNEL_CONFIG(0, dir)), \
.dma_callback = stm32_sdmmc_dma_cb, \
.linked_channel = STM32_DMA_HAL_OVERRIDE, \
}, \

},

#define SDMMC_DMA_CHANNEL(dir, DIR) \
.dma_##dir = { \
COND_CODE_1(DT_INST_DMAS_HAS_NAME(0, dir), \
(SDMMC_DMA_CHANNEL_INIT(dir, DIR)), \
(NULL)) \
.dma_##dir = { \
COND_CODE_1(DT_INST_DMAS_HAS_NAME(0, dir), \
(SDMMC_DMA_CHANNEL_INIT(dir, DIR)), \
(NULL)) \
},

#else
#else /* STM32_SDMMC_USE_DMA */
#define SDMMC_DMA_CHANNEL(dir, DIR)
#endif
#endif /* STM32_SDMMC_USE_DMA */

PINCTRL_DT_INST_DEFINE(0);

Expand Down
99 changes: 49 additions & 50 deletions drivers/i2c/i2c_ll_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ void i2c_stm32_smbalert_disable(const struct device *dev)
(DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)), \
.dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
(DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)), \
},
},

void i2c_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
uint32_t channel, int status)
Expand Down Expand Up @@ -498,73 +498,72 @@ void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
#define I2C_DMA_DATA_INIT(index, dir, src, dest) \
IF_ENABLED(DT_INST_DMAS_HAS_NAME(index, dir), \
(.dma_##dir##_cfg = { \
.dma_slot = STM32_DMA_SLOT(index, dir, slot), \
.channel_direction = STM32_DMA_CONFIG_DIRECTION( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.cyclic = STM32_DMA_CONFIG_CYCLIC( \
.dma_slot = STM32_DMA_SLOT(index, dir, slot), \
.channel_direction = STM32_DMA_CONFIG_DIRECTION( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.channel_priority = STM32_DMA_CONFIG_PRIORITY( \
.cyclic = STM32_DMA_CONFIG_CYCLIC( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
.channel_priority = STM32_DMA_CONFIG_PRIORITY( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.source_burst_length = 1, \
.dest_burst_length = 1, \
.dma_callback = i2c_stm32_dma_##dir##_cb, \
},))
.source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
.source_burst_length = 1, \
.dest_burst_length = 1, \
.dma_callback = i2c_stm32_dma_##dir##_cb, \
},))

#else
#else /* CONFIG_I2C_STM32_V2_DMA */

#define I2C_DMA_INIT(index, dir)
#define I2C_DMA_DATA_INIT(index, dir, src, dest)

#endif /* CONFIG_I2C_STM32_V2_DMA */

#define I2C_STM32_INIT(index) \
I2C_STM32_IRQ_HANDLER_DECL(index); \
I2C_STM32_IRQ_HANDLER_DECL(index); \
\
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(static const uint32_t i2c_timings_##index[] = \
DT_INST_PROP_OR(index, timings, {});)) \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(static const uint32_t i2c_timings_##index[] = \
DT_INST_PROP_OR(index, timings, {});)) \
\
PINCTRL_DT_INST_DEFINE(index); \
PINCTRL_DT_INST_DEFINE(index); \
\
static const struct stm32_pclken pclken_##index[] = \
STM32_DT_INST_CLOCKS(index); \
static const struct stm32_pclken pclken_##index[] = STM32_DT_INST_CLOCKS(index); \
\
static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
.i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
.pclken = pclken_##index, \
.pclk_len = DT_INST_NUM_CLOCKS(index), \
I2C_STM32_IRQ_HANDLER_FUNCTION(index) \
.bitrate = DT_INST_PROP(index, clock_frequency), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
(.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}), \
.sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),)) \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(.timings = (const struct i2c_config_timing *) i2c_timings_##index, \
.n_timings = \
sizeof(i2c_timings_##index) / (sizeof(struct i2c_config_timing)),)) \
I2C_DMA_INIT(index, tx) \
I2C_DMA_INIT(index, rx) \
}; \
static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
.i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
.pclken = pclken_##index, \
.pclk_len = DT_INST_NUM_CLOCKS(index), \
I2C_STM32_IRQ_HANDLER_FUNCTION(index) \
.bitrate = DT_INST_PROP(index, clock_frequency), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
IF_ENABLED(CONFIG_I2C_STM32_BUS_RECOVERY, \
(.scl = GPIO_DT_SPEC_INST_GET_OR(index, scl_gpios, {0}), \
.sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),)) \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(.timings = (const struct i2c_config_timing *)i2c_timings_##index, \
.n_timings = sizeof(i2c_timings_##index) / \
(sizeof(struct i2c_config_timing)),)) \
Comment on lines +547 to +548
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the "stray" / makes this a bit harder to understand now

I2C_DMA_INIT(index, tx) \
I2C_DMA_INIT(index, rx) \
}; \
\
static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
}; \
static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
}; \
\
PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
\
I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
PM_DEVICE_DT_INST_GET(index), \
&i2c_stm32_dev_data_##index, \
&i2c_stm32_cfg_##index, \
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
&api_funcs); \
I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
PM_DEVICE_DT_INST_GET(index), \
&i2c_stm32_dev_data_##index, \
&i2c_stm32_cfg_##index, \
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
&api_funcs); \
\
I2C_STM32_IRQ_HANDLER(index)
I2C_STM32_IRQ_HANDLER(index)

DT_INST_FOREACH_STATUS_OKAY(I2C_STM32_INIT)
65 changes: 32 additions & 33 deletions drivers/i2c/i2c_ll_stm32_rtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,47 +275,46 @@ static int i2c_stm32_init(const struct device *dev)
}

#define I2C_STM32_INIT(index) \
I2C_STM32_IRQ_HANDLER_DECL(index); \
I2C_STM32_IRQ_HANDLER_DECL(index); \
\
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(static const uint32_t i2c_timings_##index[] = \
DT_INST_PROP_OR(index, timings, {});)) \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(static const uint32_t i2c_timings_##index[] = \
DT_INST_PROP_OR(index, timings, {});)) \
\
PINCTRL_DT_INST_DEFINE(index); \
PINCTRL_DT_INST_DEFINE(index); \
\
static const struct stm32_pclken pclken_##index[] = \
STM32_DT_INST_CLOCKS(index); \
static const struct stm32_pclken pclken_##index[] = STM32_DT_INST_CLOCKS(index); \
\
static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
.i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
.pclken = pclken_##index, \
.pclk_len = DT_INST_NUM_CLOCKS(index), \
I2C_STM32_IRQ_HANDLER_FUNCTION(index) \
.bitrate = DT_INST_PROP(index, clock_frequency), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(.timings = (const struct i2c_config_timing *) i2c_timings_##index, \
.n_timings = \
sizeof(i2c_timings_##index) / (sizeof(struct i2c_config_timing)),)) \
}; \
static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
.i2c = (I2C_TypeDef *)DT_INST_REG_ADDR(index), \
.pclken = pclken_##index, \
.pclk_len = DT_INST_NUM_CLOCKS(index), \
I2C_STM32_IRQ_HANDLER_FUNCTION(index) \
.bitrate = DT_INST_PROP(index, clock_frequency), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
(.timings = (const struct i2c_config_timing *)i2c_timings_##index, \
.n_timings = sizeof(i2c_timings_##index) / \
(sizeof(struct i2c_config_timing)),)) \
}; \
\
I2C_RTIO_DEFINE(CONCAT(_i2c, index, _stm32_rtio), \
DT_INST_PROP_OR(index, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \
DT_INST_PROP_OR(index, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \
I2C_RTIO_DEFINE(CONCAT(_i2c, index, _stm32_rtio), \
DT_INST_PROP_OR(index, sq_size, CONFIG_I2C_RTIO_SQ_SIZE), \
DT_INST_PROP_OR(index, cq_size, CONFIG_I2C_RTIO_CQ_SIZE)); \
\
static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
.ctx = &CONCAT(_i2c, index, _stm32_rtio), \
}; \
static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
.ctx = &CONCAT(_i2c, index, _stm32_rtio), \
}; \
\
PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
\
I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
PM_DEVICE_DT_INST_GET(index), \
&i2c_stm32_dev_data_##index, \
&i2c_stm32_cfg_##index, \
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
&api_funcs); \
I2C_DEVICE_DT_INST_DEFINE(index, i2c_stm32_init, \
PM_DEVICE_DT_INST_GET(index), \
&i2c_stm32_dev_data_##index, \
&i2c_stm32_cfg_##index, \
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, \
&api_funcs); \
\
I2C_STM32_IRQ_HANDLER(index)
I2C_STM32_IRQ_HANDLER(index)

DT_INST_FOREACH_STATUS_OKAY(I2C_STM32_INIT)
21 changes: 11 additions & 10 deletions drivers/ipm/ipm_stm32_hsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,16 @@ static const struct stm32_hsem_mailbox_config stm32_hsem_mailbox_0_config = {
* a virtual mailbox device. So there will have only one instance.
*/
#define IPM_STM32_HSEM_INIT(inst) \
BUILD_ASSERT((inst) == 0, \
"multiple instances not supported"); \
DEVICE_DT_INST_DEFINE(0, \
&stm32_hsem_mailbox_init, \
NULL, \
&stm32_hsem_mailbox_0_data, \
&stm32_hsem_mailbox_0_config, \
POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&stm32_hsem_mailbox_ipm_dirver_api); \
BUILD_ASSERT((inst) == 0, \
"multiple instances not supported"); \
\
DEVICE_DT_INST_DEFINE(0, \
&stm32_hsem_mailbox_init, \
NULL, \
&stm32_hsem_mailbox_0_data, \
&stm32_hsem_mailbox_0_config, \
POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&stm32_hsem_mailbox_ipm_dirver_api);

DT_INST_FOREACH_STATUS_OKAY(IPM_STM32_HSEM_INIT)
44 changes: 22 additions & 22 deletions drivers/pwm/pwm_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,31 +719,31 @@ static int pwm_stm32_init(const struct device *dev)

#ifdef CONFIG_PWM_CAPTURE
#define IRQ_CONNECT_AND_ENABLE_BY_NAME(index, name) \
{ \
IRQ_CONNECT(DT_IRQ_BY_NAME(PWM(index), name, irq), \
DT_IRQ_BY_NAME(PWM(index), name, priority), \
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
irq_enable(DT_IRQ_BY_NAME(PWM(index), name, irq)); \
}
{ \
IRQ_CONNECT(DT_IRQ_BY_NAME(PWM(index), name, irq), \
DT_IRQ_BY_NAME(PWM(index), name, priority), \
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
irq_enable(DT_IRQ_BY_NAME(PWM(index), name, irq)); \
}

#define IRQ_CONNECT_AND_ENABLE_DEFAULT(index) \
{ \
IRQ_CONNECT(DT_IRQN(PWM(index)), \
DT_IRQ(PWM(index), priority), \
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
irq_enable(DT_IRQN(PWM(index))); \
}
{ \
IRQ_CONNECT(DT_IRQN(PWM(index)), \
DT_IRQ(PWM(index), priority), \
pwm_stm32_isr, DEVICE_DT_INST_GET(index), 0); \
irq_enable(DT_IRQN(PWM(index))); \
}

#define IRQ_CONFIG_FUNC(index) \
static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
{ \
COND_CODE_1(DT_IRQ_HAS_NAME(PWM(index), cc), \
(IRQ_CONNECT_AND_ENABLE_BY_NAME(index, cc)), \
(IRQ_CONNECT_AND_ENABLE_DEFAULT(index)) \
); \
}
#define CAPTURE_INIT(index) \
.irq_config_func = pwm_stm32_irq_config_func_##index, \
static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
{ \
COND_CODE_1(DT_IRQ_HAS_NAME(PWM(index), cc), \
(IRQ_CONNECT_AND_ENABLE_BY_NAME(index, cc)), \
(IRQ_CONNECT_AND_ENABLE_DEFAULT(index))); \
}

#define CAPTURE_INIT(index) \
.irq_config_func = pwm_stm32_irq_config_func_##index, \
.four_channel_capture_support = DT_INST_PROP(index, four_channel_capture_support)
#else
#define IRQ_CONFIG_FUNC(index)
Expand All @@ -760,7 +760,7 @@ static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
PINCTRL_DT_INST_DEFINE(index); \
\
static const struct stm32_pclken pclken_##index[] = \
STM32_DT_CLOCKS(PWM(index)); \
STM32_DT_CLOCKS(PWM(index)); \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it would be better to always use tabs rather than end with spaces (general remark, as there's - alas! - no consistency across drivers...)

Suggested change
STM32_DT_CLOCKS(PWM(index)); \
STM32_DT_CLOCKS(PWM(index)); \

\
static const struct pwm_stm32_config pwm_stm32_config_##index = { \
.timer = (TIM_TypeDef *)DT_REG_ADDR(PWM(index)), \
Expand Down
Loading