USB 2.0 ARCHITECTURE Overview The Basics

KANWAR SAAD BIN LIAQAT Research Assistant - UG

AGENDA

• Main Features & History • Basic Definitions • Device Enumeration Steps • Data Transfer Modes

HISTORY

• USB 1.0 (Jan 1996) • USB 1.1 (Sep 1998) • USB 2.0 (Apr 2000) • USB 3.0 (Nov 2008)

FEATURES • Supported data rates : 1.5Mbps, 12Mbps, 480Mbps • No. of devices : 127 including hubs • Supports hot plugging • External bus • Max hub levels : 5 • Uses tiered

BASIC DEFINITIONS -- Bus Speeds

Speed Name

USB version

Data rate

Low Speed

USB 1.0

1.5 Mbps

Full Speed

USB 1.1

12 Mbps

High Speed

USB 2.0

480 Mbps

Super Speed

USB 3.0

4.8 Gbps

BASIC DEFINITIONS -- Bus Topology Tiered Star Bus Topology

BASIC DEFINITIONS -- HOST • Master of the bus • Initializes all transactions. • Devices cannot communicate directly with each other. • The only exception is that a suspended device can initiate a remote wake-up call.

BASIC DEFINITIONS -- Cables • Shielded cable containing 4 wires • Two of these D+ and D- form a twisted pair, responsible for carrying differential data and single ended signals. • Third one is the ground wire as a reference for D+ and D- named GND. • Fourth one is the 5V supply called VBUS

BASIC DEFINITIONS -- Cable Length

• Max cable length = 5m • Since hub levels are allowed so a device can be at the most 25m away from the host. • Hence for transferring data through USB the device should be closer to the host.

BASIC DEFINITIONS -- Connectors

BASIC DEFINITIONS -- Powering

• • • • • •

Bus provides 5V supply on a single wire. Unit load = 100mA 5 unit loads allowed at max. i.e. 500mA Low power devices draw 1 unit load at max. By default a device is configured low power device. High power devices can utilize max unit loads supported by bus on demand. • If the device requires more power than this then device should arrange it’s own power and it is called a ‘self powered device’.

BASIC DEFINITIONS -- Line States • Detached : No device plugged in. D+ and D- are low. • Attached : Device is plugged in. Either D+ or D- will go high. • Idle : State before and after a packet is sent. One of the D+ or Dline remains high and other remains low.

BASIC DEFINITIONS -- J, K, SE0 and SE1

• • • •

J : Same polarity as the idle state. K : Opposite of K. SE0 : Single Ended zero state is when both lines are pulled low. SE1 : When both lines are pulled high. There is no such signal as SE1, hence whenever such a signal comes, it shows an error.

BASIC DEFINITIONS -- RESET Signal • Host Keeps SE0 state for at least 10ms. However device will recognize it after 2.5us. • It is NOT a power on type reset. It is just a protocol reset to ensure that the device signaling starts from a known state.

-- EOP Signal • End of Packet signal is sent whenever a packet ends. • It is an SE0 signal for 2 bit times followed by a J state for 1 bit time.

BASIC DEFINITIONS -- SUSPEND Signal • When there is an inactivity at the device then host keeps SE0 state for 3ms. This sends the device to suspend state. • A suspended device may draw no more than 0.5 mA from Vbus. • A suspended device must recognise the resume signal, and also the reset signal.

-- RESUME Signal • When a suspended device wants to wake up, it sends a resume signal. • This is achieved by reversing the polarity of the lines for atleast 20ms.

BASIC DEFINITIONS -- Packets

• • • • • • •

Smallest Element of data transmission. Each packet contains integral no. of bytes. Least Significant Bit(LSB) is transmitted first. The bus is in the idle state, before and after the packet. Packet = synch + data bytes + EOP NRZI Encoding is used. To ensure synchronized clock bit stuffing is used. A zero is inserted after every 6 consecutive 1’s.

BASIC DEFINITIONS -- EndPoint (EPn) • • • • •

Each USB device has a number of endpoints. Each endpoint is a source or sink of data. A device can have up to 16 OUT and 16 IN endpoints. IN and OUT are referenced from Host. EP0 is a special case. EP0 = EP0(IN) + EP0(OUT).

-- Pipe • A logical data connection between the host and a particular endpoint, in which we ignore the lower level mechanisms for actually achieving the data transfers. • A pipe is seen from upper layers.

