/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully * enumerated by the host and is now ready to be used by the application. */ void EVENT_USB_Host_DeviceEnumerationComplete(const uint8_t corenum) { uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; if (USB_Host_GetDeviceConfigDescriptor(corenum, 1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { PRINTDBG("\nError Retrieving Configuration Descriptor."); return; } FlashDisk_MS_Interface.Config.PortNumber = corenum; if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface, ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError) { PRINTDBG("\nAttached Device Not a Valid Mass Storage Device."); return; } if (USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 1) != HOST_SENDCONTROL_Successful) { PRINTDBG("\nError Setting Device Configuration."); return; } uint8_t MaxLUNIndex; if (MS_Host_GetMaxLUN(&FlashDisk_MS_Interface, &MaxLUNIndex)) { PRINTDBG("\nError retrieving max LUN index."); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } PRINTDBGA("\nTotal LUNs: %d - Using first LUN in device.", (MaxLUNIndex + 1)); if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface)) { PRINTDBG("\nError resetting Mass Storage interface."); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } SCSI_Request_Sense_Response_t SenseData; if (MS_Host_RequestSense(&FlashDisk_MS_Interface, 0, &SenseData) != 0) { PRINTDBG("\nError retrieving device sense."); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true)) { PRINTDBG("\nError setting Prevent Device Removal bit."); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } SCSI_Inquiry_Response_t InquiryData; if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData)) { PRINTDBG("\nError retrieving device Inquiry data."); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } PRINTDBG("\nMass Storage Device Enumerated."); }
void EVENT_USB_Host_DeviceEnumerationComplete(void) { LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (MS_Host_ConfigurePipes(&DiskHost_MS_Interface, ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } uint8_t MaxLUNIndex; if (MS_Host_GetMaxLUN(&DiskHost_MS_Interface, &MaxLUNIndex)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } if (MS_Host_ResetMSInterface(&DiskHost_MS_Interface)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } SCSI_Request_Sense_Response_t SenseData; if (MS_Host_RequestSense(&DiskHost_MS_Interface, 0, &SenseData) != 0) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); return; } pf_mount(&DiskFATState); LEDs_SetAllLEDs(LEDMASK_USB_READY); }
/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully * enumerated by the host and is now ready to be used by the application. */ void EVENT_USB_Host_DeviceEnumerationComplete(const uint8_t corenum) { uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; if (USB_Host_GetDeviceConfigDescriptor(corenum, 1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { DEBUGOUT("Error Retrieving Configuration Descriptor.\r\n"); return; } FlashDisk_MS_Interface.Config.PortNumber = corenum; if (MS_Host_ConfigurePipes(&FlashDisk_MS_Interface, ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError) { DEBUGOUT("Attached Device Not a Valid Mass Storage Device.\r\n"); return; } if (USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 1) != HOST_SENDCONTROL_Successful) { DEBUGOUT("Error Setting Device Configuration.\r\n"); return; } uint8_t MaxLUNIndex; if (MS_Host_GetMaxLUN(&FlashDisk_MS_Interface, &MaxLUNIndex)) { DEBUGOUT("Error retrieving max LUN index.\r\n"); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } DEBUGOUT(("Total LUNs: %d - Using first LUN in device.\r\n"), (MaxLUNIndex + 1)); if (MS_Host_ResetMSInterface(&FlashDisk_MS_Interface)) { DEBUGOUT("Error resetting Mass Storage interface.\r\n"); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } SCSI_Request_Sense_Response_t SenseData; if (MS_Host_RequestSense(&FlashDisk_MS_Interface, 0, &SenseData) != 0) { DEBUGOUT("Error retrieving device sense.\r\n"); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } // if (MS_Host_PreventAllowMediumRemoval(&FlashDisk_MS_Interface, 0, true)) { // DEBUGOUT("Error setting Prevent Device Removal bit.\r\n"); // USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); // return; // } SCSI_Inquiry_Response_t InquiryData; if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData)) { DEBUGOUT("Error retrieving device Inquiry data.\r\n"); USB_Host_SetDeviceConfiguration(FlashDisk_MS_Interface.Config.PortNumber, 0); return; } /* DEBUGOUT("Vendor \"%.8s\", Product \"%.16s\"\r\n", InquiryData.VendorID, InquiryData.ProductID); */ DEBUGOUT("Mass Storage Device Enumerated.\r\n"); }
void DiskHost_USBTask(void) { if (USB_HostState == HOST_STATE_Addressed) { LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } if (MS_Host_ConfigurePipes(&DiskHost_MS_Interface, ConfigDescriptorSize, ConfigDescriptorData) != MS_ENUMERROR_NoError) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } uint8_t MaxLUNIndex; if (MS_Host_GetMaxLUN(&DiskHost_MS_Interface, &MaxLUNIndex)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } if (MS_Host_ResetMSInterface(&DiskHost_MS_Interface)) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } USB_HostState = HOST_STATE_Configured; /* Note: For the RequestSense call to work, the host state machine must be in the * Configured state, or the call will be aborted */ SCSI_Request_Sense_Response_t SenseData; if (MS_Host_RequestSense(&DiskHost_MS_Interface, 0, &SenseData) != 0) { LEDs_SetAllLEDs(LEDMASK_USB_ERROR); USB_HostState = HOST_STATE_WaitForDeviceRemoval; return; } pf_mount(&DiskFATState); LEDs_SetAllLEDs(LEDMASK_USB_READY); } MS_Host_USBTask(&DiskHost_MS_Interface); }