`JSB
`aeai:
`
`
` N AXELSON225m.
`
`No custom drivers needed—use
`MNRPA amelie de DERG
`
`
`siore
`
`FISI Ex 2014-1
`Huawei v FISI
`IPR2018-00487
`
`
`
`
`
` USB
`
`Complete
`
`Everything You Need
`to Develop Custom USBPeripherals
`
`Jan Axelson
`
`a ys
`
`FISI Ex 2014-2
`Huawei v FISI
`IPR2018-00487
`
`
`
`copyright 1999 by Jan Axelson. All rights reserved.
`Published by Lakeview Research
`Cover by Rattray Design. Cover Photo by Bill Bilsley Photography.
`
`Lakeview Research
`2209 Winnebago St.
`Madison, WI 53704
`USA
`
`Phone: 608-241-5824
`Fax: 608-241-5848
`Email: info@ivr.com
`Web: http://www.lvr.com
`
`1413 12 11 1098765432
`
`Products and services named in this book are trademarks or registered trademarks of
`their respective companies. In all instances where Lakeview Research is aware of a
`trademark claim, the product name appearsin initial capitalletters, in all capital letters,
`or in accordance with the vendor’s capitalization preference. Readers should contact the
`appropriate companies for complete information on trademarks and trademark registra-
`tions. All trademarks and registered trademarks in this book are the property of their
`respective holders.
`Nopart of this book, except the programs and program listings, may be reproduced in
`any form, or stored in a database orretrieval system, or transmitted: or distributed in any
`form, by any means, electronic, mechanical photocopying, recording, or otherwise,
`without the prior written permission of Lakeview Research orthe author, except as per-
`mitted by the Copyright Act of 1976. The programs and program listings, or any portion
`of these, may be stored and executed in a computer system and may be incorporated into
`computer programs developed by the reader.
`.
`The information, computer programs, schematic diagrams, documentation, and other
`material in this book and the accompanying diskette are provided “as is,” without war-
`ranty of any kind, expressed or implied, including without limitation any warranty con-
`cerning the accuracy, adequacy, or completeness of the material or the results obtained
`from using the material. Neither the publisher nor the author shall be responsible for
`any claims attributable to errors, omissions, or other inaccuracies in the material in this
`book and the accompanying disc. In no event shall the publisher or authorbe liable for
`
`_
`
`FISI Ex 2014-3
`Huawei v FISI
`IPR2018-00487
`
`
`
`IPR2018-00487
`
`
`In order to design and program a USB device, you need to knowacertain
`amount about the inner workingsof the interface. This is true even though
`the hardware and system software handle manyofthedetails automatically.
`This and the next three chapters are a tutorial on how USBtransfers data.
`This chapter has the essentials that apply to all transfers. Thefollowing
`chapters cover the four transfer types supported by USB, the enumeration
`process, and the standard requests used in controltransfers.
`USB is complicated, and much of what you need to know is intertwined
`with everything else. This makes it hard to know wheretostart. In general, I
`try to begin withthe big picture and work downtothe details. Unavoidably,
`some of the things I refer to won't be explained in detail until later. And
`some things are repeated because they're important and relevant in more
`than oneplace.
`The information in these chapters is dense. If you don’t have a background
`in USB, you won't absorbit all in one reading. You should, however, get a
`
`
`
`
`
`
`Inside USB Transfers
`
`3
`
`Inside USB Transfers
`
`USB Complete
`
`FISI Ex 2014-4
`Huaweiv FISI
`
`FISI Ex 2014-4
`Huawei v FISI
`IPR2018-00487
`
`
`
`
`
`
`Chapter 3
`
`feel for how USB works, and will know where to look later when you need
`to check the details.
`
`You don’t need to know every bit of this informationin order to get a
`project up and running, but I’ve found that understanding something about
`how thetransfers work helps in deciding which transfer types to use, in writ-
`ing the firmware for the controller chip, and in tracking downtheinevitable
`bugs that will occur when youtry out yourcircuits and code.
`The ultimate authority on the USBinterface is the specification published
`by its sponsoring members. The specification document, Universal Serial
`Bus Specification,
`is available on the USB Implementers Forum’s website.
`However, by design, the specification omits information and tips that are
`unique to any operating system or controller chip, and this type of informa-
`tion is essential when youre designing a product for the real world.
`
`IPR2018-00487
`
`
`
`
`
`
`
`Transfer Basics
`You can divide USB communicationsinto two types, depending on whether
`they're used in initial configuration or in applications. In configuration
`communications,
`the host
`learns about
`the device and prepares it for
`exchanging data. Most of these communications take place when the host
`enumerates the device on powerup or attachment. Application communica-
`tions occur when applications on the host exchange data with an enumer-
`ated device. These are the communications that carry out
`the device's
`purpose. For example, for a keyboard, the application communications are
`the sending of keypress data to the host, to tell an application to display a
`character or perform otheractions.
`
`Configuration Communications
`During enumeration, the device's firmware respondsto a series of standard
`requests from the host. The device must identify each request, return the
`requested information, and takeother actionsspecified by the requests.
`
`On PCs, Windows performs the enumeration, so there’s no user program-
`ming involved. However,
`to complete the enumeration, Windows must
`
`USB Complete
`
`FISI Ex 2014-5
`Huaweiv FISI
`
`FISI Ex 2014-5
`Huawei v FISI
`IPR2018-00487
`
`
`
`inside USB Transfers
`
`have twofiles available: an INFfile that identifies the filename and location
`of the device's driver, and the device driveritself.
`
`Depending onthe device and howit will be used, the device driver may be
`one thats included with Windows or provided by the chip or peripheral
`vendor. The INFfile is a text file that you can usually adapt from an exam-
`ple provided by the driver’s provider. Chapter 11 has more details about
`device drivers and INFfiles.
`
`: you need
`
`,
`Ring about
`Ise, in writ-
`
`;
`:
`
`;
`j
`
`:
`
`‘
`hs that are
`
`
`
`
`
`
`Application Communications
`After the host has exchanged enumeration information with the device and
`“a device driver has been assigned and loaded, the application phase can be
`fairly straightforward. At the host, applications can use standard Windows
`API functions to read and write to the device. At the device, transferring
`datatypically requires placing data to send in the USB controller's transmit
`buffer, reading received data from the receive buffer when a hardware inter-
`rupt signals that data has arrived; and on completing a transfer, ensuring the
`device is ready for the next transfer. Most devices also require some addi-
`tional support for handling errors and other events.
`Each data transfer on the bus uses one of four transfer types: control, inter-
`rupt, bulk, or isochronous. Each has a format and protocol suited for partic-
`ular uses.
`
`IPR2018-00487
`
`Managing Data on the Bus
`The USB’s twosignal lines carry data to and from all of the devices on the
`bus. The wires form a single transmission path thatall of the devices must
`share. Unlike RS-232, which has a TX line to carry data in one direction
`and an RX line for the other direction, USB’s pair of wires carries a single
`differential signal, with the directionstaking turns.
`The hostis in chargeofseeing thatall transfers occur as quickly as possible.
`It manages the traffic by dividing time into 1-millisecond frames and giving
`each transfer a part of each frame (Figure 3-1).
`
`USB Complete
`
`FISI Ex 2014-6
`Huaweiv FISI
`
`FISI Ex 2014-6
`Huawei v FISI
`IPR2018-00487
`
`
`
`Chapter 3
`
`
`DEVICE1,ENDPOINT2DEVICE2,ENDPOINT2DEVICE5,ENDPOINT3
`DEVICE5,ENDPOINT3
`DEVICE5,ENDPOINT3
`
` ENDPOINT2
`DEVICE2,ENDPOINT@
`DEVICES,ENDPOINT3
`DEVICE5,ENDPOINT3
`DEVICE1,ENDPOINT2DEVICE2,ENDPOINT@
`DEVICE2,ENDPOINT@
`STARTOFFRAME
`STARTOFFRAME
`[~[STARTOFFRAME
`DEVICE|,
`
`—_|
`
`1-MILLISECOND FRAME
`I-MILLISECONO FRAME
`1-MILLISECOND FRAME
`Figure 3-1: The host schedulestransactions within 1-millisecond frames. Each
`frame beginswith a Start-of-Frame packet, followed by transactions that transfer
`data to or from device endpoints. The host may schedule transactions anywhere
`it wants within a frame.
`
`IPR2018-00487
`
`
`Eachtransfer consists of one or more transactions. Control transfers must
`use multiple transactions because they have separate Setup, (optional) Data,
`and Status stages. Other transfers use multiple transactions when they have
`more data than fits in one transaction. Depending on how the host sched-
`ules the transactions and the speed of a device's response, a transfer’s transac-
`tions mayall be in a single frame, or they may use multiple frames.
`Because all of the transfers share one data path, each transaction must
`include the address of the transaction’s source or destination. Every device
`has a unique address assigned by the host, andall data travels to or from the
`host. Each transaction begins with the host’s sending a block of information
`that includes the address of the receiving device as well as a specific location,
`called an endpoint, within the device. Everything a device sends is in
`Tesponse to receiving a request from the host to send either data orstatus
`information in response to received data.
`
`PC-to-PC Communications
`The USBdoesn’ allow peripherals to exchangedata directly. All communi-
`cations must go through a host. And there’s no way for two hosts to send
`data to each other without going through a peripheral. There is, however, a
`way to enable two PCs to communicate using their USB ports. Cypress
`Semiconductor’s EZ-Link contains two USB peripheral controllers that
`
`USB Complete
`
`FISI Ex 2014-7
`Huaweiv FISI
`
`FISI Ex 2014-7
`Huawei v FISI
`IPR2018-00487
`
`
`
`
`
`
`
`:C
`
`_——_—__—
`E
`
`
`
`Inside USB Transfers
`
`
`
`|
`
`|
`
`\
`
`
`
`
`
`
`\
`ifi
`:
`|
`
`
`
`
`
`
`
`
`
`
`
` 4
`
`USB Complete
`
`FISI Ex 2014-8
`Huaweiv FISI
`IPR2018-00487
`
`share a buffer. Each controller connects to a different PC and uses the shared
`buffer to exchangedata. Similar products are available from other vendors.
`Elementsof a Transfer
`levels deep.
`Understanding USBtransfers requires looking inside several
`Each transfer is made up of transactions. Each transaction is made up of
`packets. And each packet contains information. To understand transactions,
`packets, and their contents, you also need to know about endpoints and
`pipes.
`Device Endpoints
`All transmissions travel to or from a device endpoint. The endpoint is a
`buffer that stores multiple bytes. ‘Typically it’s a block of data memory or a
`register in the controller chip. The data stored at an endpoint may be
`received data, or data waiting to transmit. The host has buffers for received
`data and data ready to transmit, but
`the host doesn’t have endpoints.
`Instead, it serves as the starting point for communicating with the device
`endpoints.
`The specification defines a device endpoint as “a uniquely addressable por-_
`tion ofa USB device thatis the source or sink ofinformation in a communi-
`cation flow between the host and device.” This suggests that an endpoint
`carries data in one direction only. However, as I'll explain, a control end-
`pointis a special case thatis bidirectional.
`The unique address required for each endpoint consists of an endpoint
`numberand direction. The number may range from 00h to OFh. The direc-
`tion is trom the host's perspective: IN is toward the host and OUTis away
`from the host. An endpoint configured to do control transfers must transfer
`data in both directions, so a control endpoint actually consists of a pair of
`IN and OUT endpoints that share an endpoint number.
`ever, 2
`Every device must have Endpoint 0 configured as a control endpoint.
`-ypress
`There's rarely, if ever, a need for additional control endpoints.
`fs
`that
`
`
`
`.
`
`
`
`
`
`
`
`
`
`
`is. Each
`it transfer
`anywhere
`
`fers must
`nal) Data,
`they have
`pst sched-
`is transac-
`E
`
`pn must
`
`fy device
`from the
`if
`ation
`location,
`Hs
`is in
`hr status
`
`mmMuni-
`Eo send
`
` Bplete
`
`\
`
`FISI Ex 2014-8
`Huawei v FISI
`IPR2018-00487
`
`
`
`
`
`
`One of the duties of a hub is to detect the attachment and removal of
`devices. Each hub has an interrupt IN pipe for reporting these events to the .
`
`host. On system boot-up, the host polls its root hub to learn if any devices ”
`
`are attached, including additional hubs and devices attached to them. After
`
`the host continues to poll periodically to learn of any newly
`boot-up,
`
`attached or removed devices.
`
`the host sends a series of requests to the
`On learning of a new device,
`device’s hub, causing the hub to establish a communications path between
`
`the host and the device. The host then attempts to enumerate the device.
`
`Enumeration is the initial exchange ofinformation that enables the host’s
`device driver to communicate with the device. The process consists of
`
`assigning an address to the device, reading descriptive data from the device,
`
`assigning and foading a device driver, and selecting a configuration from the
`
`options presented in the retrieved data. The device is then configured and
`
`ready to transfer data using any ofthe endpoinis in its configuration,
`The host enumerates by sending control transfers containing standard USB
`requests to Endpoint 0. AH USB devices must support control transfers,
`
`standard USB requests, and Endpoint 0. For a successful enumeration, the
`
`device must respond to each request by returning the requested information
`
`and taking other requested actions.
`From the user’s Perspective, enumeration should be invisible and automatic,-
`except for in some cases a window that announces the detection of a new ©
`device and whether or not the attempt to configure it succeeded. Sometimes _
`on first use, the user will need to provide a disk containing the INF file and
`device driver,
`When enumeration is complete, Windows adds the new device to the
`Device Manager display in the Control Panel. Figure 5-[ shows an example.
`
`
`
`Chapter 5
`
`The Process
`
`
`
`FISI Ex 2014-9
`Huawei v FISI
`IPR2018-00487
`
`
`
`is Modern
`a) Honitors
`2 Mouse
`2) Network adapters
`afPorts (COM& LPT)
`€& SCSI controtters
`ch
`ic 56, Sound, video and game contolers
`1 Systernt devices
`fee Tape drive controllers
`ape drives
`
`
`
`
`: ee Generat purpose USB Hub
`- oop Intel 42371 ABVEG PO to US6 Universet dost Cantatas
`ep RDC-HOAG
`+eP USB Root Hub
`
`Figure 5-1: The Device Manager in Windows’ Control Panel lists all detected
`USB devices. (Some deviceswill be listed by type, such as keyboard or modem,
`father than under Universal Serial Bus controllers.)
`
`In a typical peripheral, the peripheral’s program code contains the informa-
`tion the host will
`request, and the program code must recognize and
`respond to requests for the information. Some application-specific chips
`(ASICs) manage the enumeration entirely in hardware and require no firm-
`ware support. On the host side, under Windows there’s no need to write
`code for enumerating, because Windows handles it automatically. Windows
`will look for a special text file called an INF file chat tells Windows what
`driver to.use for the device.
`
`
`
`Enumeration Steps
`During the enumeration process, a device moves through fourof the six pos-
`sible device states: Powered, Default, Address, and Configured. (The other
`
`USB Complete
`
`FISI Ex 2014-10 75
`Huawei v FISI
`IPR2018-00487
`
`
`
`FISI Ex 2014-10
`Huawei v FISI
`IPR2018-00487
`
`
`
`Chapter 5
`
`the device has defined
`states are Attached and Suspended.) In each state,
`capabilities and behavior. These are the events that cause and occur during
`
`enumeration:
`1. The user plugs a device into a USB port. Orthe system powers up with
`a device already plugged into a port. The port may be on the root hub atthe
`host or on a hub that connects downstream ofthe host. The hub normally
`provides powerto the port, and the device is in the Powered state.
`2. The hub detects the device. The hub monitors the voltages on the signal
`lines of each ofits ports.
`The hub has a 15-kilohm pull-downresistor on each ofthe port's twosignal
`lines (D+ and D-), while a device has a 1.5-kilohm pull-up resistor on either
`D+ (for a full-speed device) or D- (for a low-speed device). When a device
`plugs into a port, the device’s pull-up brings thatline high, enabling the hub
`to detect that a device is attached. Chapter 16 has more on how hubs detect
`devices.
`
`IPR2018-00487
`
`the hub continues to provide power but doesn’t
`On detecting a device,
`transmit USB traffic to the device, because the device isn’t yet ready to
`receiveit.
`3. The host learns of the new device. Each hub uses its interrupt pipe to
`report events at the hub. The report indicates only whether the hub or a
`port (and if so, which port) has experienced an event. When the hostlearns
`of an event, it sends the hub a Get_Port_Starus request to find out more.
`Get_Port_Status and the other
`requests described here are standard
`hub-class control
`requests that all hubs understand. The information
`returnedtells the host when a device is newly attached.
`4, The hubresets the device. When a host learns of a new device, the host
`controller sends the hub a Set_Port_Feature request that requests the hub to
`reset the port. The hub places the device’s USB datalines in the Reset condi-
`
`FISI Ex 2014-11
`Huawei v FISI
`IPR2018-00487
`
`
`
`states and the deviceis ready to respondto control transfers over the default
`pipe at Endpoint 0. The device can now communicate with the host, using
`the default address of Oh. At this point, the device can draw no more than
`100 milliamperes from the bus.
`6. The hub detects the device's speed. Either just before or just after the
`Reset, the hub detects the device’s speed by examining the voltages on the
`twosignal lines. The hub detects the speed of a device by determining which
`line has the higher voltage when idle. The hub sends the information to the
`hostin response to the next Get_Port_Status request.
`7. The host sends a Get_Descriptor request to learn the maximum
`packet size of the default pipe. The host sends the request
`to device
`address 0, Endpoint 0. Because the host enumerates only one device at a
`time, only one device will respond to communications addressed to device
`address Q.
`The maximum packetsize is in the eighth byte ofthe descriptor, so the host
`needs to read only thefirst 8 bytes. A Windows host requests 64 bytes, but
`after receiving just one packet (whether or notit has 64 bytes), it begins the
`_ Status stage. On completion of the status stage, the host requests the hub to
`reset the device (repeating steps 4 and 5). The specification doesn’t require a
`reset here, because devices should be able to handle the host’s abandoning a
`control transfer at any time by responding to the next Setup stage. Resetting
`is a precaution that ensures that the device will be in a knownstate when the
`reset ends,
`
`8. The host assigns an address. The host controller assigns a unique
`address to the device by sending a Set_Address request. The device reads the
`Tequest, returns an acknowledge, and stores the new address. The device is
`now in the Address state. All communications ftom this point on use the
`new address. The addressis valid only until the device is detached ot the sys-
`
`
`FISI Ex 2014-12 es
`Huawei v FISI
`
`IPR2018-00487
`
`
`FISI Ex 2014-12
`Huawei v FISI
`IPR2018-00487
`
`
`
`Chapter 5
`
`tem powers down. On the next enumeration, the device may be assigned a _
`different address.
`
`the device’s abilities. The host sends 4 -
`learns about
`9. The host
`Get_Descriptor request to the new address to read the device descriptor, this
`time reading the whole thing, The descriptor is a data structure containing
`the maximum packet size for Endpoint 0, the number of configurations the “
`device supports, and otherbasic information aboutthe device. The host uses
`this information in the communications that follow.
`
`IPR2018-00487
`
`Windows then requests the configuration descriptor again, this time using —
`the retrieved total length, up to FFh bytes. This causes the device to send the -
`descriptors total more aaOFopie
`“ovis obtains the full set of =
`
`descriptors on a third request. Each descriptor begins with its length and
`“datathat follows. The Descriptors section in this chapter has more on what-
`each descriptor contains.
`10. The host assigns and loads a device driver (except for composite :
`devices). After the host learns as much as it can about the device from its
`descriptors, it looks for the best match in a device driver to manage commu-
`nications with the device. In selecting a driver, Windows tries to match the
`Vendor and Product
`IDs, Release Number, and/or class
`information
`retrieved from the device with the information stored in the system’s INF
`files. After the driver is loaded, it often requests the device to resend descrip-
`
`The host then continues to learn about the device by requesting the one or
`more configuration descriptors specified in the device descriptor. A Win-:
`dows hostbeginsbyrequesting just the configurationdescriptor’s nine bytes.
`Included in these bytes is the total length of the configuration descriptor |
`and all of its subordinate descriptors.
`
`
`
`FISI Ex 2014-13
`Huawei v FISI
`IPR2018-00487
`
`
`
`tiple configurations, the driver can decide which to use based on whatever
`information it has about how the device will be used, or it may ask the user
`whatto do,or it may just select the first configuration. The device reads the
`request andsets its configuration to match. The device is now in the Config-
`ured state and the device's interface(s) are enabled.
`
`Drivers for the interfaces in compound devices may be assigned now. As
`with other devices, if Vendor and Produce IDs are available, the host uses
`these to select the driver for an interface. Otherwise, the host uses whatever
`class, subclass, and protocol values are available.
`
`The device is now ready for use.
`
`The other two device states, Attached and Suspended, may exist at any time.
`Attached state. If the hub isn't providing power (VBUS) to the port, the
`device is in the Attached state. This may occur if the hub detects an
`over-current condition, or if the host requests the hub to remove power
`from the port. With no power on VBUS, the host and device can’t communi-
`cate, so from their perspective, the situation is the same as when the device
`isn't attached atall.
`
`Suspended State. The Suspended, or Suspend, state means that the device
`has seen noactivity on the bus for at least 3 milliseconds. In the suspended
`state, the device must consume minimal bus power. Both configured and
`unconfigured devices must support the Suspended state. Chapter 17 has
`
`Enumerating a Hub
`
`in exactly the same way it enumerates a device. If the hub has devices
`
` Hubsare also USB devices, and the host enumerates a newly attached hub
`
`USB Complete
`
`FISI Ex 2014-14
`Huawei v FISI
`IPR2018-00487
`
`FISI Ex 2014-14
`Huawei v FISI
`IPR2018-00487
`
`
`
`Chapter 5
`
`attached, the hostalso enumerates each of these after the hub informs the
`host of their presence,
`
`Device Remova]
`When a user removes a device from the bus, the hub disables the device’s
`port. The host learns that the removal occurred after polling the hub, learn-
`ing thar an event has occurred, and sending a Get_Port_Status request to:
`find out what the event was. Windows then removes the device from the
`Device Manager's display and the device's address becomes available to.
`another newly attached device.
`
`AboutDescriptors
`that
`Descriptors are data structures, or formatted blocks of information,
`enable the host to learn about a device. Each descriptor contains informa-
`tion abouteither the device as a whole or an element within the device,
`All USB peripherals must respond to requestsfor the standard USB descrip-
`tors. This meansthat the peripheral must do two things: store the informa-
`tion that
`the host may request, and respond to requests with the
`information in the expected format.
`
`Types
`As described above, during enumeration the host uses control transfers to
`tequest descriptors
`from the device. As enumeration Progresses,
`the
`requested descriptors concern increasingly small elements ofthe device:first
`the entire device, then each configuration, each configuration’s Interface(s),
`andfinallyeachinterface’s endpoint(s),
`The higher-level descriptors inform the host of any additional, lower-level
`
`FISI Ex 2014-15
`Huawei v FISI
`IPR2018-00487
`
`