Universal Serial (USB)

The Universal Serial Bus is a cable bus that allows high- Mbits/sec or 12 Mbits/sec, over a maximum cable length speed data exchange between a host computer and a variety of 5 meters. USB cable contains 4 wires: of peripherals. Supporting both attachment and removal of peripherals while the host system is running, USB was ■ Two of the wires form a twisted pair, which is used for dif- designed to provide a convenient and universal interface for ferential data transmission connecting peripherals to desktop computers, without the ■ The remaining two wires provide power and ground for de- need to power down the computer. In this article Barbara vices that don’t have their own 5 V DC power supply. provides an introduction to the USB standard, outlining the goals of the USB committee and describes the physical USB device speeds cabling and connectors, the physical and logical bus topol- The USB specification classifies USB devices into two main ogies, the types of data transfers, and the communication flow types: between the different layers of USB software. ■ Low-speed devices ■ Full-speed devices he Universal Serial Bus (USB) was originally designed by a consortium of telecom companies and desktop PC Low-speed devices Tsuppliers, which included Compaq, DEC, IBM, Intel, Low-speed USB devices (typically switches, mice and , Microsoft, NEC and Northern Telecom. Their primary purpose and keyboards) transfer USB data at 1.5 Mbits/sec. The cost of for working together was to provide a computer-telephony these devices is kept down by the fact that their low-bandwidth connection mechanism. cables can be designed without shielding.

However, the members soon realized that the USB was well Full-speed devices suited to many applications outside the area of computer- Full-speed USB devices (such as video, disk and LAN telephony integration. interfaces) transfer data at 12 Mbits/sec. As might be expected, these full-speed devices are designed for performance, and their The goals of the USB committee were threefold: support of this higher data transfer rate is more expensive.

■ To provide an architecture that could link desktop PCs to the telephone network USB usage in 1998 ■ To develop an architecture that truly offered an easy way for users to connect and reconfigure peripherals ■ To provide a means by which a large number of peripherals could be attached to desktop PCs, without the traditional tangle of cables and different I/O interface standards. USB The USB connectivity vision Despite the fact that USB is well defined, desktop computer suppliers won’t switch over to this new peripheral standard Mouse Printer Video LAN immediately. Most vendors plan to take a phased approach, by providing one (or possibly two) USB ports on their desktop Keyboard Serial Audio SCSI system, while still providing the traditional PC I/O interface ports. (See Figure 1) This transitional phase will allow time for USB usage in 200X both hardware and software companies to prepare for the shift to the USB architecture. USB USB USB While there are several other competing I/O architectures, USB will probably become the dominant desktop I/O architecture for Keyboard Mouse several reasons. (See the sidebar entitled The competition on Video Printer page 54.) LAN Scanner Digital audio I/O The USB physical media Figure 1 Digital telephony USB supports up to 127 devices, with bandwidths of 1.5 Modem

Reprinted from VMEbus Systems / June 1998 / 1 Copyright 1998 ~ All rights reserved Universal Serial Bus (USB)

USB physical topology ■ self-powered hubs The USB architecture supports a hierarchical topology, where ■ low bus-powered devices “downstream” hubs and devices are connected to “upstream” ■ high bus-powered devices hubs (in a star-like pattern) with the restriction of a maximum ■ self-powered devices of 5 hubs along any given chain. Figure 2 shows the tiers in this hierarchy. Hubs are intelligent devices that not only act as signal DC power flows downstream from the root hub to the various repeaters and routers, but also provide some basic power hubs and peripherals [4]. The maximum power that any device management [3]. can draw from the upstream bus is 500 mA @ 5V, with an added

The root hub (in the USB host controller) is the anchor point Host (Root Hub) for all of the USB ports in the system. Data flows between the Host (Root Tier) root hub and the USB devices through the signal lines and hubs Upstream of the hierarchy in 2 directions: Tier 1 Hub 1 ■ downstream, starting at the root hub, and flowing from hub Tier 2 to hub, until it ultimately flows into a peripheral device Node ■ upstream, starting from a peripheral device, and flowing Hub 2 Node from hub to hub, until it reaches the root hub Tier 3 Downstream Hub 3 Hub 4 Node Node USB power distribution Tier 4 Each USB hub or peripheral might have its own local power supply, or it might draw its power from the bus, through its upstream cable. USB devices can be classified into 5 categories, Node Node Node Node based on how they derive their power:

