Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
USB
使用rtthread USB, 枚举不了鼠标,设备描述符,调试打印显示 ge...
发布于 2020-05-18 16:02:42 浏览:3151
订阅该版
你好, 最近在使用rtthread USB HOST , 要做一个可识别U盘和HID设备, 使用U盘没什么问题, 而插入鼠标时,在取全部设备描述符时失败, 调试打印显示:`get full device descriptor failed`, 如图,获取全部描述符应该是一个标准的发送接收, U盘可以, HID为什么不行呢, 是什么问题导致,百思不得解, 是什么原因麻烦知道的人帮助解答一下,感谢:handshake. ![打印失败.jpg](/uploads/202005/18/155843hbfhe533hcwwwwj6.jpg)
查看更多
7
个回答
默认排序
按发布时间排序
wxfjog
2020-05-20
这家伙很懒,什么也没写!
大家好,通过调试打印输出已经找到问题的所在了,主要是在第一次读取端点0数据返回的`wMaxPacketSize = 8`, rtthread这个表达式, ```c 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`, 可以读取 全部设备描述符了., 官方的USB HOST U盘程序 只能枚举`wMaxPacketSize > 18`字节的,小于的话,像鼠标类8字节会枚举失败。:) ```c 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; } ```
wxfjog
2020-05-18
这家伙很懒,什么也没写!
```c rt_err_t rt_usbh_attatch_instance(uinst_t device) { int i = 0; rt_err_t ret = RT_EOK; struct uconfig_descriptor cfg_desc; udev_desc_t dev_desc; uintf_desc_t intf_desc; uep_desc_t ep_desc; rt_uint8_t ep_index; upipe_t pipe; ucd_t drv; RT_ASSERT(device != RT_NULL); rt_memset(&cfg_desc, 0, sizeof(struct uconfig_descriptor)); dev_desc = &device->dev_desc; /* alloc address 0 ep0 pipe*/ ep0_out_desc.wMaxPacketSize = 8; ep0_in_desc.wMaxPacketSize = 8; rt_usb_hcd_alloc_pipe(device->hcd, &device->pipe_ep0_out, device, &ep0_out_desc); rt_usb_hcd_alloc_pipe(device->hcd, &device->pipe_ep0_in, device, &ep0_in_desc); RT_DEBUG_LOG(RT_DEBUG_USB, ("start enumnation\n")); /* get device descriptor head */ ret = rt_usbh_get_descriptor(device, USB_DESC_TYPE_DEVICE, (void*)dev_desc, 8); if(ret != RT_EOK) { rt_kprintf("get device descriptor head failed\n"); return ret; } /* reset bus */ rt_usbh_hub_reset_port(device->parent_hub, device->port); rt_thread_delay(2); rt_usbh_hub_clear_port_feature(device->parent_hub, i + 1, PORT_FEAT_C_CONNECTION); /* set device address */ ret = rt_usbh_set_address(device); if(ret != RT_EOK) { rt_kprintf("set device address failed\n"); return ret; } /* free address 0 ep0 pipe*/ rt_usb_hcd_free_pipe(device->hcd,device->pipe_ep0_out); rt_usb_hcd_free_pipe(device->hcd,device->pipe_ep0_in); /* set device max packet size */ ep0_out_desc.wMaxPacketSize = device->dev_desc.bMaxPacketSize0; ep0_in_desc.wMaxPacketSize = device->dev_desc.bMaxPacketSize0; /* alloc true address ep0 pipe*/ rt_usb_hcd_alloc_pipe(device->hcd, &device->pipe_ep0_out, device, &ep0_out_desc); rt_usb_hcd_alloc_pipe(device->hcd, &device->pipe_ep0_in, device, &ep0_in_desc); RT_DEBUG_LOG(RT_DEBUG_USB, ("get device descriptor length %d\n", dev_desc->bLength)); /* get full device descriptor again */ ret = rt_usbh_get_descriptor(device, USB_DESC_TYPE_DEVICE, (void*)dev_desc, dev_desc->bLength); if(ret != RT_EOK) { rt_kprintf("get full device descriptor failed\n"); return ret; } RT_DEBUG_LOG(RT_DEBUG_USB, ("Vendor ID 0x%x\n", dev_desc->idVendor)); RT_DEBUG_LOG(RT_DEBUG_USB, ("Product ID 0x%x\n", dev_desc->idProduct)); /* get configuration descriptor head */ ret = rt_usbh_get_descriptor(device, USB_DESC_TYPE_CONFIGURATION, &cfg_desc, 18); if(ret != RT_EOK) { rt_kprintf("get configuration descriptor head failed\n"); return ret; } /* alloc memory for configuration descriptor */ device->cfg_desc = (ucfg_desc_t)rt_malloc(cfg_desc.wTotalLength); rt_memset(device->cfg_desc, 0, cfg_desc.wTotalLength); /* get full configuration descriptor */ ret = rt_usbh_get_descriptor(device, USB_DESC_TYPE_CONFIGURATION, device->cfg_desc, cfg_desc.wTotalLength); if(ret != RT_EOK) { rt_kprintf("get full configuration descriptor failed\n"); return ret; } /* set configuration */ ret = rt_usbh_set_configure(device, 1); if(ret != RT_EOK) { return ret; } for(i=0; i
cfg_desc->bNumInterfaces; i++) { /* get interface descriptor through configuration descriptor */ ret = rt_usbh_get_interface_descriptor(device->cfg_desc, i, &intf_desc); if(ret != RT_EOK) { rt_kprintf("rt_usb_get_interface_descriptor error\n"); return -RT_ERROR; } RT_DEBUG_LOG(RT_DEBUG_USB, ("interface class 0x%x, subclass 0x%x\n", intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass)); /* alloc pipe*/ for(ep_index = 0; ep_index < intf_desc->bNumEndpoints; ep_index++) { rt_usbh_get_endpoint_descriptor(intf_desc, ep_index, &ep_desc); if(ep_desc != RT_NULL) { if(rt_usb_hcd_alloc_pipe(device->hcd, &pipe, device, ep_desc) != RT_EOK) { rt_kprintf("alloc pipe failed\n"); return RT_ERROR; } rt_usb_instance_add_pipe(device,pipe); } else { rt_kprintf("get endpoint desc failed\n"); return RT_ERROR; } } /* find driver by class code found in interface descriptor */ drv = rt_usbh_class_driver_find(intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass); if(drv != RT_NULL) { /* allocate memory for interface device */ device->intf[i] = (struct uhintf*)rt_malloc(sizeof(struct uhintf)); device->intf[i]->drv = drv; device->intf[i]->device = device; device->intf[i]->intf_desc = intf_desc; device->intf[i]->user_data = RT_NULL; /* open usb class driver */ ret = rt_usbh_class_driver_enable(drv, (void*)device->intf[i]); if(ret != RT_EOK) { rt_kprintf("interface %d run class driver error\n", i); } } else { rt_kprintf("find usb device driver failed\n"); continue; } } return RT_EOK; } ```
aozima
2020-05-20
调网络不抓包,调I2C等时序不上逻辑分析仪,就像电工不用万用表!多用整理的好的文字,比截图更省流量,还能在整理过程中思考。
楼主V5,可以提交个PR吗?
じ★ve萫彯彯
2020-12-29
这家伙很懒,什么也没写!
我U盘可以,USB键盘不行,奇怪! USB键盘如下: ![63c92a799722a96726f50d39d3849ec4.jpg](/uploads/20201229/63c92a799722a96726f50d39d3849ec4.jpg) U盘如下: ![cd7b504f30dc072456e9eb880c8504ae.jpg](/uploads/20201229/cd7b504f30dc072456e9eb880c8504ae.jpg)
zhangf0633
2022-12-17
这家伙很懒,什么也没写!
我最近也在搞这方面,也是一样的问题,官方还是么有解决吗,大家现在是怎么做的
Lrain
2023-09-05
这家伙很懒,什么也没写!
我也遇到了这个问题,请问楼主解决了吗?U盘可以,插鼠标就不行了,刚开始提示get full device descriptor failed,将send_size = 18;后,又提示get device descriptor head failed,不知道是哪的问题了,求解答
woshi520laoxie
2024-01-08
这家伙很懒,什么也没写!
我试了一下,这么修改,的确不报错误了,但是鼠标活动的时候也没有见到任何打印信息的出现 鼠标线程似乎就阻塞着了,也不太正常,否则鼠标活动应该会有打印鼠标的信息的吧
撰写答案
登录
注册新账号
关注者
0
被浏览
3.2k
关于作者
wxfjog
这家伙很懒,什么也没写!
提问
16
回答
12
被采纳
3
关注TA
发私信
相关问题
1
请教USB Host
2
STM32F4调试USB 读卡器(Slave)提示格式化
3
急求 STM32F4 USB Device MSC+SD 的相关问题
4
USB 框架问题
5
USB键盘
6
LPC17xx 如何添加USB HOST设备
7
RT-Thread目前支持USB HOST了吗?
8
USB HOST的支持问题
9
RTT 2.0.1 USB存储设备问题,枚举到USBREQ_GET_MAX_LUN后复位
10
USB库已经很久没更新了
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
freemodbus主机在freertos的适配,参考rtthread例程
2
开源共生 商业共赢 | RT-Thread 2024开发者大会议程正式发布!
3
【24嵌入式设计大赛】基于RT-Thread星火一号的智慧家居系统
4
RT-Thread EtherKit开源以太网硬件正式发布
5
还在担心bsp不好维护吗?快使用yml管理主线bsp
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
rt_mq_消息队列_msg_queue
keil_MDK
ulog
MicroPython
C++_cpp
本月问答贡献
a1012112796
20
个答案
3
次被采纳
张世争
12
个答案
3
次被采纳
踩姑娘的小蘑菇
7
个答案
3
次被采纳
rv666
9
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
RTT_逍遥
1
篇文章
7
次点赞
大龄码农
1
篇文章
5
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部