AnsweredAssumed Answered

Can't play audio file from SD card using DMA for card and DMA for DAC

Question asked by harrison.david on Jun 8, 2015
Latest reply on Jun 10, 2015 by harrison.david

Hi. I am porting an audio product that I designed and sell from the PIC32 platform to the STM32F401xc platform.

I can read from the SD card using the 4 bit SDIO card interface using DMA2_Stream3 and FATFS vers 11.0.

I am using DMA1_Stream4 to dump the audio data to an I2S DAC over the SPI2 port. I have set the DMA interrupts for transfer half complete and transfer complete.

I have two 16 bit audio buffers, each 1024 samples long. I initialize the DMA1_Stream4->MOAR address to the first buffer.

In the half transfer complete section of the DMA2_Stream3_IRQHandler I attempt to read the audio file from the SD card to load the alternate buffer that is not being dumped to the DAC with the next buffer full of data.

In the transfer complete section of the DMA2_Stream3_IRQHandler I wait until the DMA1_Stream4 is effectively disabled, clear the transfer complete flag and switch the DMA1_Stream4->MOAR address to the alternate buffer and reset the BufferSize (DMA1_Stream4->NDTR).
I then restart the DMA1_Stream4 to handle the next buffer full transfer into the DAC.

The problem is that I can't read from the file inside the DMA2_Stream3_IRQHandler. The f_read function blocks and hangs the application.

The technique works perfectly on my PIC32 platform, although it is using a polled SPI interface to read the card, not a DMA driven 4 bit SDIO interface (which should be much faster).

If I comment out the f_read call in the DMA2_Stream3_IRQHandler the application doesn't hang and I get only a repetitive noise through the DAC. By toggling a GPIO pin in the DMA2_Stream3_IRQHandler I can verify that the DMA transfers to the DAC are occurring at the correct frequency. Naturally without the f_read, the DAC isn't being updated with new audio data so I just get the audio buzz.

Does anyone have any idea what I might be missing? The two DMA streams for reading the SD card and dumping to the DAC are on DMA2 and DMA1, so there shouldn't be any priority issues between them.

Outcomes