USB fundamentals 101

Universal Serial Bus (USB) communications has greatly advanced the versatility of PCs and embedded systems with external peripherals. USB provides the next-generation interface for all devices that at one time communicated through the serial port, parallel port, or utilized a custom connector interface to the host computer system. This column introduces the basic architecture of the USB bus, provides some advanced information on the internal workings of USB communications and lists sources of information to provide greater detail for further USB study.

USB basics
USB is an asynchronous serial interconnect between a host and up to a total of 127 devices. It utilizes a four wire shielded cable with a length of up to 5m between a host and a device or hub. Two of the wires are power and ground which are sourced by the host or a hub providing limited supply power for attached devices. All USB information is transmitted on the other two wires. These wires are a twisted pair and the USB data is transmitted as a differential signal.

The USB cable itself has a unique keyed interface to ensure proper connection between the host and device. The end of the USB cable that plugs into the host is referred to as Series-A plug and mates with the Series-A receptacle on the host. The end of the USB cable that plugs into the device is referred to as Series-B plug and mates with the Series-B receptacle on the USB device. It was later recognized that the Series-B plug and receptacle may be too large for some USB devices so the Mini-B plug and receptacle was introduced. Figure 1 depicts USB receptacle pinouts.

21
Figure 1: USB receptacle pinouts

USB communications have provided many benefits to the PC and to embedded systems; however, it also has some drawbacks and limitations. Table 1 lists some of the dominant benefits and limitations of USB communications.

21
Table 1

USB 1.0 was released in January 1996. In September 1998, USB 1.1 was released which added an additional method of transferring data between the host and device. USB 1.0 and 1.1 supported two data transfer speeds; a low speed of 1.5 Mbps and a full speed of 12 Mbps.

USB 2.0 was released in April 2000 and added a faster data transfer speed of 480 Mbps while retaining all the characteristics of the original USB 1.1. This introduction of the faster transfer speed allowed devices such as external hard drives, video transport, scanners, and the newer printers that require high data throughput to utilize USB communications.

USB components include a root hub which is also referred to as the host and is the PC or primary embedded system; hubs which are bridges with one input and multiple outputs; and peripherals which can also referred to as devices. Figure 2 shows an example of multiple USB devices connected to a host.

22
Figure 2: An illustration of multiple USB devices connected to a host

Figure 2

USB utilizes a tiered star topology in which each device is connected to hubs which may be connected to other hubs or directly connected to the host which is the PC or primary embedded system. The host controls all communications on a USB bus and only one device at a time communicates with the host. This is referred to as a Äúspeak when spoken to Äù communications protocol.

The USB hubs themselves are also USB devices. They communicate with the host the same as any of the devices attached to the USB link. Hubs that are USB 2.0 compatible contain more intelligence within the hub and provide additional data trafficking in order to provide assistance to the host and move the USB data more efficiently. An example of this is the ability of a USB 2.0 hub to buffer data from attached USB 1.1 devices that are transmitting at low or full speed and retransmit the data to a USB 2.0 host at a high speed. This buffering data is defined as the USB 2.0 hub acting as a transaction translator. This ability of the USB 2.0 hub to be a transaction translator allows any attached USB devices regardless of their data transmission speed to communicate with the host at high speed which frees bandwidth for the host for communications with other devices directly attached to it.

USB 2.0 supports full backward compatibility to USB 1.1. The majority of USB 2.0 devices that communicate at the high data transfer speed of 480 Mbps are also able to communicate at the full data transfer speed of 12 Mbps which is supported by USB 1.1. As shown in Figure 1, if a USB 2.0 device is connected to a USB 1.1 hub the data transfer speed will be limited to 12 Mbps. The same is also true if a USB 2.0 device was directly connected to a USB 1.1 supported host. This flexibility for USB 2.0 devices to support multiple data transmission speeds is what allows USB 2.0 devices to operate with USB 1.1 based hubs or host. This is the basis for providing the backward compatibility of USB 2.0 to USB 1.1.

USB communications
USB supports three different communication speeds for transferring data across the bus; low speed, full speed and high speed. Low speed is 1.5 Mbps, full speed is 12 Mbps and high speed is 480 Mbps. This transmission speed describes the rate that all information is transmitted on the bus. This includes all data, error checking, control information and status information required for USB communications. The actual data rate of information transmitted on the bus for a signal device is about 800 bytes per second for low speed, 1.2 MBps for full speed and 53 MBps for high speed.

Unlike the baud rate setting in RS232 communications, the transmission speed for USB communications is not a constant value. The transmission speed that data is transferred through the bus can be unique for each individual device. If you have a device communicating at low speed such as a mouse, a device communicating at full speed such as a thumb-drive and a device communicating at high speed such as a web camera all connected to a USB 2.0 bus, all three transmission speeds will be present on the bus. Because only one device communicates with the host at a time, the host communicates with each individual device at the transmission speed requested or supported by that particular device.

