Skip to content

Commit 4e322a4

Browse files
committed
drivers: i2s: i2s_stm32_sai add support for stm32l4xx
xxx Signed-off-by: Mario Paja <[email protected]>
1 parent 601446f commit 4e322a4

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

drivers/i2s/i2s_stm32_sai.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,18 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
285285

286286
#if defined(CONFIG_SOC_SERIES_STM32H7X)
287287
hdma->Instance = __LL_DMA_GET_STREAM_INSTANCE(stream->reg, stream->dma_channel);
288+
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
289+
#elif defined(CONFIG_SOC_SERIES_STM32L4X)
290+
hdma->Instance = __LL_DMA_GET_CHANNEL_INSTANCE(stream->reg, (stream->dma_channel - 1));
291+
#else
292+
hdma->Instance = LL_DMA_GET_CHANNEL_INSTANCE(stream->reg, stream->dma_channel);
293+
#endif
294+
295+
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32L4X)
288296
hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
289297
hdma->Init.MemDataAlignment = DMA_PDATAALIGN_HALFWORD;
290298
hdma->Init.Priority = DMA_PRIORITY_HIGH;
291-
hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE;
292299
#else
293-
hdma->Instance = LL_DMA_GET_CHANNEL_INSTANCE(stream->reg, stream->dma_channel);
294300
hdma->Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;
295301
hdma->Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;
296302
hdma->Init.DestDataWidth = DMA_DEST_DATAWIDTH_HALFWORD;
@@ -302,12 +308,14 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
302308
#endif
303309

304310
hdma->Init.Request = dma_cfg.dma_slot;
311+
/* L4 how to get the request */
312+
hdma->Init.Request = DMA_REQUEST_1;
305313
hdma->Init.Mode = DMA_NORMAL;
306314

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

310-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
318+
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32L4X)
311319
hdma->Init.PeriphInc = DMA_PINC_DISABLE;
312320
hdma->Init.MemInc = DMA_MINC_ENABLE;
313321
#else
@@ -319,7 +327,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
319327
} else {
320328
hdma->Init.Direction = DMA_PERIPH_TO_MEMORY;
321329

322-
#if defined(CONFIG_SOC_SERIES_STM32H7X)
330+
#if defined(CONFIG_SOC_SERIES_STM32H7X) || defined(CONFIG_SOC_SERIES_STM32L4X)
323331
hdma->Init.PeriphInc = DMA_PINC_ENABLE;
324332
hdma->Init.MemInc = DMA_MINC_DISABLE;
325333
#else
@@ -341,7 +349,7 @@ static int i2s_stm32_sai_dma_init(const struct device *dev)
341349
LOG_ERR("HAL_DMA_ConfigChannelAttributes: <Failed>");
342350
return -EIO;
343351
}
344-
#elif !defined(CONFIG_SOC_SERIES_STM32H7X)
352+
#elif !defined(CONFIG_SOC_SERIES_STM32H7X) && !defined(CONFIG_SOC_SERIES_STM32L4X)
345353
if (HAL_DMA_ConfigChannelAttributes(&dev_data->hdma, DMA_CHANNEL_NPRIV) != HAL_OK) {
346354
LOG_ERR("HAL_DMA_ConfigChannelAttributes: <Failed>");
347355
return -EIO;
@@ -400,6 +408,7 @@ static void dma_callback(const struct device *dma_dev, void *arg, uint32_t chann
400408
DMA_HandleTypeDef *hdma = arg;
401409

402410
ARG_UNUSED(dma_dev);
411+
LOG_WRN("dma_callback");
403412

404413
if (status < 0) {
405414
LOG_ERR("DMA callback error with channel %d.", channel);
@@ -456,21 +465,28 @@ static int i2s_stm32_sai_configure(const struct device *dev, enum i2s_dir dir,
456465
return -EINVAL;
457466
}
458467

468+
/* Not possible to control MCLK output from SAI configuration */
469+
#if !defined(CONFIG_SOC_SERIES_STM32L4X)
459470
if (cfg->mclk_enable && stream->master) {
460471
hsai->Init.MckOutput = SAI_MCK_OUTPUT_ENABLE;
461472
} else {
462473
hsai->Init.MckOutput = SAI_MCK_OUTPUT_DISABLE;
463474
}
475+
#endif
464476

465477
if (cfg->mclk_div == (enum mclk_divider)MCLK_NO_DIV) {
466478
hsai->Init.NoDivider = SAI_MASTERDIVIDER_DISABLED;
467479
} else {
468480
hsai->Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
481+
482+
/* MckOverSampling is not supported by all STM32L4xx MCUs */
483+
#if !defined(CONFIG_SOC_SERIES_STM32L4X)
469484
if (cfg->mclk_div == (enum mclk_divider)MCLK_DIV_256) {
470485
hsai->Init.MckOverSampling = SAI_MCK_OVERSAMPLING_DISABLE;
471486
} else {
472487
hsai->Init.MckOverSampling = SAI_MCK_OVERSAMPLING_ENABLE;
473488
}
489+
#endif
474490
}
475491

476492
/* AudioFrequency */

0 commit comments

Comments
 (0)