Hot!USB MSD performance

Author
jtemples
Super Member
  • Total Posts : 10788
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
2018/01/08 16:55:22 (permalink)
0

USB MSD performance

I'm using the latest (2017) USB host MSD stack from MLA with a PIC24E @ 120 MHz.  It works fine, but I noticed that creating a new file takes ~1.1 seconds.  That wouldn't matter, except the MSD stack blocks during this process, and the device has a UI that needs to remain responsive.  Reads and writes take < 50 ms, so the issue is just with file creation.  Different USB sticks perform the same.
 
Has anyone run into this?  I haven't delved deeply enough into the stack to see what exactly it's doing.
#1

12 Replies Related Threads

    Chris A
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: USB MSD performance 2018/01/09 08:57:13 (permalink)
    +1 (1)
    When using an older version but I expect not much has changed...
     
    I seem to remember about 1 second to create each file!  The other issue I had was if the USB stick had a lot of files, this really slowed things down.  Each time it allocated something from the FAT, it starts from the beginning and searches. On FAT32 the FAT covers an great number of sectors that must be read.  This is very slow and all it really needed was to cache the index where it got to last time during in the search!
     
    To deal with the blocking problem, I called my SystemTasks() function from within USBMain.c : USBFuncTasks()  which is called via the USBTask() macro.
     
    post edited by Chris A - 2018/01/09 09:43:34
    #2
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/09 11:53:06 (permalink)
    0
    Thanks, I'll try that.
    #3
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/09 14:50:14 (permalink)
    0
    I found that disabling directory support makes file creation ~25% faster.
     
    #4
    Chris A
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: USB MSD performance 2018/01/10 06:43:24 (permalink)
    0
    Oh interesting. 
     
    I just had a look for the offending function that searches the FAT  FSIO.c : FATfindEmptyCluster()
    And my comments here: http://www.microchip.com/forums/FindPost/701734But I never did go further as I intended to try FATFS instead of FSIO.c.
      http://www.microchip.com/forums/FindPost/723599
     
    #5
    Jim Nickerson
    User 452 _
    • Total Posts : 4706
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: USB MSD performance 2018/01/10 06:59:06 (permalink)
    0
    I find this interesting http://www.embeddedcodeso...nippet/fatfs-for-pic32
    though for Pic32
    edit: add pic32 comment
    post edited by Jim Nickerson - 2018/01/10 07:00:32
    #6
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/10 12:15:46 (permalink)
    0
    Chris A
    I just had a look for the offending function that searches the FAT  FSIO.c : FATfindEmptyCluster()
    And my comments here: http://www.microchip.com/forums/FindPost/701734But I never did go further as I intended to try FATFS instead of FSIO.c.
      http://www.microchip.com/forums/FindPost/723599

     
    Reading through all of that makes me think FatFS is the way to go.
    #7
    Chris A
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: USB MSD performance 2018/01/11 08:35:59 (permalink)
    0
    I would certainly put my effort in that direction :-)  I think it will also be smaller!
    But I haven't seen a USB integrated version. I believe the above is for SD.
    #8
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/11 19:09:08 (permalink)
    +2 (2)
    I've integrated FatFS into the Microchip USB stack.  File creation is ~250 ms.  Still pretty slow, but far better than FILEIO.  Code size is about 3KB smaller.
    #9
    Chris A
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: USB MSD performance 2018/01/12 04:25:23 (permalink)
    0
    Oh good.
    Have you also implemented the multi-block read/write that I have seen discussed for SD cards?  Of cause, for USB, the sectors are already split into smaller chunks!
     
    Can/will you share it?
    #10
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/12 14:08:58 (permalink)
    0
    After more experimenting, I'm questioning the times I measured above.  When I was measuring, I was plugging/unplugging the USB stick.  But I found that if I reset the board instead, file creation times are in the tens of ms rather than hundreds.  Apparently, the USB sticks take some time to boot up before you can access them?
    #11
    jtemples
    Super Member
    • Total Posts : 10788
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: USB MSD performance 2018/01/12 14:12:59 (permalink)
    +1 (1)
     I've attached the diskio.c port for USB MSD.  No other FatFS files need to be modified.  The USB MSD stack has a dependency on FILEIO from MLA, so you have to include its header files, but no FILEIO source is required.
     
    Edit: Updated with disk_ioctl fix for f_sync.
    post edited by jtemples - 2018/01/17 12:46:48
    #12
    Chris A
    Super Member
    • Total Posts : 785
    • Reward points : 0
    • Joined: 2010/07/20 04:37:07
    • Location: 0
    • Status: offline
    Re: USB MSD performance 2018/01/13 16:06:22 (permalink)
    0
    Thank you.  I will give it a go next week :-)
    #13
    Jump to:
    © 2018 APG vNext Commercial Version 4.5