cancel
Showing results for 
Search instead for 
Did you mean: 

Noisy audio output with TAS2110 codec over SAI on STM32U5G9J-DK1

Jinal
Associate II

 

Post edited by ST moderator to be inline with the community rules especially with the code sharing. In next time please use </> button to paste your code. Please read this post: How to insert source code

Hi,

On checking, I noticed a mismatch between the expected sampling frequency (44.1 kHz) and the actual frequency (46.875 kHz). Could this be the cause of the noise? Any suggestions on what might be going wrong?

For reference, I’m using SAI1_A with circular linked-list channel 12 of GPDMA1. The configuration details for SAI and GPDMA are provided below.
 

GPDMA Configuration: 

handle_GPDMA1_Channel12.Instance = GPDMA1_Channel12;

handle_GPDMA1_Channel12.InitLinkedList.Priority = DMA_HIGH_PRIORITY;

handle_GPDMA1_Channel12.InitLinkedList.LinkStepMode = DMA_LSM_FULL_EXECUTION;

handle_GPDMA1_Channel12.InitLinkedList.LinkAllocatedPort = DMA_LINK_ALLOCATED_PORT0;

handle_GPDMA1_Channel12.InitLinkedList.TransferEventMode = DMA_TCEM_LAST_LL_ITEM_TRANSFER;

handle_GPDMA1_Channel12.InitLinkedList.LinkedListMode = DMA_LINKEDLIST_CIRCULAR;



SAI Configuration:

hsai_BlockA1.Instance = SAI1_Block_A;

hsai_BlockA1.Init.Protocol = SAI_FREE_PROTOCOL;

hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX;

hsai_BlockA1.Init.DataSize = SAI_DATASIZE_16;

hsai_BlockA1.Init.FirstBit = SAI_FIRSTBIT_MSB;

hsai_BlockA1.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;

hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS;

hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;

hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;

hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_1QF;

hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_44K;

hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE;

hsai_BlockA1.Init.MckOutput = SAI_MCK_OUTPUT_DISABLE;

hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE;

hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING;

hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;

hsai_BlockA1.Init.PdmInit.Activation = DISABLE;

hsai_BlockA1.Init.PdmInit.MicPairsNbr = 1;

hsai_BlockA1.Init.PdmInit.ClockEnable = SAI_PDM_CLOCK1_ENABLE;

hsai_BlockA1.FrameInit.FrameLength = 32;

hsai_BlockA1.FrameInit.ActiveFrameLength = 16;

hsai_BlockA1.FrameInit.FSDefinition = SAI_FS_CHANNEL_IDENTIFICATION;

hsai_BlockA1.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;

hsai_BlockA1.FrameInit.FSOffset = SAI_FS_BEFOREFIRSTBIT;

hsai_BlockA1.SlotInit.FirstBitOffset = 0;

hsai_BlockA1.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;

hsai_BlockA1.SlotInit.SlotNumber = 2;

hsai_BlockA1.SlotInit.SlotActive = 0x00000003;
LinkList configuration:

pNodeConfig.NodeType = DMA_GPDMA_LINEAR_NODE;

pNodeConfig.Init.Request = GPDMA1_REQUEST_SAI1_A;

pNodeConfig.Init.BlkHWRequest = DMA_BREQ_SINGLE_BURST;

pNodeConfig.Init.Direction = DMA_MEMORY_TO_PERIPH;

pNodeConfig.Init.SrcInc = DMA_SINC_INCREMENTED;

pNodeConfig.Init.DestInc = DMA_DINC_FIXED;

pNodeConfig.Init.SrcDataWidth = DMA_SRC_DATAWIDTH_HALFWORD;

pNodeConfig.Init.DestDataWidth = DMA_DEST_DATAWIDTH_BYTE;

pNodeConfig.Init.SrcBurstLength = 1;

pNodeConfig.Init.DestBurstLength = 1;

pNodeConfig.Init.TransferAllocatedPort = DMA_SRC_ALLOCATED_PORT0|DMA_DEST_ALLOCATED_PORT0;

pNodeConfig.Init.TransferEventMode = DMA_TCEM_BLOCK_TRANSFER;

pNodeConfig.TriggerConfig.TriggerPolarity = DMA_TRIG_POLARITY_MASKED;

pNodeConfig.DataHandlingConfig.DataExchange = DMA_EXCHANGE_NONE;

pNodeConfig.DataHandlingConfig.DataAlignment = DMA_DATA_RIGHTALIGN_ZEROPADDED;

pNodeConfig.SrcAddress = 0;

pNodeConfig.DstAddress = 0;

pNodeConfig.DataSize = 0;

 

 Thanks,

Jinal

13 REPLIES 13
Saket_Om
ST Employee

Hello @Jinal 

To help us further investigate the sampling frequency mismatch, could you please share the configuration details of your SAI kernel clock? For accurate 44.1 kHz audio output, the SAI kernel clock should be set to a frequency that is multiple of 44.1 kHz.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
Jinal
Associate II

Hi @Saket_Om 

Thanks for your response. My clock configuration is shown in the image, and I’ve attached the IOC file for reference. Appreciate your support!

Jinal_0-1759256321669.png

Thanks,

Jinal

 

Hello @Jinal 

Could you try with the flowing config please. 

Saket_Om_0-1759313328850.png

In this config the SAI kernel clock is around 11.294 which is nearly multiple of 44.1 Khz.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

Hi @Saket_Om 

Thanks for response,

I configured the SAI kernel clock as per your suggestion, and the audio output is now slightly clearer.
When we play a mono-converted audio file using the existing configuration, the sound quality has improved — it’s more audible, though still not perfect.

Could you please suggest the recommended configuration for mono audio playback?

Thank you

Jinal



Hello @Jinal 

The ideal is to use an external SAI clock with an output frequency exactly multiple of 44.1 Khz.

Saket_Om_0-1759847844243.png

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

Hi,
As per your suggestion, we made the changes and the clock now appears almost the same. However, the audio is still noisy.
Could you please suggest the correct mono mode configuration so that we can test the mono audio file with it?

Jinal_0-1759907828291.png

Hi @Saket_Om 

I played the same audio using the EVK’s onboard MCU, and the output was clean (no noise or distortion) with the same configuration. However, when using the STM setup, the audio is noisy. Could you please suggest if I might be missing any configuration settings?

Thanks

Jinal

Hi,

sure about : 

Init.Protocol = SAI_FREE_PROTOCOL;

...as from ds, TAS2110 expects I2S protocol (if not set to other) ?

If you feel a post has answered your question, please click "Accept as Solution".

Hello @Jinal 

The issue might be related to the audio codec configuration. Please make sure that the TAS2110 is being configured correctly.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om