cancel
Showing results for 
Search instead for 
Did you mean: 

USB-FS MSC Slow Writing Speed

Mohammad Hossein
Associate II
Posted on March 05, 2017 at 20:12

Hi,

I'm using STM32F4 as a USB Host for writing data to a mass storage (flash drive) in FS mode using CubeMX. As we know USB-FS nominal speed is 12Mbit/s and I set this speed in CubeMX for my application. However, the maximum writing speed that I reached is about 560 kbit/s!

I don't know what is the reason. Is there any special setting in FATFS,USB_FS or USB_Host configurations that affects  speed?

My code is similar to CubeMX example in repository,but I use FS Mode rather than HS used in example.

Is there anything important with preparing data buffer for writing (that affects speed)? My writing code is:

for(int16_t z=0;z<1024;z++)

{

sprintf(buf,'%5.5f,%5.5f\r\n',fbuf[z][0],fbuf[z][1]);

res = f_write(&MyFile, buf, strlen(buf), (void *)&byteswritten);

if((byteswritten == 0) || (res != FR_OK)) {

Error_Handler();

}

}

Thanks 

#usb-mass-storage #usb-fs #stm32 #cubemx #fatfs #usb-host
3 REPLIES 3
Posted on March 05, 2017 at 20:44

Writing a dozen bytes at a time is always going to be brutally slow, buffer the data more effectively.

A data rate of 600-700 KB/s might be achievable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 08, 2017 at 18:19

 ,

 ,

Hi,

As I guessed it before and you mentioned correctly, it is very important how to buffer the data.

At first the  ,size of data to be written should be a multiple of sector size (e.g. 512 bytes).Additionally,the more sector to be written ,the more speed can ,

be achieved because it takes a busy time after sending command and data to write in a single sector.

For more information about writing considerations see the ,link below:

http://elm-chan.org/fsw/ff/en/appnote.html ♯ memory

 ,

As stated in above link:

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 appers at faster interface speed and the performance ratio often becomes grater than ten

Finally by writing multiple sectors ( about 20 sectors (=10 kB) every time) my speed increased to 860 kB/s!!

Thanks

Posted on March 08, 2017 at 19:25

The alignment on the media tends to be a power of 2, so 8KB, 16KB, etc. ie sector, cluster, erase block

The erase block is likely 128KB. Aligned operation on the flash array (ie non-spanning) tend to provide more optimal results.

One sector will have a large command overhead. The sweet spot is probably 32KB, I tend to use that, depends on how much memory is available.

8KB might provide slightly better long term performance than 10KB, and uses less memory. Where speed/performance is critical I tend to benchmark and tune.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..