2022-10-01 11:26 PM
Hello,
I'm using an STM32 M4 for recording short audio signals through the I2S interface and I write the PCM to an SD card. To check that everything is fine I have recorded pure tones (1kHz or 2kHz). By doing that I noticed in some recordings (not all of them) some glitches in the audio signal. Can someone help understand why those glitches appear?
The reference manual reports that I2SxCLK frequency should be higher than the APB bus. In my case the APB is 16MHz and the I2SxCLK is 48MHz. Here is attached one of the 2s audio tracks recorded. Sometimes the glitch appears at the beginning of the track, some others later.
What else can generate this issue?
2022-10-02 12:33 AM
SD card can't store data fast enough?
JW
2022-10-02 06:57 AM
obviously a dropout.
can't find my crystal ball right now....
sample rate ? DMA ? circular? block size ? buffers ? size? card interface spi/sd ? SDIO data rate ? filesystem? file size? SDcard size?
2022-10-02 11:20 AM
Sorry,
The I2S has:
The SPI configuration for the SD card is:
The SD card size is 4GB SDHC (2.2 MB/s max speed) and I write 512 bytes at a time. The file system is fat32.
Do you need more information?
2022-10-02 03:21 PM
buffers ? size? how long are dropouts ?
2022-10-02 06:02 PM
I write 512 bytes at a time
That’s likely to be a problem.
You need to write multiple blocks in one hit with SD-Write-Multi in order to approach the rated speed of an SD card.
This is because internally the page size of an SD card is much larger than 512 bytes, so to write 512 it actually has to erase (say) 16k then copy over all-but-the-512-you’re-changing.
2022-10-02 11:45 PM
Dear all,
thanks for the answers. I report also the code snippet I use:
for(uint16_t i=0; i < N_DURATION; i++){
while(dma_state == DMA_WAIT);
if(dma_state == DMA_HALF){
PDM_Filter(&pdm_data[0], &pcm_data[0], &PDM1_filter_handler);
}
else if(dma_state == DMA_FULL){
PDM_Filter(&pdm_data[2048], &pcm_data[0], &PDM1_filter_handler);
}
f_state = f_write(&USERFile, &pcm_data[0], 512, &wb);
dma_state = DMA_WAIT;
}
As you can see I'm only writing a single block (512) at a time. What I could try to do is increase the DMA buffer in order to write 1024 or 2048 bytes at a time. What do you think? I cannot increase it too much because the RAM is limited.
I have tried measuring the tick count for the PDM filter and the SD write. The SD write sometimes takes longer than usual... Instead, the PDM filter takes almost identical time at every hit.
2022-10-03 12:59 AM
just guessing:
2022-10-04 10:11 AM
Dear @AScha.3 ,
unfortunately, I cannot write directly 4k into the SD card because I would need a very large amount of RAM for the DMA to store PDM data and this is not available on the STM32 I'm using.
However, measuring the execution time of the PDM filter and SD write I noticed that sometimes the SD card takes more than 100ms to write 512bytes (usually it takes about 8/10).
Any suggestions?
2022-10-05 12:54 AM
delay of 100ms or more is a problem...i had some big delays with cheap chinese SDcard.
so try new/other card from "good" source , i use only SanDisk ;
( Samsung, Kingston and Toshiba SDcards also good in my tests.)