AnsweredAssumed Answered

STM32F2/F4 USB-MSC >4gb limitation

Question asked by lopez.pedro.001 on Jul 18, 2016
Latest reply on Jul 19, 2016 by lopez.pedro.001

I have added USB Host support for MSC. It is working ok with USBs under 4gb... but it is not detected properly with USB-sticks over 4gb.

I'm using library version 2.2.0, microcontroller are F2/F4 (project is done for 2 different boards). As note i'm using also FatFs R0.11a

This is what my debug output echoes...

> USB Host library started.
     USB Host Library v2.2.0
> Device Attached
> Full speed device detected
VID : 0951h
PID : 1607h
> Mass storage device connected
Manufacturer : Kingston
Product : DataTraveler 2.0
Serial Number : 001D0F0C7365A9B0D5360657
> Enumeration completed
Enumeracion hecha
> File System initialized.
> Disk capacity : 3724541440 Bytes

In this case the usb-stick had 8Gb

I have spent some time checking different posts i saw some posts with something similar for  SD cards but I didnt find anything about USB sticks.  

Checking the code MSCapacity is set to uint32_t but it is sectors

typedef struct __MassStorageParameter
  uint32_t MSCapacity;
  uint32_t MSSenseKey;
  uint16_t MSPageLength;
  uint8_t MSBulkOutEp;
  uint8_t MSBulkInEp;
  uint8_t MSWriteProtect;
} MassStorageParameter_TypeDef;

Debugging the code here it is assigned but i'm reading the USBH_DataInBuffer 

uint8_t USBH_MSC_ReadCapacity10(USB_OTG_CORE_HANDLE *pdev)
      if(USBH_MSC_BOTXferParam.BOTXferStatus == USBH_MSC_OK)
        /*assign the capacity*/
        (((uint8_t*)&USBH_MSC_Param.MSCapacity )[3]) = USBH_DataInBuffer[0];
        (((uint8_t*)&USBH_MSC_Param.MSCapacity )[2]) = USBH_DataInBuffer[1];
        (((uint8_t*)&USBH_MSC_Param.MSCapacity )[1]) = USBH_DataInBuffer[2];
        (((uint8_t*)&USBH_MSC_Param.MSCapacity )[0]) = USBH_DataInBuffer[3];
        /*assign the page length*/
        (((uint8_t*)&USBH_MSC_Param.MSPageLength )[1]) = USBH_DataInBuffer[6];
        (((uint8_t*)&USBH_MSC_Param.MSPageLength )[0]) = USBH_DataInBuffer[7];
        /* Commands successfully sent and Response Received  */      
        USBH_MSC_BOTXferParam.CmdStateMachine = CMD_SEND_STATE;
        status = USBH_MSC_OK;     

this is what  i get om USBH_DataInBuffer


15663103 sectors with 512 bytes each = 7.46gb, thats right but i see it as 3724 because it is too big for 32bits addressing.

Is there a fix for this limitation?, any tip?. would it work if  i create a partition under 4gb?

We need only 100mb of the usb space, but the problem is that customers can put any kind of usb-stick, it is not easy to find actually usb sticks under 4gb, and force them to create a partition under 4gb when they are normal users is not a nice thing.

Thanks in advance