USB Mass Storage Device

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.
User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB Mass Storage Device

Postby Giovanni » Mon Oct 01, 2012 8:04 pm

I am relieved, I was scheduled for a semaphore-related bug nightmare this night :-)

Giovanni

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

Re: USB Mass Storage Device

Postby Badger » Mon Oct 01, 2012 8:35 pm

Sounds like a fun evening :D

Latest code now on github.

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

Re: USB Mass Storage Device

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

Hi guys,

I posted a new question related to the Mass Storage device, here: viewtopic.php?f=3&t=666#p6704

Fred

jeremie.delaitre
Posts: 26
Joined: Fri Oct 05, 2012 3:16 pm
Been thanked: 1 time

Re: USB Mass Storage Device

Postby jeremie.delaitre » Thu Jan 24, 2013 6:28 pm

Hi,

I am playing a bit with USB Mass Storage and it works out of the box...but I have some questions :)
To be noted that I tried everything on a P407 board tweaked to have the SD card operating in SDIO mode instead of SPI.

So, when I read/write some files from the micro-SD card (4GB SDHC, FatFS) through UMS, the performance are really poor. It took around 13 minutes to copy a 170MB file on the SD card while it took only 18 seconds with the same card but using a USB/micro-SD card reader.

I have compared what lsusb tells me about both devices. The only differences are:
- UMS code declares the end point addresses to be "0x81 EP 1 IN" and "0x01 EP 1 OUT" while the USB/SD reader declares "0x82 EP 2 IN" and "0x01 EP 1 OUT"
- the wMaxPacketSize for both end points are "0x0040 1x 64 bytes" against "0x0200 1x 512 bytes"
- the bInterval for both end points are 5 against 0

Looking at the USB specs, it seems that bInterval is ignored in bulk mode. Moreover, wMaxPacketSize must be 64 bytes max. So it seems that everything is ok.
I've found on the net that for High Speed USB the wMaxPacketSize should be 512. But I didn't find anything in the USB specs.

I obviously tried to set 512 as wMaxPacketSize but everything became unstable, lot of USB reset requested (apparently it is not handled properly according to the TODO)... In the end, I did not succeed in copying my test file...

What's going wrong?!

Shouldn't we be able to reach the same transfer rate as a USB/micro-SD reader?
What is the problem with 512 packet size?
Does the USB-OTG port of the P407 act like a USB-FS rather than USB-HS? How to check that? (to be noted that I use USBD2 in my code, not USBD1, so this is the correct port!)
Any hint? I've read all the threads on the forum regarding USB, SD stuff... but I have no clue!

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

Re: USB Mass Storage Device

Postby Badger » Thu Jan 24, 2013 7:12 pm

I'm away from my computer at the moment so I can't answer in much detail, but as far as I'm aware on f4 the ports are only FS unless you use an external PHY, so that's going to limit it severely. I've got an oilmex stm32 e407 that I intend to do proper testing with one day...

skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: USB Mass Storage Device

Postby skute » Fri Jan 25, 2013 1:09 am

For full-speed USB, bulk endpoints are limited to a maximum of 64 byte endpoints. Based on your timing, you are writing at ~225kB/sec, which is well below the USB bandwidth so I would expect the slowness you are seeing is related to writing to the SD card. To get the best performance on an SD card you should be writing in erase-block sizes (which requires a lot of ram, depending on the card), and this is likely what the card reader is doing. However, is likely that you are writing to the card in smaller chunks (since you have an stm32 w/ limited ram), which will kill performance.

Perhaps you can test the write speed of your sd-card without usb getting involved (using the same block size writes that the msd driver uses). Then, if you want to see how fast you can really go, try to write in erase sized blocks, or keep increasing the size of the write and at some point it will go much quicker.

iggarpe
Posts: 129
Joined: Sun Sep 30, 2012 8:32 pm

Re: USB Mass Storage Device

Postby iggarpe » Fri Jan 25, 2013 10:27 pm

Question:

Shouldn't this code...

Code: Select all

/**
* @brief IN EP1 state.
*/
static USBInEndpointState ep1InState, ep1OutState;


... be something like this ... ?

Code: Select all

/**
* @brief IN EP1 state.
*/
static USBInEndpointState ep1InState;
static USBOutEndpointState ep1OutState;

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB Mass Storage Device

Postby Giovanni » Sat Jan 26, 2013 8:17 am

Yes, it is an error.

Giovanni

Koen
Posts: 35
Joined: Mon Dec 21, 2015 12:15 am
Been thanked: 5 times

Re: USB Mass Storage Device

Postby Koen » Mon Dec 21, 2015 12:29 am

Hello,
    is this code still the preferred way to ease USB Mass Storage Device for ChibiOS version 3 ?
Thank you !

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: USB Mass Storage Device

Postby Giovanni » Mon Dec 21, 2015 9:07 am

Hi,

There is no official MS support yet, this is still the best attempt so far. I think adapting it to 3.0 should not take long.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 14 guests