|
|
|
@ -78,7 +78,7 @@ int main(void)
|
|
|
|
|
if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
|
|
|
|
|
sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
|
|
|
|
|
{
|
|
|
|
|
printf("Error Retrieving Configuration Descriptor.\r\n");
|
|
|
|
|
puts_P(PSTR("Error Retrieving Configuration Descriptor.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
@ -87,7 +87,7 @@ int main(void)
|
|
|
|
|
if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface,
|
|
|
|
|
ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError)
|
|
|
|
|
{
|
|
|
|
|
printf("Attached Device Not a Valid Mass Storage Device.\r\n");
|
|
|
|
|
puts_P(PSTR("Attached Device Not a Valid Mass Storage Device.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
@ -95,13 +95,13 @@ int main(void)
|
|
|
|
|
|
|
|
|
|
if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
|
|
|
|
|
{
|
|
|
|
|
printf("Error Setting Device Configuration.\r\n");
|
|
|
|
|
puts_P(PSTR("Error Setting Device Configuration.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Mass Storage Device Enumerated.\r\n");
|
|
|
|
|
puts_P(PSTR("Mass Storage Device Enumerated.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
|
|
|
|
USB_HostState = HOST_STATE_Configured;
|
|
|
|
|
break;
|
|
|
|
@ -111,17 +111,17 @@ int main(void)
|
|
|
|
|
uint8_t MaxLUNIndex;
|
|
|
|
|
if (MS_Host_GetMaxLUN(&FlashDisk_MS_Interface, &MaxLUNIndex))
|
|
|
|
|
{
|
|
|
|
|
printf("Error retrieving max LUN index.\r\n");
|
|
|
|
|
puts_P(PSTR("Error retrieving max LUN index.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Total LUNs: %d - Using first LUN in device.\r\n", (MaxLUNIndex + 1));
|
|
|
|
|
printf_P(PSTR("Total LUNs: %d - Using first LUN in device.\r\n"), (MaxLUNIndex + 1));
|
|
|
|
|
|
|
|
|
|
if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface))
|
|
|
|
|
{
|
|
|
|
|
printf("Error resetting Mass Storage interface.\r\n");
|
|
|
|
|
puts_P(PSTR("Error resetting Mass Storage interface.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
@ -130,7 +130,7 @@ int main(void)
|
|
|
|
|
SCSI_Request_Sense_Response_t SenseData;
|
|
|
|
|
if (MS_Host_RequestSense(&FlashDisk_MS_Interface, 0, &SenseData) != 0)
|
|
|
|
|
{
|
|
|
|
|
printf("Error retrieving device sense.\r\n");
|
|
|
|
|
puts_P(PSTR("Error retrieving device sense.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
@ -138,7 +138,7 @@ int main(void)
|
|
|
|
|
|
|
|
|
|
if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true))
|
|
|
|
|
{
|
|
|
|
|
printf("Error setting Prevent Device Removal bit.\r\n");
|
|
|
|
|
puts_P(PSTR("Error setting Prevent Device Removal bit.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
@ -147,15 +147,15 @@ int main(void)
|
|
|
|
|
SCSI_Inquiry_Response_t InquiryData;
|
|
|
|
|
if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData))
|
|
|
|
|
{
|
|
|
|
|
printf("Error retrieving device Inquiry data.\r\n");
|
|
|
|
|
puts_P(PSTR("Error retrieving device Inquiry data.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID);
|
|
|
|
|
printf_P(PSTR("Vendor \"%.8s\", Product \"%.16s\"\r\n"), InquiryData.VendorID, InquiryData.ProductID);
|
|
|
|
|
|
|
|
|
|
printf("Waiting until ready...\r\n");
|
|
|
|
|
puts_P(PSTR("Waiting until ready...\r\n"));
|
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
@ -167,37 +167,37 @@ int main(void)
|
|
|
|
|
/* Check if an error other than a logical command error (device busy) received */
|
|
|
|
|
if (ErrorCode != MS_ERROR_LOGICAL_CMD_FAILED)
|
|
|
|
|
{
|
|
|
|
|
printf("Error waiting for device to be ready.\r\n");
|
|
|
|
|
puts_P(PSTR("Error waiting for device to be ready.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("Retrieving Capacity... ");
|
|
|
|
|
puts_P(PSTR("Retrieving Capacity...\r\n"));
|
|
|
|
|
|
|
|
|
|
SCSI_Capacity_t DiskCapacity;
|
|
|
|
|
if (MS_Host_ReadDeviceCapacity(&FlashDisk_MS_Interface, 0, &DiskCapacity))
|
|
|
|
|
{
|
|
|
|
|
printf("Error retrieving device capacity.\r\n");
|
|
|
|
|
puts_P(PSTR("Error retrieving device capacity.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%lu blocks of %lu bytes.\r\n", DiskCapacity.Blocks, DiskCapacity.BlockSize);
|
|
|
|
|
printf_P(PSTR("%lu blocks of %lu bytes.\r\n"), DiskCapacity.Blocks, DiskCapacity.BlockSize);
|
|
|
|
|
|
|
|
|
|
uint8_t BlockBuffer[DiskCapacity.BlockSize];
|
|
|
|
|
|
|
|
|
|
if (MS_Host_ReadDeviceBlocks(&FlashDisk_MS_Interface, 0, 0x00000000, 1, DiskCapacity.BlockSize, BlockBuffer))
|
|
|
|
|
{
|
|
|
|
|
printf("Error reading device block.\r\n");
|
|
|
|
|
puts_P(PSTR("Error reading device block.\r\n"));
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
|
|
|
|
|
USB_HostState = HOST_STATE_WaitForDeviceRemoval;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\r\nContents of first block:\r\n");
|
|
|
|
|
puts_P(PSTR("\r\nContents of first block:"));
|
|
|
|
|
|
|
|
|
|
for (uint16_t Chunk = 0; Chunk < (DiskCapacity.BlockSize >> 4); Chunk++)
|
|
|
|
|
{
|
|
|
|
@ -210,7 +210,7 @@ int main(void)
|
|
|
|
|
printf_P(PSTR("%.2X "), CurrByte);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf(" ");
|
|
|
|
|
printf_P(PSTR(" "));
|
|
|
|
|
|
|
|
|
|
/* Print out the 16 bytes of the chunk in ASCII format */
|
|
|
|
|
for (uint8_t ByteOffset = 0; ByteOffset < (1 << 4); ByteOffset++)
|
|
|
|
@ -219,7 +219,7 @@ int main(void)
|
|
|
|
|
putchar(isprint(CurrByte) ? CurrByte : '.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("\r\n");
|
|
|
|
|
printf_P(PSTR("\r\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
|
|
|
|