Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions drivers/i2s/Kconfig.stm32
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ menuconfig I2S_STM32_SAI
select USE_STM32_HAL_DMA
select USE_STM32_HAL_DMA_EX
select USE_STM32_HAL_SAI
select USE_STM32_HAL_SAI_EX if SOC_SERIES_STM32F4X
help
Enable SAI support on the STM32 family of processors.

Expand Down
23 changes: 16 additions & 7 deletions drivers/i2s/i2s_stm32_sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,17 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
}

hdma->Instance = STM32_DMA_GET_INSTANCE(stream->reg, stream->dma_channel);
#if defined(CONFIG_SOC_SERIES_STM32F4X)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here it could probably be #ifdef DMA_CHANNEL_1.

hdma->Init.Channel = dma_cfg.dma_slot * DMA_CHANNEL_1;
#else
hdma->Init.Request = dma_cfg.dma_slot;
#endif
hdma->Init.Mode = DMA_NORMAL;

#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32L4X) || \
defined(CONFIG_SOC_SERIES_STM32G4X) || defined(CONFIG_SOC_SERIES_STM32L5X)
defined(CONFIG_SOC_SERIES_STM32G4X) || defined(CONFIG_SOC_SERIES_STM32L5X) || \
defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 293 to +295
Copy link
Contributor

Choose a reason for hiding this comment

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

And here we could maybe use #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v1) || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_dma_v2) ?


hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma->Init.Priority = DMA_PRIORITY_HIGH;
Expand All @@ -304,15 +310,16 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
hdma->Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;
#endif

#if defined(CONFIG_SOC_SERIES_STM32H7X)
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32F4X)
Copy link
Contributor

Choose a reason for hiding this comment

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

And here #ifdef DMA_FIFOMODE_DISABLE

hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
#endif

if (stream->dma_cfg.channel_direction == (enum dma_channel_direction)MEMORY_TO_PERIPHERAL) {
hdma->Init.Direction = DMA_MEMORY_TO_PERIPH;

#if !defined(CONFIG_SOC_SERIES_STM32H7X) && !defined(CONFIG_SOC_SERIES_STM32L4X) && \
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X)
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X) && \
!defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 320 to +322
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we replace all these defined with a single #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32u5_dma) ?
That would probably make adding other series easier.

Copy link
Contributor Author

@mariopaja mariopaja Oct 20, 2025

Choose a reason for hiding this comment

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

I will do it on a separate PR after F7 is merged (and then I am node with almost all series), It is already in todo :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Very well. Approved!

hdma->Init.SrcInc = DMA_SINC_INCREMENTED;
hdma->Init.DestInc = DMA_DINC_FIXED;
#endif
Expand All @@ -322,7 +329,8 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
hdma->Init.Direction = DMA_PERIPH_TO_MEMORY;

#if !defined(CONFIG_SOC_SERIES_STM32H7X) && !defined(CONFIG_SOC_SERIES_STM32L4X) && \
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X)
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X) && \
!defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 331 to +333
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

hdma->Init.SrcInc = DMA_SINC_FIXED;
hdma->Init.DestInc = DMA_DINC_INCREMENTED;
#endif
Expand All @@ -342,7 +350,8 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
return -EIO;
}
#elif !defined(CONFIG_SOC_SERIES_STM32H7X) && !defined(CONFIG_SOC_SERIES_STM32L4X) && \
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X)
!defined(CONFIG_SOC_SERIES_STM32G4X) && !defined(CONFIG_SOC_SERIES_STM32L5X) && \
!defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 352 to +354
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

if (HAL_DMA_ConfigChannelAttributes(&dev_data->hdma, DMA_CHANNEL_NPRIV) != HAL_OK) {
LOG_ERR("HAL_DMA_ConfigChannelAttributes: <Failed>");
return -EIO;
Expand Down Expand Up @@ -458,7 +467,7 @@ static int i2s_stm32_sai_configure(const struct device *dev, enum i2s_dir dir,
}

/* Control of MCLK output from SAI configuration is not possible on STM32L4xx MCUs */
#if !defined(CONFIG_SOC_SERIES_STM32L4X)
#if !defined(CONFIG_SOC_SERIES_STM32L4X) && !defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 469 to +470
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment is outdated (missing F4). This could be replaced with #ifdef SAI_MCK_OUTPUT_ENABLE to avoid having to add other series in future.

if (cfg->mclk_enable && stream->master) {
hsai->Init.MckOutput = SAI_MCK_OUTPUT_ENABLE;
} else {
Expand All @@ -472,7 +481,7 @@ static int i2s_stm32_sai_configure(const struct device *dev, enum i2s_dir dir,
hsai->Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;

/* MckOverSampling is not supported by all STM32L4xx MCUs */
#if !defined(CONFIG_SOC_SERIES_STM32L4X)
#if !defined(CONFIG_SOC_SERIES_STM32L4X) && !defined(CONFIG_SOC_SERIES_STM32F4X)
Comment on lines 483 to +484
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Could be replaced with #ifdef SAI_MCK_OVERSAMPLING_DISABLE

if (cfg->mclk_div == (enum mclk_divider)MCLK_DIV_256) {
hsai->Init.MckOverSampling = SAI_MCK_OVERSAMPLING_DISABLE;
} else {
Expand Down