■ bus-powered hubs Figure 2 The competition There are several I/O architectures that are competing with Mbits/sec over a maximum cable length of 4 feet [1]. However, USB to provide peripheral interconnection to desktop GeoPort was designed strictly to support telephony devices computers, including: and applications, and has never been extended to support other types of devices outside of this category. [2]. ■ ■ Geoport Access.bus ■ Access.bus Access.bus uses: ■ Firewire (IEEE1394) ■ a hardware layer based on the Phillips I2C bus [8] Apple Desktop Bus ■ a software layer developed by Digital, to provide additional The Apple Desktop Bus (ADB) is a low-speed serial bus that functionality for I2C connects input devices, such as keyboards, mouse devices and graphics tablets to a computer. ADB provides a I2C bus is an acronym for Inter-IC bus. That name explains its simple read/write protocol for up to 16 devices. ADB supports purpose, which is to provide a communication link between data rates of up to 90 Kbits/sec. Some disadvantages of ADB integrated circuits. This bus provides 2 active wires, and a single are its relatively low data rate, and the fact that it is not an ground connection. The active wires are the Serial Data line and entirely “open” standard because Apple Computer owns the Serial Clock line, which are both bi-directional [8]. patents on ADB. Access.bus is an extension of I2C that routes the Serial Data GeoPort and Serial Clock lines through cables, to support keyboards, GeoPort has historically been an Apple proprietary interface. mice, monitors and microcontrollers. It provides speeds up to However, Apple is currently licensing the GeoPort spec- 100 Kbits/sec, and the protocols provided by its software layer ification to other companies. Apple Computer developed this allow it to interconnect up to 127 I/O devices. It is royalty free, interface to enable Macintosh telephony applications, but cable lengths are very limited, and there are no lines in the including both voice and data. cable for distribution of DC power to devices.

Apple’s GeoPort Telecom Adapter provides hardware and Firewire (IEEE1394) software that supports: Firewire (IEEE1394) supports up to 63 peripheral devices, and offers very high data transfer rates – from 100 Mbits/sec to 400 ■ data communications Mbits/sec. It provides ample bandwidth to support almost any ■ communications peripheral, and is well suited to I/O applications that require ■ telephony services such as voice mail very high-speed data transfers. However, its complexity (and its high cost) make it impractical as a desktop I/O interconnect The standard GeoPort uses RS-422 signaling, and provides a for low-performance, low-cost peripherals, such as mice and point-to-point link that supports data transfer rates up to 2 keyboards. [2]

2 / Reprinted from VMEbus Systems / June 1998 Copyright 1998 ~ All rights reserved restriction that the maximum current that it can draw during The logical USB architecture startup is 100 mA. Figure 4 shows the logical topology of the USB architecture shown in Figure 2. While the devices are physically attached to A self-powered hub can be designed with a power supply that the USB in a tiered, star topology, the details of this physical provides the maximum DC current (500 mA @ 5V) to each of hierarchy are hidden from the application program by the system its downstream ports. However, a bus-powered hub has only the software, which presents each logical device to the application DC power from the upstream cable (500 ma @ 5V) to distribute program as a collection of endpoints. The application program to all of its downstream ports. If several devices are connected can then exchange data directly with each endpoint. [1]. This to its downstream ports, the bus-powered hub might draw more logical connection to each device endpoint is represented by a than its allotted 500 mA. point-to-point line segment in Figure 4.

To prevent damage to the DC power supplies, the host (root hub) Hub 1 and all self-powered hubs must have overcurrent protection on Node Node their DC power supplies. If any self-powered hub detects an Node Hub 4 aggregate current drawn by all downstream ports in excess of 5.0 Amps, its overcurrent protector removes power from all downstream ports, and it reports the condition to the host controller [1]. Hub 2 Application Node program USB cable connectors Some USB devices (such as keyboards, mice and hubs) have Node their upstream cable permanently attached to them. Other Node devices (such as , printers and scanners) need to have Endpoints Node Node Hub 3 a detachable upstream cable.

However (As shown in Figure 3) the USB committee wanted Figure 4 to make sure that, when users interconnect USB devices with detachable cables, they didn’t accidentally: Note: The USB system software on the host must verify that the endpoint to which each data transfer is directed corresponds to ■ connect a downstream port of one hub to the downstream some physical device on the bus. In order to do this, it must be port of another hub, since this would create a “loop” in the cognizant of the physical hierarchy of the bus, and it must update USB hierarchy its logical-to-physical device mapping as devices (or hubs) are ■ connect the upstream port of one device to the upstream port added to (or removed from) the bus. of another device, since this could leave the 2 devices “orphaned” from the hierarchy Communication flow over the USB All USB data transactions are host-initiated. USB devices can To guard against this, the USB committee specified that the two never initiate transfers. They only respond to the host’s ends of a detachable USB cable have two different connector commands. [5] Whenever an application program on the host types: requests a data transfer, the host system software initiates the data transfer, regardless of whether data will be transferred from ■ The upstream end of the cable is to be equipped with a “Type the host to the device, or from the device to the host. A” connector, which plugs into the downstream socket on a USB hub. As shown in Figure 5, communication between the host and a ■ The downstream end of the cable is to be equipped with a USB device is handled by 3 layers of software. The application “Type B” connector, which plugs into the upstream socket program on the host system communicates with the USB of a USB device. devices through the logical interface provided by these 3 layers.