Device Enumeration Steps

DEVICE ENUMERATION… Step 01 : Plug the device in USB port • Port may be in the host or hub. • Hub provides power to the port. • Device is in the powered state.

Step 02 : Hub detects the device • The hub monitors the voltages of signal lines. • If there is change in any of the line voltages it means a device is connected.

DEVICE ENUMERATION… Step 03 : Host learns of the new device • Each hub uses it’s interrupt pipe to report events at the hub. • The report indicates whether a port or a hub has experienced an event. • When the host learns of an event, it sends a GET_PORT_STATUS request to the hub. • Hub replies of an event that a device is attached.

DEVICE ENUMERATION… Step 04 : Hub detects whether device is low or full speed. • • • • •

Hub has both D+ and D- lines pulled down through 1.5kΩ resistors. A full speed device has a 1.5kΩ pull up resistor on D+ line. A low speed device has a 1.5kΩ pull up resistor on D- line. Initially a high speed device is also detected as a full speed device. Hub detects which line is pulled up by the device. Based on the pulled up line, the hub knows whether the device is full speed or low speed.

DEVICE ENUMERATION… Step 04 : Hub detects whether device is low or full speed.

A Full speed device is connected

DEVICE ENUMERATION… Step 04 : Hub detects whether device is low or full speed.

A low speed device is connected

DEVICE ENUMERATION… Step 05 : Hub resets the device. • Host learns that a new device is attached. • It requests the hub to reset the device. • Host gives a reset signal to the device. i.e. it keeps SE0 signal on lines for at least 10ms.

DEVICE ENUMERATION… Step 06 : Host learns if a full speed device supports high speed. • During the 10ms reset the device that supports high speed sends a chirp K signal. • A hub that supports high speed responds with an alternating chirp K,J signal. KJKJKJ. • When device recieves this signal it removes it full speed pull up and performs rest of it’s communication at high speed. • All high speed devices must be capable of responding to enumeration requests at full speed.

DEVICE ENUMERATION… Step 06 : Host learns if a full speed device supports high speed.

DEVICE ENUMERATION… Step 07 : The hub establishes a signal path between the device and the hub. • The host first verifies that the device has exited the reset state or not by sending a GET_PORT_STATUS request. • A bit in the data returned shows whether the device is in reset state or not. • If necessary the host repeats the request until device exits the reset state. • When the hub removes the reset, the device is in the default state. • The device is ready for control transfers through EP0. • The device can communicate with the host using a default address of 00h.

DEVICE ENUMERATION… Step 08 : The Host learns about the max packet size of the default pipe of the device. • The host sends a request to device 0 at EP0. Because the host can enumerate only one device at a time hence only one device has an address of 00h. • The device returns a 8 byte device description that contains the max packet size supported by EP0.

DEVICE ENUMERATION… Step 09 : The Host assigns an address. • The host controller assigns a unique address to the device. • The device reads the request and ACK’s it. • The device is now in address state.

Step 10 : The Host learns about device’s abilities. • The host sends get_descriptor request to the device at new address. • The device replies with the device_descriptor. • Device_descriptor contains max packet size of EP0, the no. of configurations the device supports and other basic information about the device.

DEVICE ENUMERATION… Step 11 : The host assigns and loads a device driver. • After host learns as much as it can of the device, it searches for it’s device driver so that it can communicate with the device. • The vendor and product ID’s retrieved from the devices can be used to match the correct device driver. • If there is no match then host matches any class, sub-class or protocol values. • Whatever matches, the host the loads its driver for further communication.

DEVICE ENUMERATION… Step 12 : The device driver selects a device configuration. • The device can support multiple configuration. • The host then asks from the user for what configuration to load or it may select the first one. • When the configuration is loaded, the device is configured and now it is ready to use.

HUB ENUMERATION…

• Hubs are also USB devices. • A hub is enumerated in exactly the same way a device is enumerated. • If the hub has devices attached, the host also enumerates each of these after the hub informs the host of their presence.

DEVICE REMOVAL…

• The host constantly polls the hub. • When a device is removed, hub responds the host that an event has occurred. • The host sends a GET_PORT_STATUS request to find out what event has occurred. • The host then removes that device from it’s list and the address of that device is assigned to another newly attached device.

DATA TRANSFER TYPES • Bulk Transfer • Interrupt Transfer • Isochronous Transfer • Control Transfer

1. BULK TRANSFER

