lpcware

LPCOpen USB Host detecting the type of device connected to the USB Host port and Virtual Com Host

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by micronpn on Wed Jul 16 04:08:54 MST 2014
I need to detect what type of device is connected to the USB Host port initially on a LPC1769 so that I could switch to call the right event functions related to the right devices.

Actually I put "in the middle" genric EVENT callback functions that inside should be able to detect the right device.

The first trial was done with a USB memory key and a Virtual Com device with this simple code:

void EVENT_USB_Host_DeviceEnumerationComplete(const uint8_t corenum)
{
   uint16_t ConfigDescriptorSize;
   uint8_t ConfigDescriptorData[512], bRet;

   if((bRet = USB_Host_GetDeviceConfigDescriptor(corenum, 1, &ConfigDescriptorSize, ConfigDescriptorData, sizeof(ConfigDescriptorData))) != HOST_GETCONFIG_Successful)
   {
      DEBUGOUT("Error Retrieving Configuration Descriptor.\r\n");
      return;
   }
   int iRet = USB_MS_Enumerated(corenum, &ConfigDescriptorSize, ConfigDescriptorData);
   if(iRet == -1)
   {
      int iRet = USB_CDC_Enumerated(corenum, &ConfigDescriptorSize, ConfigDescriptorData);
      if(iRet == -1)
      {
         DEBUGOUT("Unsupported or unknown attached device!!!\r\n");
         return;
      }
   }
}

but in practice if I don't put the USB memory key in the USB host connector the code loops for ever in USB_MS_Enumerated(..) without exiting so that the next instructions are not executed at all.

I suppose that there is a function that should be able to return the type of the device connected to the USB host port. Am I wrong?

Kind regards,
Massimo

Outcomes