-
Notifications
You must be signed in to change notification settings - Fork 8.1k
drivers: i2s: stm32 sai add support for stm32f4xx series #97829
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here we could maybe use |
||
|
||
hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; | ||
hdma->Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; | ||
hdma->Init.Priority = DMA_PRIORITY_HIGH; | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here |
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we replace all these defined with a single There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is outdated (missing F4). This could be replaced with |
||
if (cfg->mclk_enable && stream->master) { | ||
hsai->Init.MckOutput = SAI_MCK_OUTPUT_ENABLE; | ||
} else { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Could be replaced with |
||
if (cfg->mclk_div == (enum mclk_divider)MCLK_DIV_256) { | ||
hsai->Init.MckOverSampling = SAI_MCK_OVERSAMPLING_DISABLE; | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_HEAP_MEM_POOL_SIZE=4192 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2025 Mario Paja | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/ { | ||
aliases { | ||
i2s-tx = &sai1_b; | ||
}; | ||
}; | ||
|
||
/* 43.836KHz (-0.37% Error) */ | ||
&pllsai{ | ||
div-m = <8>; | ||
mul-n = <101>; | ||
div-q = <9>; | ||
div-divq = <1>; | ||
clocks = <&clk_hse>; | ||
status = "okay"; | ||
}; | ||
|
||
&sai1_b { | ||
pinctrl-0 = <&sai1_mclk_b_pf7 &sai1_sd_b_pe3 &sai1_fs_b_pf9 &sai1_sck_b_pf8>; | ||
pinctrl-names = "default"; | ||
status = "okay"; | ||
mclk-enable; | ||
mclk-divider = "div-256"; | ||
dma-names = "tx"; | ||
}; | ||
|
||
&dma2 { | ||
status = "okay"; | ||
}; |
There was a problem hiding this comment.
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
.