25 #define BULK_OUT &ep[ epOutIndex ]
26 #define BULK_IN &ep[ epInIndex ]
28 static void PrintDeviceStrings(uint8_t *buf);
29 static bool QualifyDevice(uint8_t *buf);
33 static int epOutIndex;
59 bool MSDH_Init(uint8_t *usbDeviceInfo,
int usbDeviceInfoSize)
77 USB_PRINTF(
"\nUSB descriptor retrieval failed.");
82 if (!QualifyDevice(usbDeviceInfo))
88 USB_PRINTF(
"\nMSD BOT initialization failed.");
103 memcpy(usbDeviceInfo, &inquiryData.T10VendorId,
sizeof(inquiryData.T10VendorId));
104 usbDeviceInfo[
sizeof(inquiryData.T10VendorId) ] =
'\0';
105 USB_PRINTF(
"\nSCSI Inquiry Vendor ID string : \"%s\"", usbDeviceInfo);
107 memcpy(usbDeviceInfo, &inquiryData.ProductId,
sizeof(inquiryData.ProductId));
108 usbDeviceInfo[
sizeof(inquiryData.ProductId) ] =
'\0';
109 USB_PRINTF(
"\nSCSI Inquiry Product ID string : \"%s\"", usbDeviceInfo);
111 memcpy(usbDeviceInfo, &inquiryData.ProductRevisionLevel,
sizeof(inquiryData.ProductRevisionLevel));
112 usbDeviceInfo[
sizeof(inquiryData.ProductRevisionLevel) ] =
'\0';
113 USB_PRINTF(
"\nSCSI Inquiry Product Revision string : \"%s\"", usbDeviceInfo);
116 if ((inquiryData.PeripheralQualifier != 0) ||
117 (inquiryData.PeripheralDeviceType != 0))
129 }
while (!ready && i < 10 && result);
133 USB_PRINTF(
"\n\nSCSI Request Sense execution error");
146 USB_PRINTF(
"\n\nSCSI Read Capacity execution error");
150 USB_PRINTF(
"\n\nSCSI Read Capacity LBA count : %ld = %ld MiB",
151 capacityData.LogicalBlockAddress,
153 (((uint64_t)capacityData.LogicalBlockAddress
154 * capacityData.LogicalBlockLength) / (1024 * 1024)));
155 USB_PRINTF(
"\nSCSI Read Capacity LBA size : %ld\n\n",
156 capacityData.LogicalBlockLength);
179 *sectorCount = capacityData.LogicalBlockAddress;
202 *sectorSize = (uint16_t) capacityData.LogicalBlockLength;
228 *blockSize = capacityData.LogicalBlockLength;
288 static bool QualifyDevice(uint8_t *buf)
292 bool epIn =
false, epOut =
false;
333 if ((epIn && epOut) && (epInIndex < 2) && (epOutIndex < 2))
355 USB_PRINTF(
"\nThis is not a valid MSD device, review device descriptors.");
362 PrintDeviceStrings(buf);
370 USB_PRINTF(
"\n\nDevice VID/PID is 0x%04X/0x%04X, device bus speed is %s",
385 static void PrintDeviceStrings(uint8_t *buf)
SCSI Inquiry response data typedef.
bool MSDH_WriteSectors(uint32_t lba, uint16_t sectors, const void *data)
Write sectors to device.
bool MSDSCSI_Init(USBH_Ep_TypeDef *out, USBH_Ep_TypeDef *in)
MSDSCSI module initialization.
bool MSDSCSI_RequestSense(MSDSCSI_RequestSenseData_TypeDef *data)
Issue a SCSI Request Sense command.
SCSI Request Sense response data typedef.
USB HOST device definition.
int USB_PRINTF(const char *format,...)
Transmit "printf" formated data on the debug serial port.
USB_DeviceDescriptor_TypeDef * USBH_QGetDeviceDescriptor(const uint8_t *buf)
Return a pointer to the device descriptor.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
bool MSDSCSI_TestUnitReady(void)
Issue a SCSI Test Unit Ready command.
USB_InterfaceDescriptor_TypeDef * USBH_QGetInterfaceDescriptor(const uint8_t *buf, int configIndex, int interfaceIndex)
Return a pointer to an interface descriptor.
bool MSDH_ReadSectors(uint32_t lba, uint16_t sectors, void *data)
Read sectors from device.
SCSI Read Capacity response data typedef.
uint8_t bConfigurationValue
int USBH_PrintConfigurationDescriptor(const USB_ConfigurationDescriptor_TypeDef *config, int maxLen)
Pretty print a configuration descriptor on the debug serial port.
bool MSDH_GetBlockSize(uint32_t *blockSize)
Get blocksize from the device.
#define USB_CLASS_MSD_BOT_TRANSPORT
void USBTIMER_DelayMs(uint32_t msec)
Active wait millisecond delay function. Can also be used inside interrupt handlers.
bool MSDH_GetSectorSize(uint16_t *sectorSize)
Get sectorsize from the device.
SCSI interface for Mass Storage Devices (MSD).
int USBH_SetAddressB(USBH_Device_TypeDef *device, uint8_t deviceAddress)
Give a device an USB address.
void USBH_PrintString(const char *pre, const USB_StringDescriptor_TypeDef *s, const char *post)
Print a USB string descriptor on the debug serial port.
#define USB_CONFIG_DESCSIZE
bool MSDSCSI_Read10(uint32_t lba, uint16_t sectors, void *data)
Issue a SCSI Read(10) command.
int USBH_GetStringB(USBH_Device_TypeDef *device, uint8_t *buf, int bufLen, uint8_t stringIndex, uint16_t langID)
Read a string descriptor from a device.
USB_ConfigurationDescriptor_TypeDef confDesc
bool MSDH_Init(uint8_t *usbDeviceInfo, int usbDeviceInfoSize)
Initialize an USB connected Mass Storage Device. Checks if the device is a valid MSD device...
USB protocol stack library API for EFM32/EZR32.
#define USB_CLASS_MSD_SCSI_CMDSET
bool MSDSCSI_ReadCapacity(MSDSCSI_ReadCapacityData_TypeDef *data)
Issue a SCSI Read Capacity command.
bool MSDSCSI_Write10(uint32_t lba, uint16_t sectors, const void *data)
Perform a SCSI Write(10) command.
int USBH_PrintDeviceDescriptor(const USB_DeviceDescriptor_TypeDef *device)
Pretty print a device descriptor on the debug serial port.
bool MSDH_GetSectorCount(uint32_t *sectorCount)
Get sectorcount from the device.
bool MSDSCSI_Inquiry(MSDSCSI_InquiryData_TypeDef *data)
Issue a SCSI Inquiry command.
USB_EndpointDescriptor_TypeDef * USBH_QGetEndpointDescriptor(const uint8_t *buf, int configIndex, int interfaceIndex, int endpointIndex)
Return a pointer to an endpoint descriptor.
USB_DeviceDescriptor_TypeDef devDesc
uint8_t USBH_GetPortSpeed(void)
Get the bus speed of the device attached to the USB port.
int USBH_PrintEndpointDescriptor(const USB_EndpointDescriptor_TypeDef *endpoint)
Pretty print an endpoint descriptor on the debug serial port.
USB_ConfigurationDescriptor_TypeDef * USBH_QGetConfigurationDescriptor(const uint8_t *buf, int configIndex)
Return a pointer to a configuration descriptor.
int USBH_SetConfigurationB(USBH_Device_TypeDef *device, uint8_t configValue)
Activate a device configuration.
USB HOST endpoint status data.
int USBH_QueryDeviceB(uint8_t *buf, size_t bufsize, uint8_t deviceSpeed)
Will request both the device descriptor and the entire configuration descriptor from the device at US...
int USBH_PrintInterfaceDescriptor(const USB_InterfaceDescriptor_TypeDef *interface)
Pretty print an interface descriptor on the debug serial port.
int USBH_InitDeviceData(USBH_Device_TypeDef *device, const uint8_t *buf, USBH_Ep_TypeDef *ep, int numEp, uint8_t deviceSpeed)
Populate device and endpoint data structures with data retrieved during device enumeration.
int USBH_AssignHostChannel(USBH_Ep_TypeDef *ep, uint8_t hcnum)
Assign a host channel to a given endpoint.