Build a USB 2.0 device from scratch
Friday 15, July 2016 Philémon `PhilGekni` Gardet <phil@lse.epita.fr>
1 / 34
Build a USB 2.0 device from scratch Friday 15, July 2016 Philmon - - PowerPoint PPT Presentation
Build a USB 2.0 device from scratch Friday 15, July 2016 Philmon `PhilGekni` Gardet <phil@lse.epita.fr> 1 / 34 2 / 34 Plan The Overview The Protocol layers Implementation considerations 3 / 34 The Overview 4 / 34 Host
Friday 15, July 2016 Philémon `PhilGekni` Gardet <phil@lse.epita.fr>
1 / 34
2 / 34
3 / 34
4 / 34
Topology
Host
RootHub Hub Hub Hub Hub Hub Hub Hub Dev Dev Dev Dev Dev Dev Dev Dev
7 levels Host
Hubs
notifications
Devices
5 / 34
Endpoints and pipes device Basic types
Full-speed
min
Device #? Control endpoint 0 Interface 1 In 1 Out 1 Interface 2 In 2 Out 2
Access by device + endpoint address
6 / 34
Interrupt transfer (≤ 64 Bytes)
Regular queries
Bulk transfer (≤ 1023 Bytes)
Large packet
Isochronous transfer (≤ 64 Bytes)
Constant bandwidth
Control transfers (≤ 64 Bytes)
Device setup / Hubs management / Status Full-speed bandwidth
Isochronous up to 69%
Interrupt 5% Bulk 5% Control 7%
7 / 34
Device Class
Class Base ID Descriptor Usage Description 00h Device Refer to Interfaces 01h Interface Audio 02h Both Communication and CDC 09h Device Hub EFh Both Miscellaneous FEh Interface Application Specific FFh Both Vendor specific
8 / 34
Vendor ID / Product ID Device signature
vid:pid
Vendor ID
Delivered by the USB-IF
Product ID
Chosen by vendor
www.linux-usb.org/usb.ids
9 / 34
10 / 34
Name Voltage Domain
Vcc 5 V D+ 3.3/0 V D- 3.3/0 V GND Ground
11 / 34
Hub
Full-speed link (D+ pull-up)
D SE0 OE D D+ D-
Device
D SE0 OE D D+ D-
D+ D-
15KΩ 3.3V 15KΩ 1.5KΩ 12 / 34
Half-Duplex
13 / 34
Data NRZI
0 1 1 0 1 0 0 0 1 1 1 0 1 1
14 / 34
Stuffed Data NRZI Data
0 0 0 1 1 1 1 1 1 1 1 0 1 1
15 / 34
Sync / SOP
Start of packet
EOP
End of packet
Reset
Full-speed: J=1 and K=0
D+ D-
Idle K J K J K J K K
2 bits 10-20 mS
16 / 34
Token package Data package Handshake package
Upstream IN : Upstream OUT : Downstream IN : Downstream OUT : Upstream
Timeout : 6.5 - 7.5 bit times
(total window : 16 bit times)
17 / 34
Token
OUT IN SETUP
Data
DATA0 DATA1
Handshake
ACK NAK STALL
PID code Check code
PID
4 bits 4 bits 1’ complement
18 / 34
Data CRC16 PID SYNC EOF PID SYNC EOF Dev addr Endpt addr CRC5 PID SYNC EOF
Token packet Data packet Ack packet
8 bits 8 bits 7 bits 4 bits 5 bits 2 bits 16 bits
19 / 34
Device
descriptor
Configuration
descriptor
Configuration
descriptor
Interface
descriptor
Interface
descriptor
Interface
descriptor
Endpoint
descriptor
Endpoint
descriptor 20 / 34
Device
descriptor
Configuration
descriptor
Interface
descriptor
Endpoint
descriptor
Class - Subclass - Protocol - VID - PID Max packet size endpoint 0 Power attributes - Max power Class - Subclass - Protocol Alternative setting Endpoint address - Endpoint type
21 / 34
Configuration
22 / 34
Configuration
23
Internal hub registers updating
23 / 34
Configuration
24
24 / 34
Configuration
25
with 0 address
25 / 34
Configuration
Descriptors
descriptors
26 / 34
27 / 34
Hardware role
level
error detection
Payload SYNC EOF
28 / 34
NRZI & Bit stuffing NRZI & Bit stuffing Shift register Shift register Buffer Buffer Hold Rx Tx RRDY RACK TMT TRDY ERR Rx Tx Hold
29 / 34
Status Manager PLL NRZI & Bit stuffing NRZI & Bit stuffing Shift register Shift register Buffer Buffer Hold Hold Rx Tx OE SE0 D+ D- PLL_E D- D+ TOE ERR Rx Tx RRDY RACK TMT TRDY D+ D-
30 / 34
RESET
PLL and resynchronization D+ D-
“ Dynamic adjustment of the
charge-pump current and loop- filter components to facilitate dynamic reconfiguration of the PLL bandwidth. This feature is available only in Arria GX, HardCopy II, Stratix II, Stratix II GX, Stratix III, and Stratix IV devices. “
Sync pattern
31 / 34
Microchip USB3320
32 / 34
33 / 34
ANDERSON Don, DZATKO Dave. Addison-Wesley, 2001
http://www.beyondlogic.org/usbnutshell
http://www.usb.org/developers/docs/devclass_docs
http://pid.codes/
34 / 34