接口协议(4) - USB
USB(Universal Serial Bus,通用串行总线)是一种新兴的并逐渐取代其他接口标准的数据通信方式,作为一种高速串行总线,其极高的传输速度可以满足高速数据传输的应用环境要求,且该总线还兼有供电简单、安装配置便捷、 扩展端口简易、传输方式多样化,以及兼容良好等优点。
1. 通信速率
Standard | Also Known As | Logo | Year Introduced | Connector Types | Max. Data Transfer Speed | Cable Length** |
USB 1.1 | Full Speed USB | 1998 |
USB-A USB-B |
12 Mbps | 3m | |
USB 2.0 | Hi-Speed USB |
|
2000 |
USB-A USB-B USB Micro A USB Micro B USB Mini A USB Mini B USB-C* |
480 Mbps | 5m |
USB 3.2 Gen 1 |
USB 3.0 USB 3.1 Gen 1 SuperSpeed |
|
2008(USB 3.0) 2013(USB 3.1) |
USB-A USB-B USB Micro B USB-C* |
5 Gbps | 3m |
USB 3.2 Gen 2 |
USB 3.1 USB 3.1 Gen 2 SuperSpeed+ SuperSpeed 10Gbps |
|
2013(USB 3.1) |
USB-A USB-B USB Micro B USB-C* |
10 Gbps | 3m |
USB 3.2 Gen 2x2 |
USB 3.2 SuperSpeed 20Gbps |
|
2017(USB 3.2) | USB-C* | 20 Gbps | 3m |
USB 4 |
USB 4 Gen 2x2 USB 4 20Gbps |
|
2019 | USB-C* | 20 Gbps | 0.8m |
USB 4 |
USB 4 Gen 3x2 USB 4 40Gbps |
|
2019 | USB-C* | 40Gbps | 0.8m |
USB 3.0发布时叫USB 3.0,USB 3.1发布后,USB 3.0改成了USB 3.1 Gen 1,而真正的USB 3.1叫做USB 3.1 Gen 2,后来,发布USB 3.2之后,USB3.0和USB 3.1的名字也跟着升级,三者分别为USB 3.2 Gen 1,USB 3.2 Gen 2,USB 3.2 Gen 2x2.
2. USB接口
Type-A and -B pinout | ||||
Pin | Name | Wire color | Description | |
1 | Vbus | Red or | Orange | +5V |
2 | D- | White or | Gold | Data- |
3 | D+ | Green | Data+ | |
4 | GND | Black or | Blue | Ground |
Mini/Micro-A and -B pinout | |||
Pin | Name | Wire color | Description |
1 | Vbus | Red | +5V |
2 | D- | White | Data- |
3 | D+ | Green | Data+ |
4 | ID | No Wire |
On-The-Go ID Distinguishes cable ends: "A" plug (host): Connected to GND "B" plug (device): not connected |
5 | GND | Black | Signal ground |
Micro-B SuperSpeed pinout | ||
Pin | Name | Description |
1 | Vbus | +5V |
2 | D- | Data- |
3 | D+ | Data+ |
4 | ID | On-the-GO |
5 | GND | Signal ground |
6 | SSTx- | SuperSpeed transmit- |
7 | SSTx+ | SuperSpeed transmit+ |
8 | GND | Signal ground |
9 | SSRx- | SuperSpeed receive- |
10 | SSRx+ | SuperSpeed receive+ |
USB 3.0 connector pinouts | ||||
Pin | Color | Signal Name | Description | |
A connector | B connector | |||
1 | Red | Vbus | +5V | |
2 | White | D- | USB 2.0 differential pair | |
3 | Green | D+ | ||
4 | Black | GND | Ground for power return | |
5 | Blue | StdA_SSRX- | StdB_SSTX- | SuperSpeed receiver differential pair |
6 | Yellow | StdA_SSRX+ | StdB_SSTX+ | |
7 | ---- | GND_DRAIN | Ground for signal return | |
8 | Purple | StdA_SSTX- | StdB_SSRX- | SuperSpeed transmitter differential pair |
9 | Orange | StdA_SSTX+ | StdB_SSRX+ | |
The USB 3.0 Powered-B connector has two additional pins for power and ground supplied to the device. | ||||
10 | ---- | DPWR | Power provided to device (Powered-B only) | |
11 | DGND | Ground for DPWR return (Powered-B only) |
USB Type-C pinout | ||||||
Type-C receptacle A pin layout | Type-C receptacle B pin layout | |||||
Pin | Name | Description | Pin | Name | Description | |
A1 | GND | Ground return | B12 | GND | Ground return | |
A2 | SSTXp1(TX1+) | SuperSpeed differential pair #1, TX, positive | B11 | SSRXp1(RX1+) | SuperSpeed differential pair #2, TX, positive | |
A3 | SSTXn1(TX1-) | SuperSpeed differential pair #1, TX, negative | B10 | SSRXn1(RX1-) | SuperSpeed differential pair #1, TX, negative | |
A4 | Vbus | Bus power | B9 | Vbus | Bus power | |
A5 | CC1 | Configuration channel | B8 | SBU2 | Sideband use(SBU) | |
A6 | Dp1(D+) | USB 2.0 diffential pair, position 1, positive | B7 | Dn2(D-) | USB 2.0 diffential pair, position 1, negative | |
A7 | Dn1(D-) | USB 2.0 diffential pair, position 1, negative | B6 | Dp2(D+) | USB 2.0 diffential pair, position 1, positive | |
A8 | SBU1 | Sideband use(SBU) | B5 | CC2 | Configuration channel | |
A9 | Vbus | Bus power | B4 | Vbus | Bus power | |
A10 | SSRXn2(RX2-) | SuperSpeed differential pair #4, RX, negative | B3 | SSTXn2(TX2-) | SuperSpeed differential pair #4, RX, negative | |
A11 | SSRXp2(RX2+) | SuperSpeed differential pair #4, RX, positive | B2 | SSTXp2(TX2+) | SuperSpeed differential pair #3, RX, positive | |
A12 | GND | Ground return | B1 | GND | Ground return |
3. 工作原理
USB是利用差分信号进行数据传输的,差分信号具有抗干扰的特性。
4. 传输模式
Type | KeyPoint | Sample | Description |
控制传输 (Control Transfers) |
完整性校验 | USB配置命令 |
突发的、非周期性的,主机软件发起的请求/响应通信,通常用于命令/状态操作。 数据量小对带宽、时间延迟要求不高,但是要求数据必须正确。 |
等时传输 (Isochronous Transfers) |
带宽、时间延迟 | 摄像头 |
等时传输:主机和设备之间定期、连续的通信,通常用于时间相关信息。 这种传输类型还保留了数据中封装的时间概念。然而,这并不意味着这些数据的交付需求总是时间紧迫的。 数据量大需要大带宽、对时间延迟也很高,但是不要求数据必须正确。也正因为前两者的要求高,也很难做到数据校验和重传。 |
中断传输 (Interrupt Transfers) |
时间延迟、完整性校验 | 键盘、鼠标 |
低频、有边界延迟通信。 对时间延迟要求高,但数据量小所以要求数据必须正确。 |
批量传输 (Bulk Transfers) |
带宽、时间延迟、完整性校验 | 文件存储 |
非周期性、大包突发通信,通常用于可以使用任何可用带宽的数据,也可以延迟到带宽可用。 数据量大需要大带宽,但对时间延迟也不高,要求数据必须正确。也正因为对延迟要求不高,所以可以做数据校验和重传。 |
5. 组成结构
5.1 Transfer/Frame (传输): 从时间的维度看,USB通信是由一系列的Transfer(传输)组成的。包括四种传输类型:
- Control Transfers 控制传输
- Isochronous Transfers 同步传输
- Interrupt Transfers 中断传输
- Bulk Transfers 批量传输
5.2 Transaction (事务): 每一个Transfer(传输)又可以分成不同的Transaction, 具体的Transaction类型为以下3种:
- IN/Read/Upstream Transaction 输入(Host)事务
- OUT/Write/Downstream Transaction 输出(Host)事务
- Control Transaction 控制事务
5.3 Packet 每一次Transaction又由不同的Packets所组成
- Token Packet
- Data Packet
- Handshake Packet
- Special Packet
5.4 Field 每一个Packet又由不同的Field组成:
- Sync 同步域
- PID 标识域
- ADDR 设备地址域
- ENDP 端点域
- FRAM 帧号域
- DATA 数据域
- CRC 校验域
6. 枚举过程
枚举过程如下。