Wishing you all a Happy and Prosperous New Year 2009


Nov 6, 2008

USB Basics - Part I (What actullay is USB?)

This article is part of a series of articles that explain USB from the standpoint of a software/firmware developer. USB has become a defacto standard in the PC world. And it is replacing the older buses like RS-232, ISA and Parallel ports at faster pace.

Apart from this USB is becoming more available, like USB On The Go(USB-OTG) and Wireless USB. Which means that both embedded system developers as well as PC application developers need to understand on how to use this new bus architecture in their development activities.

As per the USB Specification 2.0 the motivation for developing USB came from three interrelated considerations. They are connecting PC to telephone, Ease-of-use and Port expansion. USB met all these 3 considerations and it not only able to connect the PC to telephone, but it also allowed lot of new devices to be created and lot of existing applications to be migrated to it architecture.

The primary advantage of USB is the ease-of-use. This is accomplised by incorporating plug & play and hot plugging mechanisms into the architecture. These features have lead to the conversion of many existing applications which use the legacy parallel ports and serial ports to USB.

The USB Specification came in two revisons. The first release is called USB 1.1 and the second release is called USB 2.0. These specifications can be downloaded from www.usb.org. www.usb.org is the implementars forum of USB and it responsible for maintaining the USB specification. This web site also maintains links to various developer resources, a frequently ask questions section etc.

The USB 2.0 specification is released in year 2000 and subsequently some errata documents are added. USB 1.1 has support for two different speeds of operation namely Low-Speed USB and Full-Speed USB. The USB 2.0 specification added another speed to the specification which is called as High-Speed USB. What this means to a developer is that, when a USB device is developed, it can operate at 3 different data transfer rates depending the device requirement. For exmample, if the USB device developed is lets say a Mouse device. The Mouse normally does not transfer large quantities of data, also in a second it may just transmit few bytes of data. Then it can work in Low-Speed USB. If there another device like let's say a data acquisition system which need to transmit data at higher rate as compared to Mouse, then it can use the Full-Speed USB operation which can do approximately 1 MB/s. If the device is something like disk drive,then the device may use High-Speed USB which can do approximate 480 Mb/s.

So, if we take an anology with RS-232, like how RS-232 supports various baud rates, USB also supports 3 speeds of operation.

Apart from USB has another feature also, which different from how RS-232 works. It supports 4 types of transfers, namely Control Transfer, Interrupt Transfer, Bulk Transfer and Isochronous Transfers. Depending on the application's requirement the USB device developer need to choose the required transfer types.

In USB each transfer type is mechanism which dectates how and what kind of the data is packed and transmitted over the USB bus.

Control Transfer: It is primarily used during intiling the device or configuring the device. USB devices support plug & play mechanism, which is nothing but auto detection and auto configuration. The USB device transmits certain information about itself as per the specificaiton to the PC to which this device is connected through the mechanism called control transfer.

Interrupt Transfer: This mechanism is used for tranmitting the actual data over the bus. The speciality of this transfer type is, the integraty of data is varified and maintained. Also, the data is transmitted in real time with accuracy. In this transfer type the amount of data that can be transmitted per second is limited. Again tipical applications are those which require integraty and timeliness. Mouse device is a good example which use this transfer.

Bulk Transfer: This mechanism is again used for transmitting the actual data. In this case the timeliness of data is not maintained, but integraty is maintained. So, applications like printers which requires correct data but which can neglect small delays in data arraival can use this transfer. As the name indicates this transfer type can transfer large quantities of data depending the speed of operation.

Isochronous Transfer: This mechanism is again used for transmitting the actual data. In this case timeliness is maintained during data transfer. But, integraty will not checked. So, applications like streaming audio devices, video cameras etc.. can use this tranfer type for real time transfer of the data.


The following table shows how each transfer type is supported in each speed of operation.


Speed of Operation
Transfer Type Low Speed Full Speed High Speed
Control Transfer Supported @ 24 KB/sec Supported @ 832 KB/sec Supported @ 15,872 KB/sec
Interrupr Transfer Supported @ 800 bytes/sec Supported @ 64 KB/sec Supported @ 24,576 KB/sec
Bulk Transfer Not Supported Supported @ 1,216 KB/sec Supported @ 53,248 KB/sec
Isochronous Transfer Not Supported Supported @ 1,023 KB/sec Supported @ 24,576 KB/sec



The above table shows what are the real speeds a device can achieve with a specific speed configuration and with a specific transfer type. But the one thing to be noticed is the specification mentions a much higher speed value for for each speed of operation. And it may look like a discripency. But one important aspect of USB bus is Port expansion. This means that the same bus is used by multiple devices. In USB terminology these devices are called as Peripherals. So, when the specification mentions a speed for a particular speed of operation, it is mentioning the maxmum amount of data that can be transmitted in a specified time by all the device on the bus which are using a specific speed of operation. Again, as we saw the atual speed depends on transfer type also.

The USB bus architecture diagram will look something like this.














In the diagram you might have observed 4 important components.

1. Host: The host is the PC or the device which has the maximum processing power with features to control peripheral buses like USB.

2. Host Controller & Root Hub: The Host controller is the device responsible for controlling the USB bus. And the Root Hub is a HUB device which will/can extend the bus. If you see 2 USB ports on a computer the there is a possibility that only one Root Hub is there. If you see more than 4 USB ports on a computer then there is a possibility that it has 2 Root Hubs and Two Host controllers connected to the Host System.

3. Hub: A device that will extend the bus and provide channels(USB Ports) to which more number of devices can be connected.

4. Peripherals: The actual USB device which will use various transfer types and speed of operation.


The USB protocol is a host controlled protocol. We will see what this means in the up coming articles.


So, this article introduced you to USB, what types of speeds available and how the architecture looks like.




No comments: