/** * @brief HCD_ReEnumerate * Perform a new Enumeration phase. * @param phost: Host Handle * @retval USBH Status */ USBH_StatusTypeDef USBH_ReEnumerate (USBH_HandleTypeDef *phost) { /*Stop Host */ USBH_Stop(phost); /*Device has disconnected, so wait for 200 ms */ USBH_Delay(200); /* Set State machines in default state */ DeInitStateMachine(phost); /* Start again the host */ USBH_Start(phost); #if (USBH_USE_OS == 1) osMessagePut ( phost->os_event, USBH_PORT_EVENT, 0); #endif return USBH_OK; }
/**************************************************************************//** * @brief main - the entrypoint after reset. *****************************************************************************/ int main(void) { int connectionResult; USBH_Init_TypeDef is = USBH_INIT_DEFAULT; BSP_Init(BSP_INIT_DEFAULT); /* Initialize DK board register access */ /* If first word of user data page is non-zero, enable eA Profiler trace */ BSP_TraceProfilerSetup(); CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO); ConsoleDebugInit(); /* Initialize DK UART port. */ printf("\n\nEFM32 USB Host device enumeration example.\n"); USBH_Init(&is); /* Initialize USB HOST stack */ for (;;) { /* Wait for device connection */ printf("\nWaiting for USB device plug-in...\n"); /* Wait for maximum 10 seconds. */ connectionResult = USBH_WaitForDeviceConnectionB( tmpBuf, 10 ); if ( connectionResult == USB_STATUS_OK ) { printf("\nA device was attached...\n"); if (USBH_QueryDeviceB(tmpBuf, sizeof(tmpBuf), USBH_GetPortSpeed()) == USB_STATUS_OK) { USBH_InitDeviceData(&device, tmpBuf, NULL, 0, USBH_GetPortSpeed()); printf( "\nDevice VID/PID is 0x%04X/0x%04X, device bus speed is %s", device.devDesc.idVendor, device.devDesc.idProduct, USBH_GetPortSpeed() == PORT_FULL_SPEED ? "FULL" : "LOW" ); GetDeviceStrings(); } else { printf("\nDevice enumeration failure, please unplug device...\n"); } while ( USBH_DeviceConnected() ){} printf("\n\nDevice removal detected..."); } else if ( connectionResult == USB_STATUS_DEVICE_MALFUNCTION ) { printf("\nA malfunctioning device was attached, please remove...\n"); } else if ( connectionResult == USB_STATUS_PORT_OVERCURRENT ) { printf( "\nVBUS overcurrent condition, please remove device.\n" ); } else if ( connectionResult == USB_STATUS_TIMEOUT ) { printf("\nNo device was attached...\n"); } USBH_Stop(); } }