When a USB device is first connected directly to a host or hub, the host will initially detect the presence of the USB device by a change in the voltage level on its signal lines. The host will then begin to request basic information from the device such as what communication speeds the device supports, the device's abilities, what transfer type the device will be utilizing, the bandwidth the device requires, what is the vendor ID, and product ID of the device along with other control information. This initialization process is referred to as enumeration. During enumeration the host will also assign a unique address to the device, reset the device, establish a communication path to the device and will load the appropriate drivers for the device to communicate with the application software.

Types of USB data
There are four transfer types used to transmit data in USB communications: control, bulk, interrupt, and isochronous. The communication requirements of the individual device will determine the communication type that is required. All USB devices will use one or a combination of the four transfer types for communications to the host as shown in Table 2.

22
Table 2
(Click graphic to zoom by 1.3x)
  • Control transfer: Control transfers are the only type of transfer that all USB devices must support. A device can utilize one of the other transfer types that may be better suited for continued communications with the host but it must support control transfers at a minimum. Control transfers are utilized during the enumeration stage of a USB communication. After enumeration the device can continue to utilize the control transfer type for communications. Control transfer type supports low, full and high transmission speeds and includes error correction.
  • Bulk transfer: Bulk transfers are used for moving large amounts of data between a host and a device. Examples of devices that utilize bulk transfers are printers, scanners, hard drives and flash drives. Bulk transfers occur on the USB bus when no other types of transfers are occurring and transmission of the data is not time critical. Bulk transfer type is only available for devices that support full- and high-speed USB communications; it includes error correction.
  • Interrupt transfer: The interrupt transfer is not the same as the interrupts that are present in an embedded system or PC. Interrupt transfers are utilized by devices that require the host to periodically poll the device to see if any information is required to be transferred. Examples of such devices are the keyboard and mouse that need to transfer small pieces of information when a key is depressed or mouse movement is detected. Interrupt transfers can be utilized by any of the USB bus transmission speeds and includes error correction.
  • Isochronous transfer: Isochronous transfer allows devices to transfer large amounts of data in real time. They guarantee a delivery time or bandwidth for the device data to be transmitted but it does not incorporate any type of error correction as the other transfer types support. Devices that utilize isochronous transfer have to be tolerant of occasional corrupt data packets arriving at the destination. Examples of devices that would utilize isochronous transfer would be a web camera or USB speakers. Isochronous transfer type is only available for devices that support full- or high-speed USB communications.

The multiple data transfer speeds in addition to the different transfer types available for efficiently moving data between the host and device is what allows the USB protocol to be such an incredibly versatile and adaptable communications platform. This is the strength of USB communications Äîwhich allows multiple devices ranging from simple data transfer requirements, such as mice and keyboards, to devices requiring complex and high bandwidth data transmission, such as video Äîto utilize the same USB bus.

Detailed USB information
When a device is initially connected to a USB port the host will begin the enumeration phase. During this phase the host will assign a unique device address to represent the device attached.

Within each device or peripheral are what is referred to as endpoints. Endpoints are a uniquely addressable portion of a USB device that is used for communications between a host and the device and are utilized for the sourcing or receiving of data. There are 16 addressable endpoints numbered 0 to 15 available in a device. The endpoints address contains an address number and a direction number. The endpoint address references one of the 16 endpoint buffers or registers within the device. The endpoint number defines if the data is traveling to or from the host and is referenced from the host point of view.

An IN endpoint describes data that is traveling from the device to the host. An OUT endpoint describes data that is traveling from the host to the device. Endpoint address 1 with a direction defined as IN and endpoint address 1 with a direction defined as OUT are two separate buffers or registers. This applies to endpoint addresses 1 through 15. Therefore a device could have 30 uniquely addressable endpoints. Endpoint 0 is configured as the control endpoint and is defined as both IN and OUT. All devices are required to have endpoint 0 as a control endpoint. Endpoint 0 is utilized during the enumeration process between the host and device.

Each transaction on bus contains a device address and the endpoint address. Full-speed and high-speed devices can utilize the entire 30 additional endpoint address dependent upon their individual function, communication requirements, and data exchange requirements. Low-speed devices are limited to only two additional endpoints in addition to endpoint 0. These two additional endpoints can be configured as a combination of IN or OUT endpoints.

The communication exchange between the host and a device that is initialized or set up during the enumeration process is referred to as a pipe. The pipe is a virtual connection between a device's endpoints and the device's controlling software or drivers that are located in the host. The pipe is a pathway for all data exchanged between the host and device. When a device is physically removed from the bus the virtual pipe is eliminated.

USB software development
USB communications are software and firmware intensive. Writing custom drivers for a PC software program to communicate with the USB interface can be a very difficult task. To simplify the task the USB specification has segmented different types of USB devices into what are called classes. These classes group similar devices together such as human interface devices (keyboards, mice, and joysticks), monitors, mass storage devices along with many other defined classes for different types of devices. The USB specification defines each class with a baseline set of capabilities and requirements. Standardized software drivers have been developed for these different types of classes and are available along with the source code from the Microsoft website and from several Linux websites.

