cancel
Showing results for 
Search instead for 
Did you mean: 

USB device MSC is too slow to access an SD in FAT32 (it works fine with FAT)

ABatt.1
Senior

Hi to all,

I use the Device MSC provided by CubeMX.

I wrote my own diskio.c file and every works fine with an SD of 2Gb formatted in FAT.

When I use n SD of 8Gb formatted in FAT32, WIndows take about 2 minutes to access the root directory. After this time, the Mass storage works fine.

What is the delay in enumerating files in FAT32?

Attached my usbd_storage_if.c

P.S.: FATFS works great with the same user_diskio.c and user_spi_diskio.c (attached)

Thanks to all.

17 REPLIES 17

>>Changing the parameter MSC_MAX_FS_PACKET has no effect.

Sure, because the size of USB packets is defined by the interface.

You should instrument the sector level read/write code, and establish the transfer sizes at the card, one sector (512 bytes) is going to have lamentable performance.

The OS, caching, and sizes of directory and cluster tables will also have a significant impact from the host side.

USB FS (12-Mbps) will likely top out at about 700-800 KBps. I modern time scales that's pretty slow. About 20 years ago when USB 2.0 (HS) first appeared with 480-Mbps performance was significantly better.

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

MSC_MEDIA_PACKET is pushed through the MSC's descriptor so the host OS knows how to decimate/deblock the transfers into sizes the storage device was capable of sustaining.

https://www.st.com/resource/en/user_manual/um1734-stm32cube-usb-device-library-stmicroelectronics.pdf

In earlier instantiations of the library MSC_MAX_PACKET, but within the MSC's Configuration Descriptor

__ALIGN_BEGIN uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END =
{
 
  0x09,   /* bLength: Configuation Descriptor size */
  USB_DESC_TYPE_CONFIGURATION,   /* bDescriptorType: Configuration */
  USB_MSC_CONFIG_DESC_SIZ,
 
  0x00,
  0x01,   /* bNumInterfaces: 1 interface */
  0x01,   /* bConfigurationValue: */
  0x04,   /* iConfiguration: */
  0xC0,   /* bmAttributes: */
  0x32,   /* MaxPower 100 mA */
 
  /********************  Mass Storage interface ********************/
  0x09,   /* bLength: Interface Descriptor size */
  0x04,   /* bDescriptorType: */
  0x00,   /* bInterfaceNumber: Number of Interface */
  0x00,   /* bAlternateSetting: Alternate setting */
  0x02,   /* bNumEndpoints*/
  0x08,   /* bInterfaceClass: MSC Class */
  0x06,   /* bInterfaceSubClass : SCSI transparent*/
  0x50,   /* nInterfaceProtocol */
  0x05,          /* iInterface: */
  /********************  Mass Storage Endpoints ********************/
  0x07,   /*Endpoint descriptor length = 7*/
  0x05,   /*Endpoint descriptor type */
  MSC_IN_EP,   /*Endpoint address (IN, address 1) */
  0x02,   /*Bulk endpoint type */
  LOBYTE(MSC_MAX_PACKET),
  HIBYTE(MSC_MAX_PACKET),
  0x00,   /*Polling interval in milliseconds */
 
  0x07,   /*Endpoint descriptor length = 7 */
  0x05,   /*Endpoint descriptor type */
  MSC_OUT_EP,   /*Endpoint address (OUT, address 1) */
  0x02,   /*Bulk endpoint type */
  LOBYTE(MSC_MAX_PACKET),
  HIBYTE(MSC_MAX_PACKET),
  0x00     /*Polling interval in milliseconds*/
};

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

Thanks. I'll move in this direction.

MNema.1
Associate II

Hello, ABatt.1, Have you managed to solve the problem? I have the same symptoms with 8 Gb MMC - it takes too long for Windows to recognize.

BOh.1
Associate II

Hello, I've received a lot of help from your uploaded source code and now I'm facing the same problem, too. I wonder if you have found some solutions. Thank you.

Two years later it might be healthier to describe your specific situation and expectations.

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

What a surprise few minute answer for years old question. Well, it is nothing different from the original problem. Windows took too much time to recognize when it is plugged in. It would be better if I could use HS device as you mentions, but my device is stm32f1 and only supports FS.

Well the STM32F1/SPI implementation isn't going to be particularly fast, and the FAT32 / EXFAT tables can get colossal.

Does the F1 part you've chosen support SDIO ?

The transfer size can also make a big difference to how efficiently the OS and the card interact with each other.

Outputting telemetry will give you some insight to the type and scope of interaction that is occurring.

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