Skip to content

Commit 5c04df9

Browse files
sgilbert182kartben
authored andcommitted
i2c: stm32: add DMA callback stubs to avoid nullptr calls in ISR context
Add stub functions for the I2C DMA callbacks, which are invoked during or upon completion of DMA-based I2C transactions. Without these, NULL pointer calls occur on DMA transfer complete or error events, leading to faults within ISR context. Signed-off-by: Simon Gilbert <srdgilbert@gmail.com>
1 parent 4348be6 commit 5c04df9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/i2c/i2c_ll_stm32.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,32 @@ static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
595595
(DT_INST_DMAS_CELL_BY_NAME(index, dir, channel)), (-1)),\
596596
},
597597

598+
void i2c_stm32_dma_tx_cb(const struct device *dma_dev, void *user_data,
599+
uint32_t channel, int status)
600+
{
601+
ARG_UNUSED(dma_dev);
602+
ARG_UNUSED(user_data);
603+
ARG_UNUSED(channel);
604+
605+
/* log DMA TX error */
606+
if (status != 0) {
607+
LOG_ERR("DMA error %d", status);
608+
}
609+
}
610+
611+
void i2c_stm32_dma_rx_cb(const struct device *dma_dev, void *user_data,
612+
uint32_t channel, int status)
613+
{
614+
ARG_UNUSED(dma_dev);
615+
ARG_UNUSED(user_data);
616+
ARG_UNUSED(channel);
617+
618+
/* log DMA RX error */
619+
if (status != 0) {
620+
LOG_ERR("DMA error %d", status);
621+
}
622+
}
623+
598624
#define I2C_DMA_DATA_INIT(index, dir, src, dest) \
599625
.dma_##dir##_cfg = { \
600626
.dma_slot = STM32_DMA_SLOT(index, dir, slot), \
@@ -610,6 +636,7 @@ static void i2c_stm32_irq_config_func_##index(const struct device *dev) \
610636
STM32_DMA_CHANNEL_CONFIG(index, dir)), \
611637
.source_burst_length = 1, \
612638
.dest_burst_length = 1, \
639+
.dma_callback = i2c_stm32_dma_##dir##_cb, \
613640
}, \
614641

615642
#else

0 commit comments

Comments
 (0)