Skip to content

drivers: dma: stm32: take "stream offset" into account when DMAV1 + DMAMUX is used #93673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/adc/adc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static int adc_stm32_dma_start(const struct device *dev,
dma->dma_cfg.head_block = blk_cfg;
dma->dma_cfg.user_data = data;

ret = dma_config(data->dma.dma_dev, data->dma.channel,
ret = dma_config(data->dma.dma_dev, data->dma.channel + STM32_DMA_STREAM_OFFSET,
&dma->dma_cfg);
if (ret != 0) {
LOG_ERR("Problem setting up DMA: %d", ret);
Expand Down
3 changes: 2 additions & 1 deletion drivers/dma/dma_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
dma_stm32_clear_stream_irq(dev, id);
return;
}

#ifdef CONFIG_DMAMUX_STM32
callback_arg = stream->mux_channel;
callback_arg = stream->mux_channel + STM32_DMA_STREAM_OFFSET;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should instead apply the offset here:

#ifdef CONFIG_DMAMUX_STM32
/* Each further stream->mux_channel is fixed here */
config->streams[i].mux_channel = i + config->offset;
#endif /* CONFIG_DMAMUX_STM32 */

#ifdef CONFIG_DMAMUX_STM32
 		/* Each further stream->mux_channel is fixed here */
- 		config->streams[i].mux_channel = i + config->offset;
+ 		config->streams[i].mux_channel = i + config->offset + STM32_DMA_STREAM_OFFSET;
#endif /* CONFIG_DMAMUX_STM32 */

#else
callback_arg = id + STM32_DMA_STREAM_OFFSET;
#endif /* CONFIG_DMAMUX_STM32 */
Expand Down
29 changes: 4 additions & 25 deletions drivers/dma/dma_stm32u5.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
dma_stm32_clear_stream_irq(dev, id);
return;
}
callback_arg = id + STM32_DMA_STREAM_OFFSET;
callback_arg = id;

/* The dma stream id is in range from STM32_DMA_STREAM_OFFSET..<dma-requests> */
/* The dma stream id is in range from 0..<dma-requests> */
if (stm32_dma_is_ht_irq_active(dma, id)) {
/* Let HAL DMA handle flags on its own */
if (!stream->hal_override) {
Expand Down Expand Up @@ -349,16 +349,12 @@ static int dma_stm32_configure(const struct device *dev,
struct dma_config *config)
{
const struct dma_stm32_config *dev_config = dev->config;
struct dma_stm32_stream *stream =
&dev_config->streams[id - STM32_DMA_STREAM_OFFSET];
struct dma_stm32_stream *stream = &dev_config->streams[id];
DMA_TypeDef *dma = (DMA_TypeDef *)dev_config->base;
uint32_t ll_priority;
uint32_t ll_direction;
int ret;

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= dev_config->max_streams) {
LOG_ERR("cannot configure the dma stream %d.", id);
return -EINVAL;
Expand Down Expand Up @@ -553,9 +549,6 @@ static int dma_stm32_reload(const struct device *dev, uint32_t id,
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);
struct dma_stm32_stream *stream;

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
}
Expand Down Expand Up @@ -590,9 +583,6 @@ static int dma_stm32_start(const struct device *dev, uint32_t id)
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);
struct dma_stm32_stream *stream;

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

/* Only M2P or M2M mode can be started manually. */
if (id >= config->max_streams) {
return -EINVAL;
Expand All @@ -619,9 +609,6 @@ static int dma_stm32_suspend(const struct device *dev, uint32_t id)
const struct dma_stm32_config *config = dev->config;
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
}
Expand All @@ -642,9 +629,6 @@ static int dma_stm32_resume(const struct device *dev, uint32_t id)
const struct dma_stm32_config *config = dev->config;
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
}
Expand All @@ -658,12 +642,9 @@ static int dma_stm32_resume(const struct device *dev, uint32_t id)
static int dma_stm32_stop(const struct device *dev, uint32_t id)
{
const struct dma_stm32_config *config = dev->config;
struct dma_stm32_stream *stream = &config->streams[id - STM32_DMA_STREAM_OFFSET];
struct dma_stm32_stream *stream = &config->streams[id];
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;

if (id >= config->max_streams) {
return -EINVAL;
}
Expand Down Expand Up @@ -723,8 +704,6 @@ static int dma_stm32_get_status(const struct device *dev,
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);
struct dma_stm32_stream *stream;

/* Give channel from index 0 */
id = id - STM32_DMA_STREAM_OFFSET;
if (id >= config->max_streams) {
return -EINVAL;
}
Expand Down