2024-02-19 11:45 PM
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:
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
Solved! Go to Solution.
2024-02-20 03:00 AM
> 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
2024-02-20 03:00 AM
> 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
2024-02-20 12:53 PM
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
2024-02-21 10:21 PM
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
2024-02-22 12:48 AM
I don't know, I don't use Cube/CubeMX. This sort of issues is one of the reasons.
JW
2024-02-22 10:02 AM
Understood, and I have some other examples in mind gently pushing in your way.
JMF