Introdução ao USB: Vantagens, Desvantagens e Arquitetura (Parte 1/6)

Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Universal Serial Bus (USB) is the de facto interface for computer peripherals to communicate with personal computers. The interface that saw the light of day in the mid-1990s was a joint effort of seven companies – Compaq, DEC, IBM, Intel, Microsoft, Nortel and NEC. These companies intended to replace the then-parallel ports and external power chargers with a universal communication standard that could simplify data exchange and also duplicate the task of power supply.

Nowadays, USB is the standard and mandatory interface on almost all motherboards, single-board computers and embedded microcontroller boards, and almost all digital peripherals, from common computer peripherals such as keyboard, mouse and joysticks, to devices smart digital devices, such as cameras, pen drives, smartphones. and tablets all come equipped with USB port(s). So far, USB 3.1 (released July 2013) has been released and the standard is now maintained and developed by the USB Implementers Forum.

Any USB interface connects two devices where one device is connected as a Host and the other device as a peripheral. For example, when a USB flash drive is inserted into a personal computer's USB port, the flash drive is the peripheral and a personal computer is the host device. By “Host” here it means that 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.

Early versions of USB (pre-release versions and USB 1.0) were developed for slower devices. But in the year 2000, the demand for high-speed communications increased and USB 2.0 was released to meet expectations. The current version of USB 3.0 supports four different data transfer modes:

Modes Performance Application
Low speed 1.5Mbit/s Keyboard, mouse, gaming peripherals
Maximum 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 releases of new versions of USB obviously feature faster data transfer speeds for different file formats:

Data size Time spent
USB 1.0 USB 2.0 USB 3.0
Image/MP3 (4 MB) 5.3 seconds 0.1 sec. 0.01 sec.
Flash drive (1GB) 22 minutes 33 seconds 3.3 seconds
HD Movie (16GB) 9.3 hours 13.9 minutes 70 seconds

Advantages of USB:

• Easy to use : USB was, for obvious reasons, designed to be a simplified interface. The simplicity of the interface lies in the following aspects:

• Single interface for multiple devices: The versatile nature of USB eliminates the complexity of different connector types and hardware requirements for each peripheral

• Automatic configuration: The host device operating system only needs to install the USB device driver once. Thereafter, whenever the peripheral device is connected, the driver will be automatically loaded to configure the connected device. Typically, the specific device driver for any USB peripheral is automatically installed the first time the device is connected to the host.

• Easy to expand: Generally personal computers (motherboards) have 3 or 4 USB ports. If more USB ports are needed, USB hubs can be used to add external ports.

• Compact size: USB sockets have small dimensions compared to RS232 or parallel ports. • No external power required: The USB interface was designed from day one to function as a DC power source. Any host device through its USB port can supply 5 VDC, providing 500 mA (USB 1.0 and 2.0) to 900 mA (USB 3.0) to the peripheral.

• Speed: USB offers multiple speed modes that make it more efficient and faster compared to RS232 and parallel ports. It offers speed ranges from 1.5 Mbit/s to 5 Gbit/s. With the introduction of USB 3.1 in 2013, the speed was increased to 10 Gbit/s. It is also known as Super Speed+.

• Reliability: The USB protocol can detect errors during data transfer and notify the transmitter to retransmit the data. Generic USB driver and specific driver software ensure error-free data communication.

• Low cost: With its versatile nature and high demand, it has become inexpensive to manufacture devices with USB support as manufacturing can be easily scaled. Therefore, the components, connector and cable are also easily available at low cost.

• Low power consumption: USB devices generally operate at +5V and draw current in milliamps. During Sleep Mode the peripheral consumes 500 microamps or less for USB 2.0 and 2.5 milliamps or less for USB 3.0 .

In addition to so many advantages, there are some limitations that make USB ineffective for some tasks.

Limitations:

• Speed: With the introduction of USB 3.0, it is possible to reach 5 Gbits/sec. But it is still inferior to Gigabit Ethernet. FireWire 800 (IEEE-1394b) is also a competitor to USB.

• Point-to-point communication: According to the USB standard, communication occurs between the host and the peripheral. Two hosts cannot communicate directly with each other. The same happens with a peripheral. On the other hand, interfaces like FireWire support peripheral-to-peripheral communication. To overcome this limitation, USB introduced the concept of OTG (On The Go). The OTG device typically functions as a peripheral, but can also function as a host with some limited capacity when necessary.

• Distance: According to USB standards, the connection cable can be up to 5 meters long, beyond which it is necessary to use USB hubs to expand connectivity.

• Transmission: Universal Serial Bus does not provide transmission capability, only individual messages can be communicated between the host and the peripheral.

USB system architecture

USB is controlled by a host; there can be multiple peripherals, but only one host per bus. The host can be considered master and peripheral as slave, with the former being responsible for managing the connection, transactions and bandwidth scheduling. The USB system uses layered start topology. It consists of 7-bit addressing; This means it can support up to 127 devices at the same time.

