I use lpcusblib debugging usbhost found that the program will stop in the WaitForTransferComplete
In enumdevice get devicedescription stop waitTransferComlete
static HCD_STATUS WaitForTransferComplete(uint8_t EdIdx)
{
#ifndef __TEST__ //
while ( HcdED(EdIdx)->status == HCD_STATUS_TRANSFER_QUEUED ) {} //while in this
return (HCD_STATUS) HcdED(EdIdx)->status;
#else
return HCD_STATUS_OK;
#endif
}
hi,
Thank you ask me ,but I did not using thread and I'm sure my hardware is correct ,The pipe enumeration device gets the device descriptor failed,The independent enumeration device gets the device descriptor normal
pipe method: get device description err
case HOST_STATE_Powered_DoReset: { // 5 ÔÚ¸´Î»É豸 µÈ´ýö¾Ù
HCD_USB_SPEED DeviceSpeed;
HcdRhPortReset(corenum); //¸´Î» ¶Ë¿Ú
HcdGetDeviceSpeed(corenum,&DeviceSpeed); // »ñÈ¡ USBµÄÉ豸ËÙ¶È full speed
USB_Host_SetDeviceSpeed(corenum, DeviceSpeed); //¸ü¸ÄÉ豸Ëٶȱê־λ full speed
HOST_TASK_NONBLOCK_WAIT(corenum, 200, HOST_STATE_Powered_ConfigPipe); //¼ÌÐøµÈ´ý200ms ʲôÒâ˼£¿
}
break;
case HOST_STATE_Powered_ConfigPipe: // 6 ÕýÔÚÅäÖùܵÀ
if (!Pipe_ConfigurePipe(corenum, PIPE_CONTROLPIPE, EP_TYPE_CONTROL, //ÅäÖùܵÀ: É豸 ¿ØÖƹܵÀ ¿ØÖƶ˵ã0
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP, // Setup 0
PIPE_CONTROLPIPE_DEFAULT_SIZE, PIPE_BANK_SINGLE) ) { // ĬÈÏ 8byte
ErrorCode = HOST_ENUMERROR_PipeConfigError;
SubErrorCode = 0;
break;
}
USB_HostState[corenum] = HOST_STATE_Default;
break;
case HOST_STATE_Default: { // 7 ÕýÔÚ¼ìË÷¿ØÖƹܵÀµÄ´óС £¬Ê¹ÓùܵÀµÄ¸ÅÄî ö¾Ù
USB_Descriptor_Device_t DevDescriptor;
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_GetDescriptor,
.wValue = (DTYPE_Device << 8),
.wIndex = 0,
.wLength = 8,
};
//¸ù¾ÝÉÏÏÂÎÄÀí½âΪ »ñÈ¡É豸ÃèÊö·û
if ((SubErrorCode = USB_Host_SendControlRequest(corenum, &DevDescriptor)) != HOST_SENDCONTROL_Successful) { //sendControlRequest
ErrorCode = HOST_ENUMERROR_ControlError;
break;
}
DEBUGOUT("Get devicedescription\r\n"); //
USB_Host_ControlPipeSize[corenum] = DevDescriptor.Endpoint0Size;
Pipe_ClosePipe(corenum, PIPE_CONTROLPIPE);
HcdRhPortReset(corenum);
HOST_TASK_NONBLOCK_WAIT(corenum, 200, HOST_STATE_Default_PostReset); //µÈ´ýpipe ¸´Î»
}
break;
stand method: get device description ok enum ok but speed vary low
ohciResetPort();
//PRINT_Log("\r\nreset port complete.");
/*get device desc max size*/
rc = hostGetDesc(USB_DESCRIPTOR_TYPE_DEVICE, 0, g_hostBuf, 8, 0);
if (rc != USBHOST_OK)
{
PRINT_Err(rc);
return rc;
}
/*set the deviceDesc*/
memcpy((uint8_t *)(&g_usbDevInfo->devDesc), (uint8_t *)g_hostBuf, sizeof(USB_DEV_DESC));
/*set the device address to USB_ADDR*/
rc = hostSetDevAddress(USB_ADDR, 0);
if (rc != USBHOST_OK)
{
PRINT_Err(rc);
return rc;
}
//USBHOST_DELAY(20);
rc = hostGetDesc(USB_DESCRIPTOR_TYPE_DEVICE, 0, g_hostBuf, sizeof(USB_DEV_DESC), USB_ADDR);
if (rc != USBHOST_OK)
{
PRINT_Err(rc);
return rc;
}
memcpy((uint8_t *)(&g_usbDevInfo->devDesc), (uint8_t *)g_hostBuf, sizeof(USB_DEV_DESC));
/*get configuration desc data length*/
rc = hostGetDesc(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, g_hostBuf, sizeof(USB_CONF_DESC), USB_ADDR);
if (rc != USBHOST_OK)
{
PRINT_Err(rc);
return rc;
}
/*get total description len*/
n = ReadLE16U((unsigned char *)&g_hostBuf[2]);
/*get all descriptions includes device,config,interface,endpoint*/
rc = hostGetDesc(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, g_hostBuf, n, USB_ADDR);
if (rc != USBHOST_OK)
{
PRINT_Err(rc);
return rc;
}
请问一下,最后是怎么解决的?
什么问题导致的死循环?
Hi,
Please check the below thread, I hope this helps.
LPC1768 USB Host mode not working
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------