Hub A All communication between the application program and the USB bus is accomplished by passing memory buffers through the host’s:

■ Client Software layer ■ USB System Software layer Hub B Node Node ■ USB Bus Interface Host Controller layer

Hub C Hub D Node Node

Loop Node Node Node Orphans

Figure 3 Figure 2

Reprinted from VMEbus Systems / June 1998 / 3 Copyright 1998 ~ All rights reserved Universal Serial Bus (USB)

The Client Software layer host. (These are called interrupt endpoints) The polling interval The host’s Client Software layer (shown in Figure 5) determines for each of these endpoints is specified by its endpoint what type of data transfer is needed to accomplish the operation descriptor. This endpoint descriptor is stored in EEPROM within that has been requested by the application program. It then the peripheral device where that endpoint resides. The USB passes to the system software layer: system software reads this polling interval during the “device enumeration” process at startup. ■ a memory buffer, called a client buffer ■ an I/O Request Packet which specifies what type of I/O The USB system software operation is required Although Figure 5 does not show the internals of the USB system software, it consists of an upper and a lower portion: The USB system software layer The host’s USB System Software layer (shown in Figure 5) ■ the upper portion is the USB driver manages the USB resources [3]. This involves: ■ the lower portion is the host controller driver

■ the allotment of USB bandwidth The USB driver ■ the assignment of a logical device address to each physical During the USB configuration phase the USB driver allows the USB device host’s Client Software layer to access the USB devices. During ■ the scheduling of interrupt transaction service normal operation it allows the application software to access the USB devices. Allotment of USB bandwidth USB transfers can be classified into 3 categories, [2] with regard As the Client Software layer passes Instruction Request Packets to their bandwidth needs: to the USB System Software layer, the USB driver translates each of these packets into one or more USB transactions, and ■ Isochronous and interrupt transfers, which require a guaran- then passes the resulting list of transactions to the host controller teed minimum bandwidth driver. ■ Bulk transfers, which do not require any minimum guaran- teed bandwidth The host controller driver ■ Control transfers, which are guaranteed 10% of the bus band- The host controller driver takes the list of transactions passed width to it by the USB driver and:

Before establishing pipes for Isochronous and interrupt ■ schedules those transactions by adding them to its transac- transfers from the host to a particular device’s endpoint, the tion list USB system software must first determine whether or not the ■ takes individual transactions out of the transaction list (one USB can provide the minimum required bandwidth to that by one) and passes them to the USB Bus Interface Host endpoint. Controller layer ■ monitors the status of each transaction to its completion Each device has an EEPROM that holds an endpoint descriptor for each of it endpoints. This endpoint descriptor records the When all of the transactions derived from an Instruction Request minimum bus bandwidth needed to support its endpoint. The Packet have completed, the USB System Software layer notifies USB system software collects this bandwidth information from the Client Software layer of that fact. all the endpoint descriptors during the device enumeration process during startup. The USB Bus Interface Host Controller layer The USB Bus Interface Host Controller layer (shown in Figure The bandwidth recorded in the endpoint descriptor indicates 5) accepts individual transactions from the host controller driver how much bandwidth is needed to carry data to (and from) that (in the USB System Software layer) and converts each endpoint. However, it does not take into account any overhead transaction into the corresponding bus activity. As a result, USB time. In order to calculate the total bandwidth required to packets are passed through the USB’s physical hierarchy of hubs support the pipe to each endpoint, the USB software factors in (shown in Figure 5 as a single USB cable) to the USB peripheral the overhead [2] based on: shown at the right side of Figure 5.

