Dealing with erratic write performance of USB drives using FatFS lib and mass storage host
Hi folks,
I'm sampling 8 microphones using 4xI2S peripherals using DMA and a double buffer, which I then use to write to 4xWAV/PCM files on a USB drive and am getting buffer overruns intermittently!
I believe I've narrowed it down to the FatFS file write, where I'm recording wildly different performance across different USB drives, but also between writes on the same USB.
To diagnose, I wrote data to 3 different USB drives using 1KB, 2KB, 4KB, 8KB and 16KB blocks. For each block size I executed the write operation 256 times and recorded each time using HAL_GetTick() to get a close-enough measurement.
As expected, the no-name USB 2.0 was the worst performing. The Sandisk USB 3.0 was next but the Toshiba USB 2.0 was almost twice as fast again and with much more consistent times!
Of the write block sizes, 8KB was somehow the magic value, with 745KB/s sustained speed, 11ms minimum, 11ms average and 48ms max. Performance dropped at higher and lower block sizes.
However, every now and then I would get extremely large pauses! Anywhere from 108ms up to 1350!! This obviously caused the DMA channel to overrun.
Does someone know why this extreme difference in write performance occurs and what I might do to get more consistent write times or otherwise work around it?
Thanks
