Communication in USB
Fig. 1: Image Showing Communication in USB
While Communication in USB we consider three parts-
a) Host which can be a Computer / PC/ laptops
b) USB cable and connector
USB systems consist of a personal computer (PC) known as host and multiple peripheral devices like mouse, keyboard, and audio system. The host itself contains two components, the host controller and the root hub. A host controller is a hardware component that is contained in a host computer. The Host controller converts the data in the language understandableto the OPERATING SYSTEM and also manages communication on the bus. The USB host controller has an embedded hub called the root hub. A hub is a common connection point that allows multiple devices to connect in the network. A hub contains multiple . The root hub connects the host controller(s) to the peripheral device and acts as the first interface layer to the USB in a system. The ports that are visible at the system’s back panel are the ports of the root hub. These ports are part of the root hub and in turn can be connected to external hub thereby increasing the number of USB devices which can be connected to host. An external hub can be used to extend the connections to the maximum of 127 devices.
Whenever a USB device is connected or disconnected it is first detected at the root hub which in turns passes information to the host controller. USB is a half duplex protocol where all data is passed via a two wire interface called D+ (D plus) and D- (D minus).
The host is responsible for the following tasks:
1.Detect attachment and removal of USB devices
2. Provide and manage power to attached devices
3. Monitor activity on the bus and initiate the process of enumeration
4. Manage data flow between host and devices.
Fig. 2: Diagrammatic Image Showing Various Devices Attached to USB
When we discuss data transfer across the USB we always use the vantage point of the host for reference. For example, if there is an IN transfer that means the host is going to receive the data. An OUT transfer means the host is going to transmit data.
USB Communication Part I (Pipes & End Points)
CONCEPT OF PIPES & END POINT
The ports are used to connect the peripheral devices like mouse, keyboards, or audio devices to them. Each device is given a specific address used during the communication process by the host. These devices are connected to the root hub and in turn to the host by pipes. A pipe is a logical connection between the host and end point and is used by client software to transfer data. It sets various parameters such as direction of data flow, length of bandwidth allocated to the device and what kind of transfer will take place. There are two types of pipes in USB one is stream pipe and other is message pipe.
· Stream Pipes– It is unidirectional communication pipes used for most of the data transfers. These pipes have no defined USB format. We can send any type of data from one end and retrieve it from another end. Data flows sequentially and has a pre-defined direction either IN or OUT. Stream pipes support bulk, isochronous and interrupt type of transfers and controlled by either host or device.
· Message Pipes– It is bi-directional communication pipes and only used for sending/receiving short messages. These pipes have defined USB format. They are host controlled initiated by request sent from the host. Data is transferred in the desired direction as per the request. They support only control transfers.
Once we have understood the pipes we learn about various types of data transfers. Depending on the type of data we need to decide which type of pipe to use.
There are four different types of data transfer in USB.
1.Control Transfer– It is used to send commands to the devices for making enquiries. This transfer uses Message pipes.
2. Interrupt Transfers– It is used to send small amount of data that requires a guaranteed minimum time delay. It uses Stream pipes.
3.Bulk Transfer– It is used for transferring large amount of data with no time guarantee and uses Stream pipes
4. Isochronous Transfers– it is used for transferring data that requires a fixed delivery rate as they are capable of fixed bus bandwidth and lack of error correction. Since there is no error correction there is no delay in transfer of data. These transfers use Stream pipes.
Fig. 3: An Overview of USB Communication
In between the device and host there is addressable buffer which is known as endpoint. An endpoint is an electrical terminal usually consists of a set of memory registers that stores the data temporarily in USB peripheral devices on their way in or out. An endpoint stores received data from the host and holds the data to be transmitted to the host. A USB device can have multiple endpoints and each endpoint has a pipe associated with it. Each endpoint is accessed with a device address assigned by the host and an endpoint number that is assigned by the device. Endpoints usually come in pairs, e.g. Endpoint 1 In and Endpoint 1 Out. One set of Endpoints, Endpoint 0 In and Endpoint 0 Out is always turned on which is used for basic commands to all USB devices.
Fig. 4: Picture Showing Relationship Between USB Host and Devices
This next figure shows the entire USB system. Let’s try to understand what exactly happens when a peripheral device is connected to the USB port and what are the processes going on between the host and the peripheral device.
Fig. 5: Block Diagram Showing Complete USB System
USB Communication Part II
When any device is connected to the PC’s USB port, it in turn gets connected to the root hub. This is known as attach event and removing of the device is known as detach event. The device is detected by the root hub by monitoring the ports voltages. A hub has a pull down resistor on D+ and D- lines. At the initial condition D+ and D- are at the same 0V potential because of the 15kohm resistors found on the host side. Now, when a cable is connected in, a pull up resistor is either on D+ or D- as specified by the manufacturer of the device so if the voltage change is detected on the D- line, then it happens to be a low speed device and voltage change is at D+ it is high speed device. Once speed is detected the process of ENUMERATION starts.
ENNUMERATION- It is a process by which host assigns an address to each of the peripheral device which allows it to communicate with the USB devices.
The enumeration process can be divided into 2 phases: Phase 1, where the host learns about the newly arrived device by reading the descriptors and loads the appropriate device driver & PHASE 2, where the device driver configures the device and makes it ready for data transfer.
STEP 1-ASSIGNING OF THE ADDRESSES
Host acknowledges about the newly attached device by port voltage changes. All devices on the USB bus will be given a unique address from the host. However when any device starts communicating with the host, it always start communicating using address 00H. A device endpoint is a uniquely addressed portion of USB device that is a source or sink of the information.
Once the initial information about the device is gathered by the host, it issues a request to the hub to reset the newly attached device. This is done by pulling both D+ and D- lines to the ground. Holding these lines low for greater than 2.5 us issues the reset condition. This reset state is held for 10 ms by the hub. A new address is assigned to each of the peripheral device once brought out of the reset state and the device responds to the request of the hosts by using control transfers by address 00h. The USB devices are enumerated sequentially and not simultaneously.
STEP 2- GATHERING INFORMATION FROM DESCRIPTORS
In the next part host starts to learn more about the device by using device descriptors. Information about a USB device is stored in segments of its ROM (read-only memory). Each time a peripheral is connected, the host will request a series of data structures from the device that will inform the host about its capabilities. These data structures are called “descriptors”. There are four types of descriptors in USB each with a specific function. The figure below gives the clear picture of the descriptors.
Fig. 6: A Closer Look at USB Descriptors
As from the figure on the top we have device descriptor next is the configuration descriptor followed by interface and then lastly end point descriptor. So, after the device descriptor, host requests for configuration descriptor, interface descriptor and end point descriptor. Each of this descriptor contains information necessary for communication between host and peripheral devices as described below.
Device Descriptors– It contains general information about the device that is accepted globally and common everywhere. A USB device can only have one device descriptor. For example when a camera is connected to the USB port, the device descriptors will send host information such as USB specification, protocols supported, vendor identification, pin identification, number of configurations a device can adopt and serial number if present.
Configuration Descriptors-Consider a multifunctional peripheral device like a video camera with internal micro-phone. At times we only use a video camera like when clicking pictures or we use micro-phone while recording the sound. In some another situation when we are interested in video recording which will use both camera and microphone. Both these arrangements will have different requirements for their working and are termed as configurations. The first configuration needs less power and the second will need more power. This is just one example of where different configuration exists in a single device; there can be other devices that will have other configuration. A configuration can be viewed as a collection of peripheral features. So, the configuration descriptors specifies values such as amount of power a particular configuration uses, secondly whether it is self powered or bus powered and last number of interfaces involved.
· Interface Descriptors– With the same example of a multifunctional device like video camera with internal microphone we can have three alternate settings.
Camera and microphone activated
Each of these different settings is present in three different interfaces. Group of endpoints forms an interface. One interface can group zero, one or many endpoints. We already know that endpoints are the temporary memory registers that stores information about the device. The end points of each interface will store different type of information specific to that setting. Interface descriptor specifies the number of end points required by a device feature.
End point Descriptors– Endpoint descriptors contain information about the I/O direction (IN which is from the device to the host or OUT which is from the host to the device), the transfer type (Control, Bulk, Interrupt, or Isochronous) and the maximum supported packet size. Devices publish Endpoint descriptors to enable clients to query what endpoint is available and what characteristics they have.
ASSIGNING AND LOADING THE DEVICE DRIVER
Once host has gathered all the information about the device it needs to load a device driver to successfully communicate with peripheral devices. A device driver is a computer program that operates or controls a particular type of device that is attached to a computer. A driver typically communicates with the device through the computer bus to which the hardware connects. When a program is called to run a particular peripheral device the driver issues commands to the device. Once the device sends data back to the driver, the driver may start routines in the original program being called. Drivers are hardware-dependent and operating-system specific. An operating system has broad group I/O devices with similar characteristics and will use particular class drivers to interact with the devices.
Fig. 7: Image Showing Various Driver Classes
A class specification defines functions that describe how the data will be transferred. They also define the number and type of buffers that are supported by the class. Classes make it easier to develop device drivers and firmware in a standardized way. USB devices that share many attributes or request similar services are grouped within the same class.
If a device was previously enumerated, operating system uses its registry to search for the proper driver. Once a driver is identified, the host may request additional descriptors that are specific to the device class or request that descriptors are resent.
For example in case of Windows it uses its INF files to locate a match for the devices Product ID and Vendor ID. An INF file is a Setup Information file, is a plain text file used by Microsoft Windows for installation of software and drivers. Device can also release version numbers which can be used optionally. If Windows cannot find a match, then it looks at the driver from a different perspective by looking for a match with any class, subclass, and protocol retrieved from the device.
LOADING OF APPLICATION SOFTWARE
Once the specific driver is loaded the data exchange between the host and peripheral device starts. Applications software associated with particular type of device can be used to improve the performance of the device. Graphics software, media players, enterprise software are some examples of application software.
Cables and Connectors
USB cable and connectors
From an outer overview, USB has two components: cables and connectors. These connectors connect devices to a host. A USB cable consists of multiple components that are shielded by an insulating jacket. Underneath the jacket is an outer shield that contains a copper braid. Inside the outer shield are multiple wires: a copper drain wire which is a twisted pair of cable, a VBUS wire (red) and a ground wire (black). An inner shield made of aluminum contains a twisted pair of data wires.
Fig. 8: Cross Sectional View of USB Cables and Connectors
There is a D+ wire (green) and a D- wire (white). In full-speed and high-speed devices, the maximum cable length is 5-meters. To increase the distance between the host and a device, you must use a series of hubs and 5-meter cables. While USB extension cables exist in the market, using them to exceed 5 meters is against the USB specification. Low-speed devices have slightly different specifications. Their cable length is limited to 3 meters and low-speed cables are not required to be a twisted pair as USB Twisted Pair Data Wires. The voltage bus gives a constant 4.40 v – 5.25v supply to all devices and the data lines supplies up to 3.3v. The reason for using the differential D+ and D- signal is for rejecting common-mode noise. If noise becomes coupled into the cable, it will normally be present on all wires in the cable. With the use of a differential amplifier in the USB hardware internal to the host and device, the common mode noise can be rejected.
Now we move ahead and learn more about the connectors. The figure below shows the various types of connectors.
Fig. 9: Overview of Various USB Ports
There are many different types of USB ports and connectors available. The upstream connection always uses a Type A port and connector, while the device uses Type B ports and connectors. Initially, the USB specification included only the larger Type A and Type B connectors for devices but later included the Mini and Micro connections. These Mini and Micro connectors were initially developed for USB On-the-Go which is a USB specification that allows devices that would normally act as slaves to become hosts but later they were adopted in devices as they had smaller size as compared to type B.
1. Type A- It is used for connecting the cable to the host device also known as upstream end. They are flat in shape and have four connections in line.
2. Type B- It is used to connect cable to peripheral device and also known as downstream end. They are square in shape and have two connections on both sides of centre.
Micro A and Micro B type connector’s description table.
Benefits of USB
BENEFITS OF USB
USB has benefits for everyone. It helps to reach the first time PC consumer by overcoming usability barriers through easy peripheral installation. The end user has a more rewarding and productive experience.
Below is a table of current capabilities that USB has to offer:
Fig. 11: Table Describing Both Micro A and Micro B Type Connector