knowledge-base

USB Spec and how it works

Here I summerize useful information on how USB works, this is a part of my research project to use a PS4 controller in the browser.

Terms And Abbreviations

The extensive list can be found here.

Architectural Overview

Host-scheduled, token-based protocol.

USB System

3 areas

A USB device usually provides one or more “functions”.

USB Protocol

All communication happens through a POLLING mechanism. So the USB Bus Protocol is Poll oriented.

Most bus transactions involve transmissions of up to 3 packets. Each transaction begins when the Host Controller, on a scheduled basis, sends a USB Token packet describing the:

The addressed USB device selects itself by decoding the appropriate address fields. (AH! That’s me!). The targeted device will then send a data packet or indicate if it has no data to transfer. The host will then reply witha handshake packet indicating if the transfer was successful.

The data transfer model between source and destination on the host and an endpoint is reffered to as a pipe.

A pipe can be

One message pipe, the Default Control Pipe always exists once a device is powered. (used for device’s configuration, status and control information)

The Host assigns a unique USB address to a newly attached device and then determines if it’s a Device or Hub or a Function. Then the hosts establishes its end of the control pipe for the newly attached USB device using the assigned USB address and endpoint 0x0.

If the newly attached device is a hub with attached devices, the above procedure is followed for each of the attached USB devices.

USB Enumeration

Activity that identifies and assigns unique address to devices attached to a bus. This happens periodically and does the detection of removing and adding of devices.

Data Flow Types

Data and control change happens through a set of either uni-directional or bi-directional pipes. Transfer take place between host software and a particular endpoint on a USB device. The association between the Host Software and a USB device endpoint is a pipe. In general, data movement through one pipe is independent from the data flow of any other pipe.

A single pipe only supports one data flow type for any given device configuration.

USB Devices

Devices are divided into classes such as hub, human interface, printer, imaging or mass storage device.

Each device is assigned an address when attached and enumerated. USB devices will have a designated pipe at endpoint 0x0 where to the *Default Control Transfer` pipe will be established. From the default control pipe we get the characteristics of a device:

Two major classes exist, hubs and functions. Functions provide capabilities to the host, hubs just more connections.

A device can have multiple functions (like sound and video, like a webcam). Each function will have a configuration. Before function can be used, it MUST be configured by the host.

USB Data Flow Model

Protocol Layer

… maybe others