您的位置:首页 > 其它

电子工程师名片——USB设备枚举过程

2013-09-23 20:20 555 查看
一、USB枚举过程

使用的工具是CATC(USB协议分析仪),整个成功枚举过程见地址:http://download.csdn.net/detail/luckywang1103/6309369 c8051f320_USB枚举过程.usb

1、GetDescripor

U主机一次GetDescriptor是在USB控制传输中完成,控制传输分为Setup Stage、Data Stage和Status Stage。

1)Setup Stage



SOF帧是USB总线的同步信号,每隔1ms主机会向设备发出一个SOF帧。

在枚举之前,设备还没有分配地址所以用的是默认地址0和端点0,Setup Stage的数据包必须为DATA0,与之对应的Status Stage的数据包必须为DATA1

DATA0 80 (bmRequestType) Device to Host,Standard,Recipient is device

06
(bRequest) GetDescriptor

00 01 (wValue) 51单片机为大端模式,01为Descriptor Type,00为Descriptor Index

00 00 (wIndex)

40 00 (wLength) 51单片机为大端模式,Descriptor Length,64 Bytes

2)Data Stage



因为在Setup Stage主机要求设备返回64 Bytes的Descriptor Data以便主机了解缺省管道的最大信息包尺寸,所以设备在DATA1中返回64 Bytes。

这64 Bytes中有Device_Descriptor 18 Bytes (12 01 00 02 00 00 0040 12 34 56 78 00 00 00 00 00 01) 最大信息包尺寸为64 Bytes

Configuration_Descriptor 9 Bytes (09 02 3C 00 01 01 00 80 FA)

Interface_Descriptor 9 Bytes (09 04 00 00 02 08 06 50 00)

EndpointIN1_Descriptor 7 Bytes (07 05 81 02 40 00 00)

EndpointOUT1_Descriptor 7 Bytes (07 05 01 02 40 00 00)

EndpointIN2_Descriptor 7 Bytes (07 05 82 02 40 00 00)

EndpointOUT2_Descriptor 7 Bytes (07 05 02 02 40 00 00)

3)Status Stage



Data Stage结束之后,由于在Data Stage用的是IN令牌,所以在Status Stage用与IN方向相反的OUT来指示状态阶段。

并且Satus Stage的数据包是一个0长数据包

USB2.0规范没有要求这里有复位动作,复位是一个谨慎的动作,在复位结束后可保证设备处在一个已知状态。

2、SetAddress

第一次主机GetDescriptor之后接着主机要对设备分配地址

1)Setup Stage



DATA0 00 (bmRequestType)Hostto Device,Standard,Recipient is device

05
(bRequest) SetAddress

02 00 (wValue) 大端模式,Device Address 0x02

00 00 (wIndex)

00 00 (wLength)
2)Status Stage



SetAddress没有数据阶段,所以在Setup Stage之后立刻就是Status Stage

3、GetDescriptor——>wValue字段中Descriptor Type为0x01表示device descriptor





4、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





5、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





6、GetDescriptor——>wValue字段中Descriptor Type为0x01表示device descriptor





7、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





8、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





9、SetConfiguration





10、GetMaxLun





11、开始识别USB设备具体某一类



二、USB枚举失败

USB枚举失败过程:http://download.csdn.net/detail/luckywang1103/6309377 USB枚举失败会复位.usb

在控制传输的时候如果设备回复给主机的描述符错误的话,主机会重新复位设备,连续3次都出错的话,主机停止枚举设备。

1、GetDescriptor——>wValue字段中Descriptor Type为0x01表示device descriptor





2、SetAddress





3、GetDescriptor——>wValue字段中Descriptor Type为0x01表示device descriptor





4、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





5、GetDescriptor——>wValue字段中Descriptor Type为0x02表示configuration descriptor





这一步设备回的Descriptor有误,连续回了3次一样的错误的127个Bytes,于是主机对设备进行复位

以上几个步骤连续重复3次,则第三次主机对设备进行挂起,在电脑上设备管理器上带有黄色的问号

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: