2015-06-08 01:38 PM
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.
2015-06-09 03:27 PM
I finally found the problem. The SD card read access time was abyssmally slow. Due to a bug in the initialization code, the SDIO clock speed wasn't being switched from the initial 400KHz to the operating 24MHz.
However, even with that corrected, the read transfer rate is only about 1MByte/sec which, for a 4 bit bus clocked at 24MHz, and using DMA, is still ridiculously slow. I have seen this reported elsewhere in this forum and no answer has been offered. My micro-SD card is a Kingston 4GB, class 4. Any ideas anyone?