Universal Serial Bus (USB) is the de facto interface for computer peripherals to communicate with the personal computers. The interface that saw the light of day around the mid-1990s was a joint effort of seven companies – Compaq, DEC, IBM, Intel, Microsoft, Nortel, and NEC. These companies were aiming to replace the then parallel ports and the external power chargers with a universal communication standard that could simplify data exchange and could double duty to supply power as well.
Nowadays, USB is the standard and must-have interface on almost all motherboards, single board computers and the embedded microcontroller boards and almost every digital peripheral from regular computer peripherals like keyboard, mouse and joysticks to smart digital devices like cameras, flash drives, smartphones and tablets, all comes equipped with the USB port(s). Till now, USB 3.1 (launched in July 2013) has been released and the standard is now maintained and developed by USB Implementers Forum.
Any USB interface connects two devices where one device is connected as Host and the other device connects as peripheral. For example, when a USB flash drive (Pen drive) is inserted into USB port of a personal computer, the flash drive is the peripheral and a personal computer is the host device. By the “Host”, here means that the data communication is managed by the host device with the help of relevant driver software. Many peripherals can be connected to a single host device. Even a single USB port can be extended to multiple USB ports using an extension hub.
The initial versions of USB (pre-release versions and USB 1.0) were developed for slower devices. But by the year 2000, demand for high-speed communication had surged up and USB 2.0 was released to meet out the expectations. The current version USB 3.0 supports four different data transfer modes:
|Low Speed||1.5Mbit/s||Keyboard, Mouse, Game Peripherals|
|Full Speed||12Mbit/s||Scanner, Printer, Digital audio|
|High Speed||480Mbit/s||Broadband, Mass storage, Imaging|
|Super Speed||5Gbit/s||Real Time Streaming, Portable SDtorage Devices|
The new version releases of USB obviously have greater data transfer speeds for different file formats:
|Data Size||Time Taken|
|USB 1.0||USB 2.0||USB 3.0|
|Image/MP3 (4MB)||5.3 Sec||0.1 Sec||0.01 Sec|
|Flash Drive (1 GB)||22 Min||33 Sec||3.3 Sec|
|HD-Movie (16 GB)||9.3 Hr||13.9 Min||70 Sec|
Advantages of USB:
• Single Interface for multiple devices: The versatile nature of USB removes the complexity of different connector type and hardware requirements for each peripheral
• Auto-configuration: The operating system of the host device only needs to install the USB device driver for once. Later whenever the peripheral device is plugged in, the driver is automatically loaded to configure the plugged in device. Usually, the device driver specific to any USB peripheral is automatically installed the first time device is connected with the host.
• Easy to expand: Generally personal computers (Motherboards) have 3 or 4 USB ports. In case if more USB ports are required, USB hubs can be used to add external ports.
• Speed: USB provides various speed modes which make it more efficient and swift compared to RS232 and parallel ports. It offers speed ranges from 1.5Mbit/s to 5Gbit/s. With the introduction of USB 3.1 in 2013, the speed has been increased to 10Gbit/s. It is also referred as Super Speed+.
• Reliability: The USB protocol can catch errors during data transfer and notify the transmitter to retransmit the data. The generic USB driver and specific driver software ensure an error-free data communication.
• Low cost: With its versatile nature and high demand, it has become inexpensive to manufacture USB supported devices as the manufacturing can be easily scaled. So the components, connector, and cable are also easily available at low cost.
• Low power consumption: The USB devices generally works on +5V and consumes current in Milliampere. During Suspend mode, the peripheral consumes 500 microamperes or less for USB 2.0 and 2.5 milliampere or less for USB 3.0.
Besides so many advantages there are some limitations which make USB ineffective for some task.
• Speed: With the introduction of USB 3.0, it is possible to achieve 5Gbits/sec. But it is still lower than Gigabit Ethernet. The FireWire 800(IEEE-1394b) is also a competitor for USB.
• Peer to Peer Communication: As per the USB standard, the communication takes place between the host and the peripheral. Two hosts cannot communicate directly to each other. Same is the case for a peripheral. On the other hand, interfaces like FireWire supports peripheral to peripheral communication. For overcoming this limitation, the USB introduced the concept of OTG (On The Go). The OTG device normally functions as peripheral, but it can also function as host with some limited capability when required.
• Distance: According to USB standards, the connecting cable can be as long as 5 meters, beyond which, USB hubs need to be used for expanding the connectivity.
• Broadcasting: Universal Serial Bus does not provide the broadcasting feature, only individual messages can be communicated between host and peripheral.
USB System Architecture
The USB is controlled by a host; there can be multiple peripherals but only one host per bus. The host can be taken as master and peripheral as slaves, whereby the former is responsible for managing the connection, transactions, and scheduling bandwidth. The USB system uses tiered start topology. It consists of 7-bit addressing; this means it can support up to 127 devices at once.
The connection cable consists of 4 shielded wires out of which two are for power (+5V and Ground) and the remaining are twisted pair differential data signals which use NRZI (Non Return to Zero invert) scheme to transmit data. In order to synchronize the host and receiver clocks, Sync field is used.
In USB, the information flows between host and device. The endpoints are source or sink of information in a communication channel. These are blocks of memory in a controller chip containing buffers for transmission and reception.
The two endpoints can have same endpoint number but different directions. When the device is plugged in, only the default endpoint 0 is accessible. This endpoint receives control and status request from the host during enumeration process. The other endpoints are declared as per requirement after configuration of the device.
A pipe is a logical data connection between host controller’s software and device endpoint. The information is exchanged through this pipe. It is created during enumeration process. When the device is unplugged, unneeded pipes are removed.
There are two types of pipes:
• Message pipes: These are bi-directional pipes which follow defined packet format. They are controlled by host and only support control transfer.
• Stream pipes: These are unidirectional pipes which don’t follow any specific data format. They can be controlled by host or device (peripheral) and support bulk, isochronous and interrupt types of transfer.
The Default Control pipe is a special type of message pipe which is bidirectional and supports control transfer type. It uses endpoint 0-IN and endpoint 0-OUT. This pipe can be accessed when a device is plugged in.
There are four types of transfer modes or types which can be used for communication:
• Control Transfer: This transfer type is used to transfer the control information while identifying and configuring the device.
• Bulk Transfer: In this transfer type, large amount of data is moved and time is not a critical factor here. It can be used as fillers.
• Interrupt Transfer: This type of transfer is for small data transmission with immediate attention.
A single transaction contains transmission of up to three packets. These packets are:
• Token Packet: This packet is always sent by Host
• Data Packet: This packet can be sent by Host or Device.
Handshaking is a mechanism to check the success/failure of a request or to check the delivery of a packet. It is done to avoid loss of packets and to ensure successful transmission. Terms related to handshaking:
• ACK – acknowledgment for data receive (success)
• NAK – negative acknowledgment means no data
• STALL – request not supported or endpoint halted
• NYET – not yet. A case can be when device is busy and not ready for next data packet
• ERR – split transaction error
USB Device States
A USB device can have several possible states as described below:
• Attached State: This state occurs when the device is attached to the Host.
• Powered State: After the device is attached, the Host provides power to the device if it does not have its own power supply. The device should not draw more than 100 mA in this state.
• Default State: This state occurs when the device is reset and has not been assigned a unique address. In this state the device uses default control pipe for communication and default address 0.
• Addressed State: The USB device enters this state after it gets a unique address which is used for future communications.
• Configured: When the Host obtains required information from the device, it loads the appropriate driver for the device. The host configures the device by selecting a configuration. The device is now ready to do the operations it was meant for.
• Suspended State: The USB device enters the suspended state when the bus remains idle for more than 3mS. In this state, the device must not draw more than 500uA of current.
Enumerating is making peripheral device recognizable at host end. For making enumeration successful some steps have to be followed -:
• Writing firmware code for the controller chip: This firmware will be responsible for sending device description, decoding the packets and responding to the host.
• A device driver needs to be installed on the host: For windows, an INF is needed which contains the information about the device. Sometimes USB device itself contains drivers for the host.
After successful enumeration, the device will be known to the host and an application will be needed to make use of the USB communication. The application uses Operating System’s API (for e.g. Windows API). The application can transmit or receive data by using Buffers.
Every USB device has a device class defining the functionality and purpose of that device. The host loads the suitable driver according to the device class. The most common device classes are:
• Human Interface Device (HID): This class is generally used by devices which use Interrupt Transfer for data communication. Examples are keyboard, mouse or joystick.
• Mass Storage: Devices which need to transfer a large amount of data through Bulk Transfer implements this class. Examples are USB flash drive, memory card reader or external hard disk.
• Audio: This class is implemented by audio devices like microphone, speaker, external sound card etc. The device uses Isochronous Transfer for data communication.
• USB Hub: It is used by USB hubs to expand the number of ports.
• Image: Used by a device like a webcam or a scanner.
• Printer: Used by Laser printer, inkjet printer or CNC machines
• Wireless: Used by the external adapter for wireless communication. Example – Bluetooth, 802.11
The next article covers the protocol of USB defining the various types of packet fields. Stay tuned for the upcoming details of USB in the series.