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

一、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次,则第三次主机对设备进行挂起,在电脑上设备管理器上带有黄色的问号


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

luckywang1103

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值