case HOST_ENUMERATION:
{
static uint16_t failedTimes = 0; //增加计数器,避免一直枚举而无法检测USB拔出状态
/* Check for enumeration status */
status = USBH_HandleEnum(phost);
if (status == USBH_OK)
{
failedTimes = 0;
/* The function shall return USBH_OK when full enumeration is complete */
USBH_UsrLog("Enumeration done.");
phost->device.current_interface = 0U;
if (phost->device.DevDesc.bNumConfigurations == 1U)
{
USBH_UsrLog("This device has only 1 configuration.");
phost->gState = HOST_SET_CONFIGURATION;
}
else
{
phost->gState = HOST_INPUT;
}
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, NULL);
#endif
#endif
}
else
{
failedTimes++;
if(failedTimes >= 3000)
{
failedTimes = 0;
phost->gState = HOST_IDLE;
//phost->gState = HOST_ABORT_STATE;
//phost->gState = HOST_DEV_DISCONNECTED;
USBH_Stop(phost);
USBH_Start(phost); //重启USB控制器
}
}
break;
}
Post Views: 74