☰
USB basic knowledge
2026/10/23 2:45:28 网站建设 项目流程

USB basic knowledge

For an embedded engineer, the easiest way to understand USB is as a hierarchical device model:

USB Device ├── Configuration 1 │ ├── Interface 0 │ │ ├── Endpoint 1 IN │ │ └── Endpoint 2 OUT │ └── Interface 1 │ └── Endpoint 3 IN │ └── Configuration 2 └── ...

1. USB Host vs Device

Host

The controller that manages the USB bus.
Examples:

  • PC
  • Raspberry Pi (host mode)
  • Phone with OTG enabled

Responsibilities:

  • Detect devices
  • Enumerate devices
  • Assign addresses
  • Schedule all transfers

Device
The peripheral connected to the host.
Examples:

  • Keyboard
  • Webcam
  • Flash drive
  • Printer

A USB device never talks unless the host asks it to.

2. Device

A Device is the complete USB peripheral.
Examples:

  • A webcam
  • A USB audio dongle
  • A flash drive

Each device contains device descriptor information such as:

  • Vendor ID (VID)
  • Product ID (PID)
  • Device Class
  • Serial Number

Example:

VID = 0x046D (Logitech) PID = 0x0825

The host first sees the device descriptor during enumeration.

3. Configuration

A Configuration describes one operating mode of a device.
A device may have:

Configuration 1 Configuration 2 ...

Host selects exactly one active configuration.
Example:
A modem might have:

Config 1: CDC Serial Interface Config 2: CDC + Mass Storage

The host chooses one using:

SET_CONFIGURATION

Most modern USB devices only have one configuration.

4. Interface

An Interface represents a logical function inside a configuration.
Examples:

Composite Device

A USB webcam with microphone:

Configuration 1 ├── Interface 0 : Video └── Interface 1 : Audio Or a keyboard + mouse combo:
Configuration 1 ├── Interface 0 : Keyboard └── Interface 1 : Mouse

An OS driver usually binds to an interface.

5. Alternate Setting

An interface may have multiple alternate settings.
Used when the same function can operate with different bandwidth requirements.
Example:

Interface 1 : Camera Alt 0: No video streaming Alt 1: 640x480@30fps Alt 2: 1280x720@30fps

Only one alternate setting is active at a time.

6. Endpoint

An Endpoint is a communication channel between the host and the device. A useful way to think about it:

Interface = Function Endpoint = Pipe used by that function

Every endpoint has the following attributes:

  • Address
  • Direction
  • Transfer type
  • Max packet size

Example:

Endpoint 1 IN Endpoint 2 OUT

Direction

IN

  • Device → Host

OUT

  • Host → Device

Remember:

Direction is defined from the HOST's perspective.

Example:

EP1 IN

means:

Device sends data to Host

7. Endpoint 0 (Control Endpoint)

Every USB device must implement:

Endpoint 0

Used for:

  • Enumeration
  • Reading descriptors
  • Device configuration
  • Standard requests

Examples:

GET_DESCRIPTOR SET_ADDRESS SET_CONFIGURATION

Without EP0, a USB device cannot function.

8. Transfer Types

Control Transfer
Used on EP0.

Purpose:

  • Configuration
  • Commands
  • Status

Examples:

GET_DESCRIPTOR SET_INTERFACE

Bulk Transfer
Reliable data transfer.

Characteristics:

  • Error checked
  • Retries automatically
  • Variable latency

Examples:

  • USB flash drive
  • USB printer

Interrupt Transfer
Small low-latency transfers.

Examples:

  • Keyboard
  • Mouse
  • Game controller

Despite the name, it is not a CPU interrupt.

The host polls periodically.

Isochronous Transfer
Real-time streaming.

Characteristics:

  • Guaranteed bandwidth
  • No retries

Examples:

  • Webcam video
  • USB microphone
  • USB speaker

Missing packets are tolerated to maintain timing.

9. Pipe

A Pipe is the host-side view of an endpoint.

Host Software | Pipe | Endpoint | Device

Endpoint exists in the device.

Pipe exists in the host.

10. USB Enumeration Process

When a device is plugged in:

Step 1
Host detects connection.

Step 2
Host resets device.

Step 3
Host reads Device Descriptor.

Step 4
Host assigns address.

SET_ADDRESS

Step 5
Host reads:

  • Configuration descriptor
  • Interface descriptors
  • Endpoint descriptors

Step 6
Host selects configuration.

SET_CONFIGURATION

Step 7
Driver loads.

Step 8
Normal data transfer begins.

11. Example: USB Webcam

USB Device | +-- Configuration 1 | +-- Interface 0 (Video Control) | | | +-- EP0 Control | +-- Interface 1 (Video Streaming) | +-- EP1 IN (Isochronous Video)

Enumeration:

Host └─ Device └─ Config 1 ├─ Interface 0 └─ Interface 1 └─ EP1 IN

Video frames flow through:

EP1 IN Device ---> Host

Quick Interview Summary

One-sentence memory aid
Device → contains Configurations → contain Interfaces → use Endpoints for data transfer.

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询