cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F4 USB to I2S using CubeIDE DMA-I2S send bytes twice (stammers)

jmf1
Senior

Hello, I try to setup a working example of UAC1.0 USB to I2S - stereo 48kHz 16 bits on a stm32F4 discovery card (with CS43L22 CODEC). I try to get the project developed as far as possible on existing code from ST:

  • STM32CubeIDE generated code,
  • The board Drivers/BSP code for the audio part,
  • inpiration from audio stand alone examples from other F4 boards.

But this is not working correctly: bit of part of music with cracks and noises. With a Logic Analyser (LA), I looked at the I2S and it is clearly wrong. There are variants, but basically, it stammers. Instead of 0x0000, 0xDE1F, 0x0000, 0xCA... it gives something like 0x0000, 0x0000, 0xDEDE, 0xCACA, 0x0000, 0x0000. Please see attached snaposhots, with buffer content after breakpoint at usbd_audio.c Sync function, and the corresponding Logic Analyser capture. Values correspond between with Dec=> Hex conversion, except the "stammer".

I have the record and playback example working, from USB board. I normally use the same BSP and board drivers code. The I2C and CS42L22 configs are the same. The configuration of the I2S and associated DMA look the same… In that case, the LA captures are correct.

I struggle to find what could cause this. I ddin't touched the Driver/BSP code of the discovery board.

Help warmly welcomed.

JMF

1 ACCEPTED SOLUTION

Accepted Solutions

> I have the record and playback example working, from USB board.

I am confused. So what is it that is not working?

Nonetheless, duplication of bytes is due to busmaster writing byte to a peripheral which is halfword wide such as the I2S/SPI DR (the duplication happens at the AHB/APB bridge, see RM). In other words, you have incorrectly set the peripheral side width in DMA to bytes.

JW

View solution in original post

5 REPLIES 5

> I have the record and playback example working, from USB board.

I am confused. So what is it that is not working?

Nonetheless, duplication of bytes is due to busmaster writing byte to a peripheral which is halfword wide such as the I2S/SPI DR (the duplication happens at the AHB/APB bridge, see RM). In other words, you have incorrectly set the peripheral side width in DMA to bytes.

JW

Thanks so much Jan, you make my day. You pointed exactly at what I needed to look, and I found the issue at the tip of your finger. The STM32F4 disco Driver/BSP code configures the I2S and associated DMA in BSP_AUDIO_OUT_MspInit, which is called by BSP_AUDIO_OUT_Init.

But just after, BSP_AUDIO_OUT_Init calls I2S3_Init > HAL_I2S_MspInit  that sets:

hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

Here are those "BYTES" causiong the issue I encountered.

This is related to an overlap between the code generated in STM32CubeIDE for the I2S and the Driver/BSP code of the discovery board.

I did not found a way in CubeMX to specify the Mem and PeriphDataAlignment to HALFWORD and did it directly in the code for the moment.

Seems that the fact that Mem and PeriphDataAlignment both Aligned to BYTES does not allows the I2S to work properly.

Big, big thanks. Not sure I would have found it without your help.

JMF

jmf1
Senior

Hello,

The code is working, but with corrections in the HAL_I2S_MspInit .c generated by STM32cubeIDE, which is bad.

Is there a way to have that code generated with "correct" DMA Mem and PeriphDataAlignment to HALFWORD settings?

Or a justification to set the I2S DMA to "BYTES" ?

Best regards,

JMF

I don't know, I don't use Cube/CubeMX. This sort of issues is one of the reasons.

JW

jmf1
Senior

Understood, and I have some other examples in mind gently pushing in your way.

JMF