element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Connector Technology & Design
  • Technologies
  • More
Connector Technology & Design
Forum 主题:初涉USB,初学者USB入门总结(1)枚举
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Connector Technology & Design to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 128 subscribers
  • Views 96 views
  • Users 0 members are here
Related

主题:初涉USB,初学者USB入门总结(1)枚举

YYD
YYD over 14 years ago

一,概述
现在很多的主控上都带有USB的功能,但是对于初学者来说,这方面应用还是比较棘手,因为usb的不但固件程序需要编写,PC端的驱动也要编写,而且驱动写好了还要写个上位机才能看出效果。这样调试起来十分困难,建议从USB的键盘,鼠标开始做,了解清楚了,再做自己的协议就比较简单了。
USB的概念历史啥的这里就不说了。我们先不管具体的数据包格式,这一节先从整个包的层面上简单的说,过程是这样的,
---------------------------------------设备插入-------------------------------------------------------------
1)    主机会轮回查询各个USB端口,主机检测到D+与D-之间有电压差,就认为有新的设置接入。主机等待100ms后发出复位请求。设备接到复位请求后将产生一个外部中断信号。
---------------------------------------枚举过程------------------------------------------------------------
2)    主机这时候只是知道有新的设备插入了,但是不知道插进来个什么东西,所以就开始询问它是什么设备,怎么用,负荷能力怎么样。这个时侯就进入了枚举过程。因为刚刚插入的设备没有分配地址,就用默认地址0,首先发送一个Get_descriptor(获取设备描述符)指令包,设备接到包后就开始解析包(其实就是你在固件程序里判断处理) ,然后按固定格式返回自己设备的设备描述符,这一步主要是主机知道你的USB设备的基础属性,比如支持的传输数据长度,电流负荷多少,支持那个USB版本,以及以后方便电脑找驱动的PID,VID。
3)    这时候主机知道你(你做的设备,简称你吧)的数据长度还有电流大小后,下一步就是给你分配一个属于你的地址。
4)    给你一个地址后就开始询问你的具体配置。首先发送一个试探性的设备配置请求Get_configuration(要求固定返回9个设备配置字),你接到后就开始发送9字节的设备配置字,其中包括你的配置字的总长度,这样主机就知道你的配置到底有多长,然后再发一次设备配置请求,这时你就开始上传所有的配置字。这个时侯主机就已经很明白你的工作方式就各种特性,然后就可以正常工作了
5)    如果你在前面的某些配置(以后章节详细说明)要求要说明自己的名字什么的,这里还要上传字符串描述符。
6)    如果是鼠标或者键盘还要上传报告描述符
---------------------------------------正常数据阶段------------------------------------------------------
7)    这个时侯你已经被主机正式接受并且注册了,你可以通过自己写测驱动或通用驱动与电脑进行通讯了。

 

以上是简单的描述,详细的后面章节再做介绍,学习一个东西关键是首先要知道这个东西是什么,简单的工作原理。对于USB的工作我这里做个比方,
     主机好比一个公司,你就是USB设备,要进入公司首先要面试(枚举),你到了面试现场(第一次插入设备),面试官首先了解到你的外表,性别已经你要应聘的岗位(设备描述符),然后给你一个号,以后就开始按号叫人,当你被叫到就开始问你的专业知识,性格等(配置描述符),如果你比较合适(通过了枚举)你就会录取了,并且注册一个你的信息到公司(驱动安装,并且写入注册表)。等你下次来公司,只要把工号(PID,VID)报上,就知道是你来了。

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube