×
接口总线驱动 > 总线 > 详情

USB设备的枚举

发布时间:2020-05-28 发布时间:
|
一,枚举是如何进行的
此处摘录一个,[12]中的关于windows下USB枚举的过程的总结:
1. The host or hub detects the connection of a new device via the device's pull
up resistors on the data pair. The host waits for at least 100ms allowing for
the plug to be inserted fully and for power to stabilise on the device.
2. Host issues a reset placing the device is the default state. The device may
now respond to the default address zero.
3. The MS Windows host asks for the first 64 bytes of the Device Descriptor.
4. After receiving the first 8 bytes of the Device Descriptor, it immediately issues
another bus reset.
5. The host now issues a Set Address command, placing the device in the
addressed state.
6. The host asks for the entire 18 bytes of the Device Descriptor.
7. It then asks for 9 bytes of the Configuration Descriptor to determine the
overall size.
8. The host asks for 255 bytes of the Configuration Descriptor.
9. Host asks for any String Descriptors if they were specified.
At the end of Step 9, Windows will ask for a driver for your device. It is
then common to see it request all the descriptors again before it issues a Set
Configuration request.
以上大概的含义如下


二,枚举的过程
1,获取设备描述符
主机向address 0发送USB协议规定的Get_Device_Descriptor命令,以取得却缺省控制管道所支持的最大数据包长度,并在有限的时间内等待USB设备的响应,该长度包含在设备描述符的bMaxPacketSize0字段中,其地址偏移量为7,所以这时主机只需读取该描述符的前8个字节。注意,主机一次只能列举一个USB设备,所以同一时刻只能有一个USB设备使用缺省地址0。




2,设置地址
主机通过发送一个Set_Address请求来分配一个唯一的地址给设备。设备读取这个请求,返回一个确认,并保存新的地址。从此开始所有通信都使用这个新地址



3,获取设备描述符
主机向新地址重新发送Get_Device_Descriptor命令,此次读取其设备描述符的全部字段,以了解该设备的总体信息,如VID,PID。



4,获取配置描述符
主机向设备循环发送Get_Device_Configuration命令,要求USB设备回答,以读取全部配置信息。





5,获取配置描述符其它内容




6再次获取设备和配置描述符





7,主机发送Get_Device_String命令,获得字符集描述(unicode),比如产商、产品描述、型号等等。这是可选项,如果设备有这些信息,主机将会弹出窗口,展示发现新设备的信息,产商、产品描述、型号等。本例中Device_Descriptor,Device_Configuration,Device_InterFace中有关字符串的字段都为0,因而没有字符串描述,所以此处无此命令.

8,设置配置
根据Device_Descriptor和Device_Configuration应答,主机判断是否能够提供USB的Driver,一般主机能提供几大类的设备,如键盘、鼠标、游戏操作杆、存储、打印机、扫描仪等,该操作就在后台运行。
如果主机不能提供驱动,此时将会弹出对话框,索要USB的Driver。
加载了USB设备驱动以后,主机发送Set_Configuration(x)命令请求为该设备选择一个合适的配置(x代表非0的配置值)。如果配置成功,USB设备进入“配置”状态,并可以和客户软件进行数据传输。




至此,常规的USB完成了其必须进行的配置和连接工作。查看注册表,能够发现相应的项目已经添加完毕,至此设备应当可以开始使用。不过,USB协议还提供了一些用户可选的协议,设备如果不应答,也不会出错,但是会影响到系统的功能。  

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
工程师常用的接口大全