These already developed standardized class drivers allow programmers to utilize an existing class driver that is similar in functional requirements to their particular device as a reference. Many times a class driver may be utilized directly or with minor modifications to meet the requirements of a particular device.

If a custom USB device is being designed such as a data acquisition system, motor interface or an interface for a legacy system, it is likely that a representative class driver may not be available and a custom driver may have to be created. There are several websites that provide reference information for creating a custom device driver including the Windows 98 Drivers Developer's Kit (DDK) which includes example code for USB drivers. There are also several companies that provide wizard based driver development kits that can greatly simplify the creation of a custom USB driver.

USB do's and don'ts

  • It is not practicable or prudent to debug or monitor USB communications through an oscilloscope or logic. The actual data that is transmitted across the bus is very complex. USB communications must be analyzed and debugged using a protocol analyzer that supports USB 2.0 communications.
  • If a system design is utilizing an existing PC/104 module that supports USB communications, it is important to find out exactly what USB chip or Integrated Circuit (IC) is being utilized on the PC/104 module and if that particular USB IC meets the need and requirements of the USB communications for the system design. There are a large number of USB ICs that are manufactured by a multitude of vendors, and the capabilities of each IC can vary greatly.
  • If a vendor is designing a custom PC/104 board that incorporates USB communications it is important to find a USB IC that meets the USB requirements of the overall system design. Some ICs offer very basic USB communications and rely upon an external CPU to handle a majority of the USB protocol. Other ICs include a CPU or microcontroller and associated firmware that provides the necessary error checking, control structure, handshaking and protocol structure required for USB communications. Also, it is also key to find out if the device supports the data transfer speed required by the system design, what firmware examples and source code is available, what hardware design support is available, and if the vendor provides any development boards that feature the USB chip in question. USB development boards are an excellent source of example source code, example communications with that chip and a source for a reference hardware design interface.

Looking forward
The two most recent released variations to the USB protocol have been USB On-The-Go and Wireless USB. USB On-The-Go is a supplement to the USB specification that allows for limited peer to peer communications directly between two USB devices. USB digital cameras are one example of technology that is utilizing USB On-The-Go and have the capability of directly printing pictures to a small USB printer.

Wireless USB defines requirements to allow wireless USB communications based upon the USB protocol. Wireless USB utilizes Ultra-Wideband radio technology and allows for data transfer of up to 480 Mbps within distances of about 3 m and data transfer of up to 110 Mbps within distances of about 10 m. It allows for up to 127 devices to be wirelessly connected, eliminates the need for physical hubs, and provides data encryption to ensure security of the data being transferred between the host and device. The wireless USB specification was released in May 2005 and it is expected that the number of devices that have wireless USB capability will dramatically increase over the next several years.

For more information
USB communications have provided a standard interface to a vast array of PC and embedded system devices. The USB standard itself is continuing to evolve to adapt to new demands and versatility required by the market.

The USB organization's website, www.usb.org, contains the USB specifications, white papers, USB forums and software for USB compliance testing, all for free. This resource is invaluable for any USB hardware development, software development or standard PC/104 board level incorporation into a system design. Some key summary information is shown in Tables 3 and 4.

Additional information, references, and web links about USB communications is available at www.jacyltechnology.com.

Books on USB communications

USB Complete: Everything You Need to Develop Custom USB Peripherals (3 th Edition), by Jan Axelson, Lakeview Research, ISBN: 1931448027

USB Design by Example:  A Practical Guide to Building I/O Devices , (2nd Edition), by John Hyde, Intel Press ISBN: 0970284659

Table 3

Web Link

Description

The primary site for all USB information.  USB specifications can also be downloaded here.

This is the USB forum located at www.usb.org.  This forum is searchable and contains a wealth of information for developing USB software and hardware products.

Contains a list of USB development boards for many of the popular vendor supplies USB chips

Contains a vast array of links to vendors that have USB based or supported chips.

Contains a list of USB development boards for many of the popular vendor supplies USB chips

Provides software development kits for creating custom USB drivers.

Link to the Windows DDK.

Table 4

. . . . .

Additional information, references, and web links about the PC/104-Plus form factor and the PCI bus is also available at www.jacyltechnology.com.

Joel Huebner is president of Jacyl Technology, Inc. He holds two degrees with honors from Purdue University in Electrical Engineering and Computer Engineering. Joel has more than 15 years’ experience as an electrical design engineer in the military aerospace industry and in the custom electronic design R&D industry.

For further information, contact Joel at:

Jacyl Technology, Inc.
P.O. Box 350
Leo, IN 46765
Tel: 800-590-6067
E-mail: jhuebner@jacyl.com
Website: www.jacyltechnology.com