• Useful for transferring data when time isn’t critical. • For sending large amounts of data without clogging the bus. • Has lowest priority. • Examples : sending data from PC to a printer, transferring data from a flash disk e.t.c • When the bus is idle, they are the fastest mode of error free transfer.

1. BULK TRANSFER… Availability : • Only full speed and high speed devices can do bulk transfer. • All devices do not need to support bulk transfers, only a certain device classes need it. E.g. mass storage devices.

Data Size : • Max packet sizes of 8, 16, 32, or 64 bytes. • If the data to be transferred do not complete in one packet then the host completes the transfer using multiple transactions.

1. BULK TRANSFER… Speed : • Host guarantees that the data transfer completes eventually. • Don’t reserve any transfer for the data hence if bus is busy it may take very long. • When bus is idle, it is the fastest mode of transfer since it has the lowest protocol overhead.

Detecting and handling errors: • Use handshake packets such as ACK, NACK e.t.c for error free transmission of data. • If a device doesn’t send handshake packet then host retries twice. • Use data toggle bits to ensure no data is lost.

1. BULK TRANSFER… Example transfer :

2. INTERRUPT TRANSFER

• When a data has to be transferred within a specific amount of time. • Typical applications are human interface devices such as mouse, keyboard. • Limited bandwidth available in low and full speed but it becomes 400x in high speed. • It does not generates interrupt as its name implies rather it also works the same way that all other transfers do i.e through polling.

2. INTERRUPT TRANSFER… Availability : • All versions of usb support this type of transfer. • All devices do not need to support Interrupt transfers, only a certain device classes need it. E.g. HID’s.

Data Size : • • • •

Low speed : 1 – 8 bytes Full speed : 1 – 64 bytes High speed : 1 – 1024 bytes If the data to be transferred do not complete in one packet then the host completes the transfer using multiple transactions.

2. INTERRUPT TRANSFER… Speed : • No guaranteed transfer rate. • Just ensures that no more latency than specified. • High speed interrupt transfers can be very fast.

Detecting and handling errors: • Use handshake packets such as ACK, NACK e.t.c for error free transmission of data. • If a device doesn’t send handshake packet then host retries twice. • Use data toggle bits to ensure no data is lost.

2. INTERRUPT TRANSFER… Example transfer :

3. ISOCHRONOUS TRANSFER

• • • • •

Used for streaming and real time transfers. Ensures a constant data rate. At full speed it can transfer more data than in interrupt transfer. Examples: encoded voice played in real time. Ensures that a large amount of data gets through quickly on a busy bus. • Completion time is predictable.

3. ISOCHRONOUS TRANSFER… Availability : • Only full and high spped devices support this type of transfer. • All devices do not need to support Isochronous transfers, only a certain device classes need it. E.g. video streaming.

Data Size : • • • •

Full speed : 0 – 1023 data bytes High speed : 1024 bytes packet size Amount of data in each frame doesn’t have to be same. If the data to be transferred do not complete in one packet then the host completes the transfer using multiple transactions.

3. ISOCHRONOUS TRANSFER… Speed : • 1.023 MBps at max. • Leaves 31% bus bandwidth for other purposes. • Protocol overhead is 9 bytes per transfer.

Detecting and handling errors: • No error correction. • Intended for uses where small errors are acceptable.

3. ISOCHRONOUS TRANSFER… Example transfer :

4. CONTROL TRANSFER

• Two uses. 1. Carry the requests for USB specifications. 2. Configure devices. • Interactive transfer. Include IN and OUT transactions.

4. CONTROL TRANSFER… Availability : • Every device must support control transfer over default pipe EP0. • A device may have additional pipes configured for control purposes. But additional control pipes can offer no advantage.

Data Size : • • • •

Low speed : 8 bytes Full speed : 8, 16, 32, or 64 bytes High speed : 64 bytes If the data to be transferred do not complete in one packet then the host completes the transfer using multiple transactions.

4. CONTROL TRANSFER… Speed : • Host ensures that all control transfers get through the bus as quickly as possible. • Reserved bandwidth : 10 % for low and full speed, and 20 % for high speed.

Detecting and handling errors: • Two retries if no handshake packet is received. • After that host stops all transactions and informs the software that there is a problem at the control port which must be rectified. • Use data toggle bits to ensure no data is lost.

4. CONTROL TRANSFER… Example transfer :

Questions?

Thank you !