Skip to content

Commit 67d2281

Browse files
erwangokartben
authored andcommitted
drivers: stm32: Keep DMA stream offset handling internal to driver
In HAL based stm32 drivers, dma handling is done internally to HAL. Though, in order to avoid a dma_config() call is done to ensure stream will be set as busy in zephyr dma driver to avoid potential resource sharing conflict. This dma_config() call was done while taking into account STM32_DMA_STREAM_OFFSET, which is wrong as it will prevent zephyr dma driver to set the right stream as busy. Fix this in impacted drivers. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent db1d31e commit 67d2281

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

drivers/flash/flash_stm32_ospi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,12 +2229,9 @@ static int flash_stm32_ospi_init(const struct device *dev)
22292229
dma_cfg.user_data = &hdma;
22302230
/* HACK: This field is used to inform driver that it is overridden */
22312231
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
2232-
/* Because of the STREAM OFFSET, the DMA channel given here is from 1 - 8 */
2233-
ret = dma_config(dev_data->dma.dev,
2234-
(dev_data->dma.channel + STM32_DMA_STREAM_OFFSET), &dma_cfg);
2232+
ret = dma_config(dev_data->dma.dev, dev_data->dma.channel, &dma_cfg);
22352233
if (ret != 0) {
2236-
LOG_ERR("Failed to configure DMA channel %d",
2237-
dev_data->dma.channel + STM32_DMA_STREAM_OFFSET);
2234+
LOG_ERR("Failed to configure DMA channel %d", dev_data->dma.channel);
22382235
return ret;
22392236
}
22402237

drivers/flash/flash_stm32_xspi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,12 +1995,9 @@ static int flash_stm32_xspi_dma_init(DMA_HandleTypeDef *hdma, struct stream *dma
19951995
dma_stream->cfg.user_data = hdma;
19961996
/* HACK: This field is used to inform driver that it is overridden */
19971997
dma_stream->cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
1998-
/* Because of the STREAM OFFSET, the DMA channel given here is from 1 - 8 */
1999-
ret = dma_config(dma_stream->dev,
2000-
(dma_stream->channel + STM32_DMA_STREAM_OFFSET), &dma_stream->cfg);
1998+
ret = dma_config(dma_stream->dev, dma_stream->channel, &dma_stream->cfg);
20011999
if (ret != 0) {
2002-
LOG_ERR("Failed to configure DMA channel %d",
2003-
dma_stream->channel + STM32_DMA_STREAM_OFFSET);
2000+
LOG_ERR("Failed to configure DMA channel %d", dma_stream->channel);
20042001
return ret;
20052002
}
20062003

drivers/i2s/i2s_stm32_sai.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
277277
/* HACK: This field is used to inform driver that it is overridden */
278278
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
279279

280-
/* Because of the STREAM OFFSET, the DMA channel given here is from 1 - 8 */
281-
ret = dma_config(stream->dma_dev, stream->dma_channel + STM32_DMA_STREAM_OFFSET, &dma_cfg);
280+
ret = dma_config(stream->dma_dev, stream->dma_channel, &dma_cfg);
282281

283282
if (ret != 0) {
284-
LOG_ERR("Failed to configure DMA channel %d",
285-
stream->dma_channel + STM32_DMA_STREAM_OFFSET);
283+
LOG_ERR("Failed to configure DMA channel %d", stream->dma_channel);
286284
return ret;
287285
}
288286

drivers/video/video_stm32_dcmi.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ static int stm32_dma_init(const struct device *dev)
136136
dma_cfg.user_data = &hdma;
137137
/* HACK: This field is used to inform driver that it is overridden */
138138
dma_cfg.linked_channel = STM32_DMA_HAL_OVERRIDE;
139-
/* Because of the STREAM OFFSET, the DMA channel given here is from 1 - 8 */
140-
ret = dma_config(config->dma.dma_dev,
141-
config->dma.channel + STM32_DMA_STREAM_OFFSET, &dma_cfg);
139+
ret = dma_config(config->dma.dma_dev, config->dma.channel, &dma_cfg);
142140
if (ret != 0) {
143-
LOG_ERR("Failed to configure DMA channel %d",
144-
config->dma.channel + STM32_DMA_STREAM_OFFSET);
141+
LOG_ERR("Failed to configure DMA channel %d", config->dma.channel);
145142
return ret;
146143
}
147144

0 commit comments

Comments
 (0)