The connecting cable consists of 4 shielded wires, of which two are for power (+5V and ground) and the remaining are twisted pair differential data signals that use the NRZI (Non Return to Zero invert) scheme to transmit data. To synchronize the host and receiver clocks, the Sync field is used.

Endpoints

In USB, information flows between the host and the device. Endpoints are sources or sinks of information in a communication channel. These are memory blocks on a controller chip containing buffers for transmission and reception.

The two endpoints can have the same endpoint number but different directions. When the device is connected, only the default endpoint 0 is accessible. This endpoint receives control request and status from the host during the enumeration process. The other endpoints are declared as per the requirement after device configuration.

Imagem mostrando terminais USB

Fig. 1: Image showing USB terminals

Tubes

A pipe is a logical data connection between the host controller software and the device endpoint. Information is exchanged through this channel. It is created during the enumeration process. When the device is disconnected, unnecessary tubes are removed.

There are two types of tubes:

• Message channels: These are bidirectional pipes that follow a defined packet format. They are controlled by the host and only support transfer of control.

• Flow pipes: These are unidirectional pipes that do not follow any specific data format. They can be controlled by host or device (peripheral) and support bulk, isochronous, and interrupt transfers.

The Standard Control Pipe is a special type of message channel that is bidirectional and supports the control transfer type. It uses the 0-IN terminal and the 0-OUT terminal. This tube can be accessed when a device is connected.

Imagem mostrando canais lógicos USB

Fig. 2: Image showing USB logic tubes

Types of transfer

There are four types of modes or transfer types that can be used for communication:

• Control transfer: This type of transfer is used to transfer control information during device identification and configuration.

• Bulk transfer: In this type of transfer, a large amount of data is moved and time is not a critical factor here. Can be used as a filler.

• Stop transfer: This type of transfer is intended for transmitting small data with immediate attention.

• Isochronous Transfer: It is a transfer in which time is a critical factor. The transfer must be completed by a certain time.

Imagem mostrando tipos de transferência USB

Fig. 3: Image showing USB transfer types

Transaction

A single transaction contains the transmission of up to three packets. These packages are:

• Token Package: This package is always sent by the Host

• Data packet: This packet can be sent by Host or Device.

• Handshake packet: This packet provides success/failure information for the received data packet. If the Host transmits the data packet, the device sends the handshake packet and vice versa.

Handshake

Handshaking is a mechanism for verifying the success/failure of a request or for verifying the delivery of a package. This is done to prevent packet loss and ensure successful transmission. Terms related to handshake:

• ACKNOWLEDGMENT – confirmation of data receipt (success)

• NO – negative recognition means there is no data

• STOP – request not supported or endpoint stopped

• NYET – not yet. A case may occur when the device is busy and not ready for the next data packet

• ERROR – split transaction error

• No reply

Imagem mostrando transações USB e handshake

Fig. 4: Image showing USB transactions and handshake

USB device states

A USB device can have several possible states, as described below:

• Attached State: This state occurs when the device is connected to the Host.

• Powered state: After the device is connected, the Host supplies power to the device if it does not have its own power supply. The device must not consume more than 100 mA in this state.

• Default state: This state occurs when the device is rebooted and has not been assigned a unique address. In this state, the device uses the default control channel for communication and the default address 0.

• Addressed state: The USB device enters this state after obtaining a unique address that is used for future communications.

• Configured: When the Host obtains the necessary 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 perform the operations for which it was designed.

• 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 consume more than 500uA of current.

Enumeration

Enumeration is to make the peripheral device recognizable on the host. To make enumeration successful, some steps must be followed -:

• Writing firmware code for the controller chip: This firmware will be responsible for sending the 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 required which contains the information about the device. Sometimes the USB device itself contains drivers for the host.

After successful enumeration, the device will be known to the host and an application will be required to make use of USB communication. The application uses operating system API (e.g. Windows API). The application can transmit or receive data using Buffers.

Device Class

Each USB device has a device class that defines the functionality and purpose of that device. The host loads the appropriate driver according to the device class. The most common device classes are:

• Human Interface Device (HID): This class is generally used by devices that use Interrupt Transfer for data communication. Examples are keyboard, mouse or joystick.

• Mass Storage: Devices that need to transfer a large amount of data through mass transfer implement this class. Examples are USB flash drive, memory card reader, or external hard drive.

• Audio: This class is implemented by audio devices such as 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 such as a webcam or scanner.

• Printer: Used by laser printer, inkjet printer or CNC machines

• Wireless: Used by the external adapter for wireless communication. Example – Bluetooth, 802.11

Tabela listando classes comuns de dispositivos USB

Fig. 5: Table listing common USB device classes

The next article covers the USB protocol that defines the various types of packet fields. Stay tuned for upcoming series USB details.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.