去掉1ms延时,我修改成如下代码,目前枚举正常,速度一下子就上来了
static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
{
int timeout = timeouts;
int status = 0;
while (1)
{
if (!connect_status)
{
return -1;
}
switch(status)
{
case 0:
rt_completion_init(&urb_completion);
RT_DEBUG_LOG(RT_DEBUG_USB, ("pipe xfer:%dn", nbytes));
rt_base_t lvl = rt_hw_interrupt_disable();
HAL_HCD_HC_SubmitRequest(&stm32_hhcd_fs,
pipe->pipe_index,
(pipe->ep.bEndpointAddress & 0x80) >> 7,
pipe->ep.bmAttributes,
token,
buffer,
nbytes,
0);
rt_hw_interrupt_enable(lvl);
status = 1;
case 1:
RT_DEBUG_LOG(RT_DEBUG_USB, ("wait_compn"));
if(rt_completion_wait(&urb_completion, timeout) != RT_EOK)
{
rt_kprintf("pipe xfer timeout:%dn", timeout);
return -1;
}
status = 2;
break;
case 2:
HCD_URBStateTypeDef urbstate = HAL_HCD_HC_GetURBState(&stm32_hhcd_fs, pipe->pipe_index);
if(URB_DONE == urbstate){
pipe->status = UPIPE_STATUS_OK;
if (pipe->callback != RT_NULL)
{
pipe->callback(pipe);
}
size_t size = HAL_HCD_HC_GetXferCount(&stm32_hhcd_fs, pipe->pipe_index);
RT_DEBUG_LOG(RT_DEBUG_USB, ("HC_XFRC:%dn", size));
if (pipe->ep.bEndpointAddress & 0x80)
{
return size;
}
return nbytes;
}
else if(URB_IDLE == urbstate){
HCD_HCStateTypeDef u***state = HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index);
RT_DEBUG_LOG(RT_DEBUG_USB, ("urb_state:%d,%dn", urbstate, u***state));
if(u***state == HC_IDLE)
{
HAL_HCD_HC_Halt(&stm32_hhcd_fs, pipe->pipe_index);
status = 0;
continue;
}
rt_completion_init(&urb_completion);
status = 1;
}
else if(URB_NOTREADY == urbstate)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("URB_NOTREADY:%dn", HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index)));
status = 0;
}
else if(URB_NYET == urbstate)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("URB_NYET:%dn", HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index)));
status = 0;
}
else if(URB_ERROR == urbstate)
{
RT_DEBUG_LOG(RT_DEBUG_USB, ("URB_ERROR:%dn", HAL_HCD_HC_GetState(&stm32_hhcd_fs, pipe->pipe_index)));
status = 0;
}
else{
rt_kprintf("urb_state:%dn", urbstate);
return -1;
}
break;
}
}
}