STM32F107 OTG Mass Storage ultra slow

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
frederic.leuba
Posts: 9
Joined: Wed Oct 03, 2012 9:12 am

STM32F107 OTG Mass Storage ultra slow

Postby frederic.leuba » Sat Oct 06, 2012 12:10 pm

Hi,

I'm using Mass Storage device code from Badger... Great work! but I have a problem.
The data transfer is damn slow... and even freezes sometimes.
Has anyone already got this problem.
Has anyone some clues how to fix or where to investigate ?

as a side note: we plan to develop a composite usb driver, for being able to do both mass-storage and serial communication on the same USB OTG port.
We'll release that as a driver module for ChibiOS.

Fred

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: STM32F107 OTG Mass Storage ultra slow

Postby mabl » Sat Oct 06, 2012 1:03 pm

Hmm the P107 uses a SPI interface. Maybe the original demo uses SDIO, which is much faster? Just guessing without ever having used it :mrgreen:

User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm
Location: Bath, UK
Contact:

Re: STM32F107 OTG Mass Storage ultra slow

Postby Badger » Sat Oct 06, 2012 3:42 pm

Hi Frederic,

great to hear you've tried the code. It is very much in the early stages so no surprise you found some problems :D

How slow is 'ultra slow'? I found that I could only read my uSD card over SPI3 (so not as fast as SPI1 on stm32F4) at about 300kb/s. Are you using full speed USB or Hight Speed? with the former the max you will get is about 1500KB/s in perfect conditions, even that will seem very slow compared to what you might be used to with HS usb sticks.

I'm more interested in the freezes you've experienced, are you able to reproduce them? I've got a test app to interface with the mass storage device, I'll have to add a stress test mode (anyone have any ideas for what I should test?)

frederic.leuba
Posts: 9
Joined: Wed Oct 03, 2012 9:12 am

Re: STM32F107 OTG Mass Storage ultra slow

Postby frederic.leuba » Sat Oct 06, 2012 10:10 pm

Hi Badger,

I actually did not measure the transfer rate. As far as I can remember, it took a good share of minutes to transfer a simple 8MB file.
Concerning the freeze, it may be that it is only an interpretation... it could be that it was actually doing its job, but so slow that it looked like being frozen and I killed it.
I'll try to investigate a bit more on monday when I'm back at work.
Is there a way to effectively measure the time spent on certain parts of the process ? Would you like to have some feedback ? Maybe if you have a test program that already do some tracking and logging, I could compile and run it ?
I'll keep you informed here about the progress. Hopefuly we can also contribute to your code.

Regards,
Fred

frederic.leuba
Posts: 9
Joined: Wed Oct 03, 2012 9:12 am

Re: STM32F107 OTG Mass Storage ultra slow

Postby frederic.leuba » Wed Oct 10, 2012 3:06 pm

Hi,
some more investigation show that this is the MMC SD card that is slow.
I added some measurement, and this is what I get when writing a 10 MB file to some SD cards :

Code: Select all

Statistics
----------
 - size of a writing block: 512
 - Number of ticks: 69037
 - Average Write Speed: 151.00000 kB/s


That is awfully slow. I must first fix that problem before switching back to USB mass-storage.

Fred

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: STM32F107 OTG Mass Storage ultra slow

Postby mabl » Wed Oct 10, 2012 3:35 pm

Maybe the FatFS statistics by chan might be intresting:

http://elm-chan.org/fsw/ff/00index_e.html

Image

dsigma
Posts: 13
Joined: Sat Jan 26, 2013 12:18 am

Re: STM32F107 OTG Mass Storage ultra slow

Postby dsigma » Fri Feb 15, 2013 10:30 pm

Hi Folks, I've been working with the USB Mass Storage driver that Badger wrote and it's been working fairly well so far. Thanks for the awesome work on the Badger! I had the same experience with slow writes, about 200k/s. I needed this to go faster so I dug into the details and found a few things that would be of interest.

-The MSD driver was writing one 512 block at a time. Small writes on an SD card can take a similar amount of time as large writes (due to how the erase-re-write cycle works in the SD card itself). I measured this on an o-scope, and found that it was taking 3ms to write a 512 byte block. This calculates out to a max of (1000/3)*512=170666 bytes per second, which is about the speeds I was getting.

-I refactored the code to download more data at a time from the USB bulk endpoint, and write out to the SD card in bigger chunks (32 blocks at a time). This was done using 2 threads, and a ping-pong buffer, such that I could retrieve data off the USB bus while simultaneously writing to the SD card. Using this technique, I was able to get 2 megabytes/second write speed over a HS ULPI interface. After scoping that again, I found that it would spend about 3ms not writing to the SD card (the initial USB transfer), and about 50ms writing to the SD card non-stop, and repeat the cycle. I suspect the next bottle neck is related to how the SDIO interface is clocked or how the SDIO peripheral is configured, not sure yet. I've seen my test cards hit about 5 megabytes/second on a hardware SD card reader, which would be cool to get to, but I'm not sure yet...