■ the number of data bytes USB Bus Interface layer ■ the transfer type The bottom layer of the USB peripheral (shown in Figure 5) is ■ the host recovery time called the USB Bus Interface layer. It interacts with the USB ■ the bit stuff time Bus Interface layer on the host to transfer the data packets from ■ the topology depth the host to the peripheral, using the packet formats specified by the USB specification. It then passes the packets upward to the Scheduling interrupt transaction service USB Logical Device layer. The USB software must determine how frequently to poll each USB endpoint. The term interrupt data transfer (which is one USB Logical Device layer of the “official” transfer type names from the USB Committee) The middle layer of the USB peripheral (shown in Figure 5) is is a bit of a misnomer. USB doesn’t provide any support for called the USB Logical Device layer. Each USB logical device interrupts in the normal sense of that word. is represented as a set of endpoints, with which the host’s USB System Software layer can communicate. Full-speed devices Only the host can initiate a USB transaction. It periodically may have up to 16 input endpoints and 16 output endpoints. polls each of the endpoints that might need service from the Low-speed devices are limited to 3 endpoints.

4 / Reprinted from VMEbus Systems / June 1998 Copyright 1998 ~ All rights reserved USB data transfer types

As shown in the table below, the USB specification defines 4 whether the data flow is from the host to the device, or from different transfer types for endpoints: the device to the host. The host stores all pending data transfer requests in 4 lists, by type: ■ Control transfers, which are guaranteed 10% of the bus bandwidth ■ Isochronous transfers ■ Isochronous transfers, which are used for host-to-device (or ■ Interrupt transfers device-to-host) data transfers that require a guaranteed ■ Control transfers minimum bandwidth ■ Bulk transfers ■ Interrupt transfers, which are used for device-to-host data transfers that require a guaranteed minimum bandwidth These lists are constantly being updated with new high priority ■ Bulk transfers, which are used for host-to-device and de- and low priority transfer requests. vice-to-host data transfers that don’t require any minimum guaranteed bandwidth The host examines these constantly-changing lists at 1-msec time intervals, in order to schedule the execution of their Control transfers pending requests. At the beginning of each 1-msec interval, the Control transfers are used: host transmits a Start of Frame (SOF) packet over the USB. It then begins servicing the requests in the Isochronous transfer ■ to configure USB devices when the system is powered up [2] list, which is given the highest priority. ■ to send commands to USB devices during normal operation ■ to obtain status information about USB devices during nor- Once the host exhausts the list of Isochronous transfer mal operation requests, it begins initiating Interrupt transfers. When it exhausts the list of Interrupt transfers, it begins initiating Bulk Isochronous transfers transfers. Isochronous (pronounced eye-SOCK-ruh-nuss) transfers are used in real-time applications because they are given the If 90% of the 1-msec scheduling interval has expired, and the highest priority, and thus have a more predictable delivery time host has not yet exhausted the Isochronous list, the Interrupt between the host and the USB devices. list, and the Bulk transfer list, it stops initiating those, and starts initiating any pending Control transfer requests. Interrupt transfers Interrupt transfers allow the host to check input devices (such This ensures that the Control transfers are always guaranteed as keyboards) for new data. However, the term “interrupt at least 10% of the USB bandwidth. If all of the Control transfer” is a misnomer, since the USB does not support packets are sent before this last 10% of the scheduling interval hardware interrupts. expires, the host will use the rest of the time to do Bulk transfers. These Bulk transfers continue to the end of the Only the host can initiate USB transactions [3] so a USB 1-msec scheduling interval. keyboard must be periodically polled, to see if it has any new data ready to be transferred to the host. A polling interval is In summary: specified for each endpoint by its interrupt descriptor. This descriptor is stored in an EEPROM on the device in which the ■ Isochronous transfers are guaranteed 90% of the bus band- endpoint resides. width ■ Interrupt transfers are guaranteed whatever portion of that Bulk transfers 90% is left over, after all of the pending Isochronous trans- Bulk transfers are used to transfer large blocks of data when fers have been completed there is no urgent deadline for the transfer. Bulk transfers can ■ Bulk transfers are then given whatever portion of the 90% be deferred during heavy traffic periods, until more bandwidth is left over after all of the pending Interrupt transfers have is available. For example, a bulk transfer might be used to send been completed. a print job to a USB printer. ■ Control transfers are guaranteed 10% of the bus bandwidth ■ Bulk transfers are then given whatever portion of that 10% How USB transfers are prioritized is left over after all of the pending Control transfers have All USB data transfers are initiated by the host, regardless of been completed.

Transfer Type Direction Timing Reliability Control Bi-directional No guarantee Delivery guaranteed Isochronous* Unidirectional Every 1 msec No guarantee - No flow control Interrupt Input only Polled rate Delivery guaranteed Bulk* Bi-directional No guarantee Delivery guaranteed * = Full Speed Devices only

Reprinted from VMEbus Systems / June 1998 / 5 Copyright 1998 ~ All rights reserved Universal Serial Bus (USB)

