USB Tutorial 1 USB Tutorial Objectives n n
USB Tutorial 1
USB Tutorial Objectives n n Review USB functionalities Be able to read a USB trace Understand the enumeration process Highlight that class drivers are part of the USB success 2
USB Tutorial Few generalities on USB Host Root Hub n n - HUB - Function - Up to 127 peripherals HUB n n HUB Keyboard Disk n Speaker Printer Tiered start topology 2 types of peripherals: A master/slave architecture USB 2. 0 spec supercedes USB 1. 1 spec - USB 2. 0 LS ( USB 1. 1 at 1. 5 Mbps) USB 2. 0 FS ( USB 1. 1 at 12 Mbps) USB 2. 0 HS (480 Mbps) Power Management - Different device class: bus powered or self powered Vbus > 4. 35 V. 100 m. A, (500 m. A after negociation), 500 u. A in suspend mode Host disables power to ill-behaved peripherals 3
USB Tutorial The Transaction Protocol is Host Based n Host based token polling - Data from host-to-function and function-to-host - Host handles most of the protocol complexity - Peripheral design is simple and low-cost n Robustness - n Handshake to acknowledge data transfer and flow control Very low raw physical bit error rate (< 10 – 10) CRC protection plus hardware retry option Data toggle Sequence bits Bounded transfer characteristics - Data transfer bandwidth and latency prenegociated - Flow control for peripheral buffer management n No asynchronous message/interrupt from the peripheral 4
USB Tutorial USB Topology n n A unique device address is assigned to each USB device Physical tiered start network: HOST Root Hub @: 1 USB cable n Hub @: 2 Keyboard @: 6 Logical network: HUB Driver MSD Driver Audio Driver Mouse @: 4 IP phone @: 5 Hub @: 2 Dok @: 3 Mouse @: 4 A driver has no information on the topology of the physical network IP phone @: 5 HID Driver Logical link n @: 3 Root Hub @: 1 HOST n Dok Keyboard @: 6 Each device sees all traffic generated by the host A device does not see data sent by another peripheral 5
USB Tutorial USB transfer A device has several endpoints Each endpoint is assigned to a logical pipe with the host Each pipe is characterized by: n n n - Device address - Endpoint number - Transfer type SOF @5 EP 0 @6 EP 1 @6 EP 2 A 1 ms USB Frame Transfer type: n n n Control: configuration/command/status type communication Bulk: large amounts of data at highly variable times Isochronous: constant-rate, error tolerant transfers Interrupt: send or receive data infrequently but with bounded service periods 6
USB Tutorial USB pipes n n n Device address is affected by the host Endpoint configuration depends on the device implementation Time multiplexing of transfer is under host control Control Transfer Bulk IN Transfer Bulk OUT Transfer Control Transfer Interrupt IN Transfer Host Control Transfer Iso IN Transfer Iso OUT Transfer Control Transfer Interrupt IN Transfer Device Address 3 Ep 0 Disk On Key Ep 1 Ep 2 Device Address 4 Ep 0 Mouse Ep 3 Device Address 5 Ep 0 IP Phone Ep 1 Ep 2 Device Address 2 Ep 0 Ep 1 Hub Logical Pipe 7
USB Tutorial Example of USB controller 8
USB Tutorial USB transactions n n A transfer is composed of one or several transactions Example of control transfer (several transactions) Setup Stage Data Stage Status Stage n Example of bulk transfer (one transaction) 9
USB Tutorial USB Transactions (1) n A transaction is made of 3 packets - Token: device address, endpoint number, transfer type - Data : data to be sent Token Data Transfer - Handshake: acknowledge n Handshake Example of bulk transaction: 10
USB Tutorial USB Transactions (2) n Example of bulk OUT transaction: Token Data Transfer Handshake Endpoint Address Device Address PID Host Token Data Device Handshake 11
USB Tutorial Summary n n n The host affects an address to the device The device has several endpoints To each endpoint corresponds a pipe and a type of transfer Transfer is made of one or several transactions Transactions are composed of 3 packets Transfer Device • Device address Offers Pipe/Endpoint • Endpoint number • Endpoint type Handles Control 2+ Bulk Iso 1+ 1+ Int 1+ Transaction Token pkt Data pkt Handshake pkt 12
USB Tutorial Control transfer The device is not ready… The device does not acknowledge the transaction The host retries… The device has Acknowledged the transaction 13
USB Tutorial USB scheduling(1) n n n SOF USB transfers occurs in a millisecond time-frame window The host sends a Start Of Frame (SOF) Packet at the beginning of each frame This is the host which starts a transfer with a logical peripheral Transactions are time multiplexed in one or several frames This is the host which do the transaction arbitration @5 @3 @6 SOF @5 @6 @6 SOF @5 @2 SOF Time A 1 ms USB Frame -Host handles most of the protocol complexity -Peripheral design is simple and low-cost 14
USB Tutorial USB scheduling (2) n n The bus allocation depends on the host controller A constant interval width is allocated to isochronous and interrupt transfer A minimum interval width is reserved for control transfer The rest of interval is for bulk transfer Valible width Control transfers Fixed width Iso + Interrupt transfer Variable width Bulk transfer -A host can refuse a new peripheral which requests large isochronous transfer size -Such peripheral offers several configurations 15
USB Tutorial Bandwidth n n Theorically up to 1216 bytes can be transferred through a bulk endpoint in a frame In practice ~950 bytes 1 ms frame 16
USB Tutorial Device detection n n The host (hub) downstream port integrates 2 pull-downs (15 Kohms). The bus state is SE 0 (DP = DM = 0 V) When a device is connected, the bus state is idle (DP = 3. 3 V DM = 0 V). DP is forced by the device pull-up (1. 5 Kohms). The hub/host detects the port status change and forces a bus reset to the new device (DP = 0 V DM = 0 V). Then the host sends requests to the device through the default control endpoint (endpoint number 0). A newly connected device address is 0. 3. 3 V HOST 15 Kohms 1. 5 Kohms DP DP DM DM Device 17
USB Tutorial Enumeration n Enumeration is the Process of Assigning Addresses and Setting Configurations Host Hub Status Change Query Change Port Enable Device Connect Cable Reset Device Get Device Descriptor via default Pipe and Address Assign a Unique Address Read all Configuration Information Attached Powered Default Addressed Configure and Assign Configuration Value Configured 18
USB Tutorial Enumeration trace Default Address, default control endpoint Enter Address State Enter Configured State 19
USB Tutorial USB Device State After 3 ms of bus inactivity the device must enter Suspended state and drain less than 500 u. A 20
USB Tutorial Standard requests n A setup transaction includes an 8 -byte formatted data packet n Standard requests are defined in Chapter 9 of the USB spec 21
USB Tutorial Host software architecture Linux and WIN CE provide ü OHCI/UHCI/EHCI HCD driver ü USBD Driver ü Main class drivers: Hub, HID, Mass storage, Printer, … • Symbian and RTOS does not provide USB host stack driver • SW IPs providers are able to provide solutions for RTOS üSoftconnex, Philog, … üExpensive: (65 k$ for a mass storage solution) • It is still possible to build a mini host from our full host: üthe SW is only able to drive some kinds of devices HID MS HUB Etc… USB Protocol Driver API Host Controller Driver (HCD) OHCI-UHCI-EHCI Host Controller regs 22
USB Tutorial Device USB driver components USB Device driver API Power Management Attach/ Status Control Protocol Endpoint Data Detach & • Standard Requests • Transfer Protocols Bulk In/Out Processing Control • Class Requests • Vendor Requests Clock Registers Pull-Up Resistor USB Controller Registers • Isochronous In/Out • Interrupt In/Out Endpoint FIFO Registers 23
USB Tutorial Device descriptor n n The USB Host stacks uses the descriptor retrieved from the device to find the corresponding driver. Windows looks for a matching Vendor ID/Product ID in its. inf library If not found, it will search for a matching class driver If not found then it will request the user to insert a CD to install the corresponding driver Device Descriptor Configuration Descriptor Interface Descriptor Endpoint Descriptor Endpoint Descriptor 24
USB Tutorial USB class drivers n n Building on top of the USB specifications, there are Device Class Specifications from the Device Working Group Matching device class requirements allow use of standard host class drivers provided by Windows or Linux Each class driver specifies the endpoint configurations required Existing class drivers: - Audio class (speakers, …) HID (keyboard, mouse, …) Mass Storage (disk on key) Printer class Smart Card CCID Communication Data Class … 25
USB Tutorial Objectives n n Review USB functionalities Be able to read a USB trace Understand the enumeration process Highlight that class drivers are part of the USB success 26
USB Tutorial What is happening? Transaction NACKed by the device 27
USB Tutorial What is the physical topology? How many device connected? Which device answers? Where is connected the bus analyser? 28
USB Tutorial Answer Bus Analyzer New Device Downstream Ports Upstream Port HUB Device Nb 3 Device Nb 2 USB Wire The bus analyzer logs all downstream packets from the host and only upstream packets from the new device 29
- Slides: 29