25 #define BULK_OUT &ep[ epOutIndex ]
26 #define BULK_IN &ep[ epInIndex ]
27 #define SCSI_INQUIRY_RETRIES 10 // Retries during MSDH_Init()
28 #define SCSI_TESTUNITREADY_RETRIES 10 // Retries during MSDH_Init()
30 static void PrintDeviceStrings(uint8_t *buf);
31 static bool QualifyDevice(uint8_t *buf);
35 static int epOutIndex;
61 bool MSDH_Init(uint8_t *usbDeviceInfo,
int usbDeviceInfoSize)
79 USB_PRINTF(
"\nUSB descriptor retrieval failed.");
84 if (!QualifyDevice(usbDeviceInfo))
92 USB_PRINTF(
"\nMSD BOT initialization failed.");
108 }
while (!ready && i < SCSI_INQUIRY_RETRIES);
116 memcpy(usbDeviceInfo, &inquiryData.T10VendorId,
sizeof(inquiryData.T10VendorId));
117 usbDeviceInfo[
sizeof(inquiryData.T10VendorId) ] =
'\0';
118 USB_PRINTF(
"\nSCSI Inquiry Vendor ID string : \"%s\"", usbDeviceInfo);
120 memcpy(usbDeviceInfo, &inquiryData.ProductId,
sizeof(inquiryData.ProductId));
121 usbDeviceInfo[
sizeof(inquiryData.ProductId) ] =
'\0';
122 USB_PRINTF(
"\nSCSI Inquiry Product ID string : \"%s\"", usbDeviceInfo);
124 memcpy(usbDeviceInfo, &inquiryData.ProductRevisionLevel,
sizeof(inquiryData.ProductRevisionLevel));
125 usbDeviceInfo[
sizeof(inquiryData.ProductRevisionLevel) ] =
'\0';
126 USB_PRINTF(
"\nSCSI Inquiry Product Revision string : \"%s\"", usbDeviceInfo);
129 if ((inquiryData.PeripheralQualifier != 0) ||
130 (inquiryData.PeripheralDeviceType != 0))
146 }
while (!ready && i < SCSI_TESTUNITREADY_RETRIES && result);
150 USB_PRINTF(
"\n\nSCSI Request Sense execution error");
163 USB_PRINTF(
"\n\nSCSI Read Capacity execution error");
167 USB_PRINTF(
"\n\nSCSI Read Capacity LBA count : %ld = %ld MiB",
168 capacityData.LogicalBlockAddress,
170 (((uint64_t)capacityData.LogicalBlockAddress
171 * capacityData.LogicalBlockLength) / (1024 * 1024)));
172 USB_PRINTF(
"\nSCSI Read Capacity LBA size : %ld\n\n",
173 capacityData.LogicalBlockLength);
196 *sectorCount = capacityData.LogicalBlockAddress;
219 *sectorSize = (uint16_t) capacityData.LogicalBlockLength;
245 *blockSize = capacityData.LogicalBlockLength;
305 static bool QualifyDevice(uint8_t *buf)
309 bool epIn =
false, epOut =
false;
350 if ((epIn && epOut) && (epInIndex < 2) && (epOutIndex < 2))
372 USB_PRINTF(
"\nThis is not a valid MSD device, review device descriptors.");
379 PrintDeviceStrings(buf);
387 USB_PRINTF(
"\n\nDevice VID/PID is 0x%04X/0x%04X, device bus speed is %s",
402 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.
#define SL_ALIGN(X)
Macro for aligning a variable. Use this macro before the variable definition. X denotes the stora...
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
#define SL_ATTRIBUTE_ALIGN(X)
GCC style macro for aligning a variable.
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.