Skip to content

Commit 4348be6

Browse files
sgilbert182kartben
authored andcommitted
i2c: stm32: add missing DMA configuration fields
Add missing fields for DMA tx and rx configuration macros Signed-off-by: Simon Gilbert <srdgilbert@gmail.com>
1 parent c2c3f75 commit 4348be6

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

drivers/i2c/i2c_ll_stm32.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,35 @@ static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
587587

588588
#ifdef CONFIG_I2C_STM32_V2_DMA
589589

590-
#define I2C_DMA_INIT(index, dir) \
591-
.dir##_dma = {.dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
592-
(DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)), \
593-
.dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir), \
594-
(DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1))},
590+
#define I2C_DMA_INIT(index, dir) \
591+
.dir##_dma = { \
592+
.dev_dma = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
593+
(DEVICE_DT_GET(STM32_DMA_CTLR(index, dir))), (NULL)),\
594+
.dma_channel = COND_CODE_1(DT_INST_DMAS_HAS_NAME(index, dir),\
595+
(DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)),\
596+
},
597+
598+
#define I2C_DMA_DATA_INIT(index, dir, src, dest) \
599+
.dma_##dir##_cfg = { \
600+
.dma_slot = STM32_DMA_SLOT(index, dir, slot), \
601+
.channel_direction = STM32_DMA_CONFIG_DIRECTION( \
602+
STM32_DMA_CHANNEL_CONFIG(index, dir)),\
603+
.cyclic = STM32_DMA_CONFIG_CYCLIC( \
604+
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
605+
.channel_priority = STM32_DMA_CONFIG_PRIORITY( \
606+
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
607+
.source_data_size = STM32_DMA_CONFIG_##src##_DATA_SIZE( \
608+
STM32_DMA_CHANNEL_CONFIG(index, dir)),\
609+
.dest_data_size = STM32_DMA_CONFIG_##dest##_DATA_SIZE( \
610+
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
611+
.source_burst_length = 1, \
612+
.dest_burst_length = 1, \
613+
}, \
595614

596615
#else
597616

598617
#define I2C_DMA_INIT(index, dir)
618+
#define I2C_DMA_DATA_INIT(index, dir, src, dest)
599619

600620
#endif /* CONFIG_I2C_STM32_V2_DMA */
601621

@@ -624,11 +644,14 @@ static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
624644
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
625645
(.timings = (const struct i2c_config_timing *) i2c_timings_##index,\
626646
.n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
627-
I2C_DMA_INIT(index, tx) \
628-
I2C_DMA_INIT(index, rx) \
647+
I2C_DMA_INIT(index, tx) \
648+
I2C_DMA_INIT(index, rx) \
629649
}; \
630650
\
631-
static struct i2c_stm32_data i2c_stm32_dev_data_##index; \
651+
static struct i2c_stm32_data i2c_stm32_dev_data_##index = { \
652+
I2C_DMA_DATA_INIT(index, tx, MEMORY, PERIPHERAL) \
653+
I2C_DMA_DATA_INIT(index, rx, PERIPHERAL, MEMORY) \
654+
}; \
632655
\
633656
PM_DEVICE_DT_INST_DEFINE(index, i2c_stm32_pm_action); \
634657
\

drivers/i2c/i2c_ll_stm32.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ struct i2c_stm32_data {
105105
const struct device *smbalert_cb_dev;
106106
#endif
107107
#ifdef CONFIG_I2C_STM32_V2_DMA
108-
struct dma_config dma_cfg;
108+
struct dma_config dma_tx_cfg;
109+
struct dma_config dma_rx_cfg;
109110
struct dma_block_config dma_blk_cfg;
110111
#endif /* CONFIG_I2C_STM32_V2_DMA */
111112
};

drivers/i2c/i2c_ll_stm32_v2.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,12 @@ static inline void msg_init(const struct device *dev, struct i2c_msg *msg,
193193
/* Configure RX DMA */
194194
data->dma_blk_cfg.source_address = LL_I2C_DMA_GetRegAddr(
195195
cfg->i2c, LL_I2C_DMA_REG_DATA_RECEIVE);
196+
data->dma_blk_cfg.source_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
196197
data->dma_blk_cfg.dest_address = (uint32_t)msg->buf;
198+
data->dma_blk_cfg.dest_addr_adj = DMA_ADDR_ADJ_INCREMENT;
197199
data->dma_blk_cfg.block_size = msg->len;
198200

199-
if (configure_dma(&cfg->rx_dma, &data->dma_cfg,
201+
if (configure_dma(&cfg->rx_dma, &data->dma_rx_cfg,
200202
&data->dma_blk_cfg) != 0) {
201203
LOG_ERR("Problem setting up RX DMA");
202204
return;
@@ -209,10 +211,13 @@ static inline void msg_init(const struct device *dev, struct i2c_msg *msg,
209211
/* Configure TX DMA */
210212
data->dma_blk_cfg.source_address =
211213
(uint32_t)data->current.buf;
214+
data->dma_blk_cfg.source_addr_adj = DMA_ADDR_ADJ_INCREMENT;
212215
data->dma_blk_cfg.dest_address = LL_I2C_DMA_GetRegAddr(
213216
cfg->i2c, LL_I2C_DMA_REG_DATA_TRANSMIT);
217+
data->dma_blk_cfg.dest_addr_adj = DMA_ADDR_ADJ_NO_CHANGE;
214218
data->dma_blk_cfg.block_size = msg->len;
215-
if (configure_dma(&cfg->tx_dma, &data->dma_cfg,
219+
220+
if (configure_dma(&cfg->tx_dma, &data->dma_tx_cfg,
216221
&data->dma_blk_cfg) != 0) {
217222
LOG_ERR("Problem setting up TX DMA");
218223
return;

0 commit comments

Comments
 (0)