新手上路
- 积分
- 43
- 金钱
- 43
- 注册时间
- 2019-12-3
- 在线时间
- 16 小时
|
楼主 |
发表于 2020-5-19 20:30:04
|
显示全部楼层
大家好,通过调试打印输出已经找到问题的所在了,主要是在第一次读取端点0数据返回的wMaxPacketSize = 8, rtthread这个表达式, send_size = (remain_size > pipe->ep.wMaxPacketSize) ? pipe->ep.wMaxPacketSize : remain_size;
实际赋值 8 = (18 > 8)? 8:18 ,因此发送的只是请求返回前8个字节的设备描述符,使得出现返回的只有8个字节, 和读取18个字节
的设备描述符对不上,打印出get full device descriptor failed,
而U盘之所以能正常是因为第一次读取端点0数据返回wMaxPacketSize = 64, 实际赋值 18 = (18> 64)? 64:18,即send_size = 18,
因此能正常读回完整的设备描述符. 通过读读取全部设备描述符时增加测试debug_dat代码人为更改send_size = 18, 可以读取
全部设备描述符了.
if(debug_dat)
{
send_size = 18;
}
int rt_usb_hcd_pipe_xfer(uhcd_t hcd, upipe_t pipe, void* buffer, int nbytes, int timeout)
{
rt_size_t remain_size;
rt_size_t send_size;
remain_size = nbytes;
rt_uint8_t * pbuffer = (rt_uint8_t *)buffer;
do
{
RT_DEBUG_LOG(RT_DEBUG_USB,("pipe transform remain size,: %d\n", remain_size));
send_size = (remain_size > pipe->ep.wMaxPacketSize) ? pipe->ep.wMaxPacketSize : remain_size;
RT_DEBUG_LOG(RT_DEBUG_USB,("pipe->ep.wMaxPacketSize = %d\r\n", pipe->ep.wMaxPacketSize));
RT_DEBUG_LOG(RT_DEBUG_USB,("send_size = %d\r\n", send_size));
if(debug_dat)
{
send_size = 18;
}
if(hcd->ops->pipe_xfer(pipe, USBH_PID_DATA, pbuffer, send_size, timeout) == send_size)
{
remain_size -= send_size;
pbuffer += send_size;
}
else
{
return 0;
}
}while(remain_size > 0);
return nbytes;
}
|
|