These endpoints are the sources and the destinations of all peripherals that will undoubtedly be offered to the desktop communication flow between the host and the USB peripherals. market. Each endpoint has a set of data transfer characteristics. [3] For example, only one direction and one data transfer type are Conclusion allowed for each endpoint. (See the Sidebar entitled USB data Unlike earlier peripheral interfaces that… transfer types for a description of the 4 types of data transfers defined by the USB specification.) ■ required a special controller board, ■ could not be reconfigured while the system was running The Function layer ■ required a separate cable for each type of peripheral The top layer of the USB peripheral (shown in Figure 5) is called the Function layer. It is the counterpart to the host’s Client …the Universal Serial Bus provides a low-cost, easy-to-use, Software layer. standardized peripheral interface that minimizes the number of cables needed to interface to external peripherals. It supports From the Client Software layer’s point of view, the layers below both low-speed, low-cost peripherals (such as switches, mice it provide a bundle of point-to-point “data pipes” between it and and joysticks) and high speed, high-performance peripherals the endpoints, which are routed to the peripheral’s Function (such as video, disk and LAN interfaces). It’s automatic layer. configuration eliminates the need for DIP switches or jumpers, and its carefully-engineered design provides the reliability From the Function layer’s point of view: needed in today’s VMEbus systems. Ω

■ it receives data sent by the host’s Client Software layer from References the endpoints of the data pipes in the USB Logical Device [1] Universal Serial Bus Specification, Revision 1.0, January 15, layer below it. 1996. (Note: The USB Specification can be downloaded free of ■ it sends data to the host’s Client Software layer by routing charge from http://www.teleport.com/~usb/docs.htm) that data into the endpoints of the data pipes in the USB Logical Device layer below it. [2] Universal Serial Bus System Architecture, Don Anderson, MindShare, Inc. Addison Wesley Developers Press 1997. These data pipes are established during USB device con- figuration, in a process called device enumeration. Each pipe [3] Understanding Universal Serial Bus Part 1: USB Basics, establishes an association between an endpoint on the peripheral Embedded Systems Programming, pp. 34-58, John Canosa, side and an endpoint descriptor on the host side. Once that June 1997. association is established, these logical pipes can be used at any time to move data between the host software’s memory buffers [4] USB: a neat package with a few loose ends; EDN, pp. 38- and peripheral’s data sinks or data sources. 52. Richard Quinnell, October 1996.

USB market growth [5] Taming the Universal Serial Bus, EDN, pp. 61-76. Richard The potential market growth for the Universal Serial Bus is quite Quinnell, June 1997. impressive. The bar graph in Figure 6 shows the number of USB-based desktop computers that Intel predicts will be sold [6] Intel Universal Serial Bus Components http://www. through the end of this decade. [7] intel.com/design/usb/howworks.htm

By equipping boards and systems with USB ports, embedded [7] The Easy Way to , Intel Corporation, hardware suppliers can make use of the large number of Marketing Literature, 1997. Universal Serial Bus: A Solution for the Computer Designs of Today and Tomorrow.

[8] I2C Faq Version 2.0 http://kar10.kar.elf.stuba.sk/ ~balogh/MM/i2c/i2cindex.htm

Barbara Hanlon is a staff software engineer/scientist at Motorola in the company’s Consumer Broadcast Division in Chandler, Arizona. She is currently working on firmware and software for digital set top box reference platforms. Prior to her current position, Barbara worked for the Motorola Computer Group, creating firmware for CompactPCI, VMEbus and motherboard PowerPC products. Barbara is a member of the Motorola technical ladder. She received her Bachelor’s degree in computer science from the University of Wyoming in 1987, and a Master’s degree in management from the Figure 6 University of Phoenix in 1993.

6 / Reprinted from VMEbus Systems / June 1998 Copyright 1998 ~ All rights reserved and answers, some advice on implementing the USB specifica- If you have any questions about this article, you can contact tion, and a list of suppliers and contacts to get you started. It is Barbara at [email protected] published by Annabooks, and has an ISBN number of 092939246-9. To order the book, you can contact the publisher at: Looking for news about USB? Try accessing www.usbnews.com Annabooks 11838 Bernardo Plaza Court Looking for a good book about USB? Suite 102A John Koon has written an excellent 342-page book entitled USB San Diego, CA 92128 Peripheral Design, which is a reference source for software and Tel: 619-673-0870 • Fax: 619-673-1432 hardware engineers and system integrators. It provides an over- Website: www.annabooks.com view of USB technology, a list of frequently-asked questions

ENTER 7 Reprinted from VMEbus Systems / June 1998 / 7 Copyright 1998 ~ All rights reserved