-I've been working with a dev board that supports a USB ULPI high speed interface. Using the high speed interface, I can get the 2M/s transfer rate (limiting factor is probably my SDIO peripheral configuration). Using the high speed interface I can get about 1M/s, which is approximately what I'd expect.

-Regarding the freezing, I had the same issue. I found that from time to time, some of my SD cards would get read errors, and this ended up calling the chSysHalt() function. I modified the code to retry up to 3 times and that has mitigated the issue, but the question remains of how to correctly handle errors. Which leads me to my next question...

Badger, I was looking for a technical reference for the USB Mass Storage/SCSI emulation specification, but I'm not sure where to find it. What are you referencing? And, did you have any ideas in mind as to how to cleanly handle hardware errors, such as read or write errors? and pass those errors back up to the host? I messed a little with setting the result sense code to SCSI_SENSE_KEY_MEDIUM_ERROR or SCSI_SENSE_KEY_HARDWARE_ERROR, and they cleanly passed back up to the host (per kernel log output under linux), but apparently did not make it to the user space application, which I was hoping to have some kind of I/O error occur.

I would like to post this code back to the community, but would really like to get error handling and other TODO's taken care of.

Best Regards,
-Dave

User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm
Location: Bath, UK
Contact:

Re: STM32F107 OTG Mass Storage ultra slow

Postby Badger » Mon Feb 18, 2013 9:50 am

Hi dsigma,

thanks for the comments! I'm afraid I'm so busy at the moment I don't really have time to do any indepth work or analysis on the driver, but I can point you in the direction of the spec I used: Universal Serial Bus Mass Storage Class.

I'd be keen to merge in your optimisations once they're ready, please feel free to make a pull request on github or post the code here.

dsigma
Posts: 13
Joined: Sat Jan 26, 2013 12:18 am

Re: STM32F107 OTG Mass Storage ultra slow

Postby dsigma » Thu Feb 21, 2013 2:06 am

Hi Badger,

I've made a fork of the chibios mainline code and am working on a few USB related things. My current version of the mass storage driver and sample app can be found on github: https://github.com/dsigma/ChibiOS/tree/ ... SS-STORAGE

There are still more things I want to do to this, so I will be continuing development, but feel free to pull and merge when you like.

There are some more TODO's left, and the read performance is lower then I'd hopped, I need to scope this and figure out where it's spending it's time... On a positive note, I had one SD card that got 3.9 megs/second write speed. I was very happy with that. I suspect the slow read rates are also due to the 512byte block read sizes, but have not confirmed this...

Also, if you don't have a board that supports the USB High Speed ULPI interface, this also works in full speed mode on USBD1. You can change the mcuconf.h and board file as needed...

I also came across a ton of information on USB Mass storage at http://www.lvr.com/mass_storage.htm

Best Regards,
-Dave

dsigma
Posts: 13
Joined: Sat Jan 26, 2013 12:18 am

Re: STM32F107 OTG Mass Storage ultra slow

Postby dsigma » Thu Feb 28, 2013 10:29 pm

Just wanted to provide a quick update and some interesting stats.

I've got the critical error handling logic integrated into the mass storage driver, and I moved the mass storage driver into the OS's 'hal' directory and modified it to use the normal #define techniques for enabling and disabling functionality. I also refactored the code in such a way that it will allow for composite USB devices (that is, USB devices that have more then one function). There is sample code in the dsigma fork for a composite device that has a Virtual COM port and a Mass Storage Device in one USB device descriptor, and utilizes the existing serial USB driver in chibios.

I have not gotten around to improving the read speed in the mass storage driver. Right not it's getting about 1.3megs/second, but I'm quite certain that this can be increased by reading multiple blocks at a time.

Here's some write speed stats that I gathered. This is also in the readme.
* A-Data, 8gig SD card, Class 6, 3.0megabytes/second write speed
* Kingston, 32gig SD card, Class 10, 3.9megabytes/second write speed
* Kingston, 16 gig SD card, Class 4, 2.9megabytes/second write speed
* RiData, 8 gig SD card, Class 6, 2.4megabytes/second write speed
* Sandisk, 32 gig SD card, Class 4, 3.9megabytes/second write speed
* Sandisk Ultra, 16gig SD card, HCI, 3.1megabytes/second write speed
* Sandisk, 8 gig SD card, Class 4, 3.9megabytes/second write speed
* Sandisk, 4 gig SD card, Class 6, 3.9megabytes/second write speed
* Transend, 16 gig SD card, Class 10, 3.9megabytes/second write speed
* Transend, 8 gig SD card, Class 6, 2.8megabytes/second write speed

Best Regards,
-Dave


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 59 guests