Electrical – STM32F4 :USB Mass Storage Write Low Speed Using FATFS Library

stm32usb

I am using fatfs library developed by http://elm-chan.org/ for reading/writing file system in usb mass storage using stm32f4.As I know, for improving speed throughput one should write data buffer in a multiple of sector size (512B).
As stated in http://elm-chan.org/fsw/ff/doc/appnote.html:

“The write throughput of the flash memory media becomes the worst at
single sector write transaction. The write throughput increases as the
number of sectors per a write transaction …. This effect more appears
at faster interface speed and the performance ratio often becomes
greater than ten…Therefore the application program should write the
data in large block as possible. The ideal write chunk size and
alighment is size of sector, and size of cluster is the best. Of
course all layers between the application and the storage device must
have consideration on multiple sector write, however most of
open-source memory card drivers lack it. Do not split a multiple
sector write request into single sector write transactions or the
write throughput gets poor. Note that FatFs module and its sample disk
drivers supprt multiple sector read/write operation.”.

I searched in the web and found that the maximum speed that one can reach for writing in a usb mass storage (usb full speed), is about 800kB/s. But even when I increase buffer size to 32kB (64 sector) I can reach 460kB/s. I tested for 4,8,16,32KB buffer size and the maximum speed has not exceeded 500kB/s.

Another thing that I found during test is that the allocation uint size (cluster size) of mass storage (USB flash drive in this case) can affect the speed but I cannot find any clear relation between that and speed. It depends somewhat on flash drive manufacturer. I don’t know if there is any specific configuration option in fatfs library that I missed to set correctly or any point that can increase the speed at least to 800kB/s or even more to rated speed (1.5MB/s).

Best Answer

You cannot ever get to the "rated speed" on any peripheral link because the rates are usually expressed in raw bits per second, and every link has packet framing, encoding overheads, and protocol overheads on every level on connection stack. So the "1.5 MB/s" is not possible to achieve even in theory.

The internet-quoted transfer rates (800 kB/s WRITE and somewhat higher on READ) are achievable only on pretty sophisticated benchmarks, where the designers/coders took every precaution to provide the best possible data stream, using explicitly prefetched coding to reduce system overhead. If you are using some naked library and a regular sequence of I/O calls at your application level, you get what you got, 450-500 kB/s. Be happy with this.