You are on page 1of 29

1

USB TutoriaI
2
USB TutoriaI
Objectives
#eview USB functionaIities
Be abIe to read a USB trace
Understand the enumeration process
HighIight that cIass drivers are part of the USB success
3
USB TutoriaI
Few generaIities on USB
Tiered start topoIogy
2 types of peripheraIs:
- HUB
- Function
- Up to 127 peripherals
master/sIave architecture
USB 2.0 spec supercedes USB 1.1 spec
- USB 2.0 LS ( USB1.1 at 1.5Mbps)
- USB 2.0 FS ( USB 1.1 at 12Mbps)
- USB 2.0 HS (480 Mbps)
!ower Management
- Different device class: bus powered or self powered
- Vbus > 4.35V. 100mA, (500mA after negociation),
500uA in suspend mode
- Host disables power to ill-behaved peripherals
Host
HUB
HUB
Root Hub
Keyboard
Speaker
Disk
Printer
4
USB TutoriaI
The Transaction !rotocoI is Host Based
Host based token poIIing
- Data from host-to-function and function-to-host
- Host handles most of the protocol complexity
- Peripheral design is simple and low-cost
#obustness
- 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
o asynchronous message/interrupt from the peripheraI
5
USB TutoriaI
USB TopoIogy
unique device address is assigned to each USB device
!hysicaI tiered start network:
LogicaI network:
Each device sees aII traffic generated by the host
device does not see data sent by another peripheraI
HOST
#oot Hub @: 1
Hub @: 2
Dok @: 3
Mouse @: 4
I! phone @: 5
Logical link
HOST
Hub @: 2
Dok @: 3
Mouse @: 4
I! phone @: 5
#oot Hub
@: 1
USB cable
Keyboard @: 6
Keyboard @: 6
HD Driver
MSD Driver
HUB Driver
Audio Driver
A driver has no
information on the
topology of the
physical network

USB TutoriaI
USB transfer
device has severaI endpoints
Each endpoint is assigned to a IogicaI pipe with the host
Each pipe is characterized by:
- Device address
- Endpoint number
- Transfer type
Transfer type:
ControI: configuration/command/status type communication
BuIk: Iarge amounts of data at highIy variabIe times
Isochronous: constant-rate, error toIerant transfers
Interrupt: send or receive data infrequentIy but with bounded service periods
Type Direction Packets per frame Max Packet Size
ControI Bidir Several 4 Bytes
BuIk Unidir Several 4 Bytes
Isochronous Unidir One 1024 Bytes
Interrupt Unidir One max 4 Bytes
1ms USB Frame
SOF @EP1 @5EP0 @EP2
7
USB TutoriaI
USB pipes
Device address is affected by the host
Endpoint configuration depends on the device impIementation
Time muItipIexing of transfer is under host controI
:-
Mo:se
Disk On Key
Control Transfer
Bulk N Transfer
Bulk OUT Transfer
Ep0
Ep1
Ep2
Device ddress 3
Control Transfer
so N Transfer
so OUT Transfer
Control Transfer
nterrupt N Transfer
Ep0
Ep3
Device ddress 4
IP Phone
Ep0
Ep1
Ep2
Device ddress 5
Device ddress 2
ost
Ep0
Ep1
Control Transfer
nterrupt N Transfer
Logical Pipe
8
USB TutoriaI
ExampIe of USB controIIer

USB TutoriaI
USB transactions
transfer is composed of one or severaI transactions
ExampIe of controI transfer (severaI transactions)
ExampIe of buIk transfer (one transaction)
Setup Stage
Data Stage
Status Stage
10
USB TutoriaI
USB Transactions (1)
transaction is made of 3 packets
- Token: device address, endpoint number, transfer type
- Data : data to be sent
- Handshake: acknowledge
ExampIe of buIk transaction:
Token Data Transfer Handshake
11
USB TutoriaI
USB Transactions (2)
ExampIe of buIk OUT transaction:
Device ddress
Endpoint ddress
Host
Device
!ID
Token
Data
Handshake
Token Data Transfer Handshake
12
USB TutoriaI
Summary
The host affects an address to the device
The device has severaI endpoints
To each endpoint corresponds a pipe and a type of transfer
Transfer is made of one or severaI transactions
Transactions are composed of 3 packets
!ipe/Endpoint
WEndpoint number
WEndpoint type
Device
WDevice address
ffers
Transfer
ControI BuIk Iso Int
2+ 1+ 1+ 1+
Transaction
%oken pkt
Data pkt
Handshake pkt
Handles
13
USB TutoriaI
ControI transfer
The device is not ready.
The device does not
acknowIedge the transaction
The host retries.
The device has
cknowIedged the transaction
14
USB TutoriaI
USB scheduIing(1)
USB transfers occurs in a miIIisecond time-frame window
The host sends a Start Of Frame (SOF) !acket at the beginning of
each frame
This is the host which starts a transfer with a IogicaI peripheraI
Transactions are time muItipIexed in one or severaI frames
This is the host which do the transaction arbitration
Time
1ms USB Frame
SOF SOF SOF SOF @3 @5 @5 @5 @ @ @ @2
-Host handles most of the protocol complexity
-Peripheral design is simple and low-cost
15
USB TutoriaI
USB scheduIing (2)
The bus aIIocation depends on the host controIIer
constant intervaI width is aIIocated to isochronous and interrupt
transfer
minimum intervaI width is reserved for controI transfer
The rest of intervaI is for buIk transfer
ontrol
transfers
Iso + Interrupt transfer
Bulk transfer
Fixed width
Variable width
Valible width
-A host can refuse a new peripheral which requests
large isochronous transfer size
-Such peripheral offers several configurations
1
USB TutoriaI
TheoricaIIy up to 1216 bytes can be transferred through a buIk
endpoint in a frame
In practice ~950 bytes
Bandwidth
1ms frame
17
USB TutoriaI
Device detection
The host (hub) downstream port integrates 2 puII-downs
(15Kohms). The bus state is SE0 (D! = DM = 0V)
When a device is connected, the bus state is idIe (D! = 3.3V DM =
0V). D! is forced by the device puII-up (1.5Kohms).
The hub/host detects the port status change and forces a bus
reset to the new device (D! = 0V DM = 0V).
Then the host sends requests to the device through the defauIt
controI endpoint (endpoint number 0). newIy connected device
address is 0.
DM
DP
Kohms
Kohms
3.3V
Kohms
DP
DM
OST
Device
18
USB TutoriaI
Enumeration
Host Hub Device
ttached
!owered
DefauIt
ddressed
Configured
Connect Cable
Status Change
Query Change
Port Enable
Reset Device
Get Device Descriptor via default Pipe and Address
Assign a Unique Address
Read all Configuration nformation
Configure and Assign Configuration Value
Enumeration is the !rocess of ssigning ddresses and Setting
Configurations
1
USB TutoriaI
Enumeration trace
Defa:t Address, defa:t contro endpoint
Enter Address State
Enter Config:red State
20
USB TutoriaI
USB Device State
After 3ms of -:s inactivity
the device m:st enter
S:spended state and drain ess
than 500:A
21
USB TutoriaI
Standard requests
setup transaction incIudes an 8-byte formatted data packet
Standard requests are defined in Chapter 9 of the USB spec
22
USB TutoriaI
Host software architecture
Host
Controller
regs
Host Controller Driver (HCD)
OHCI-UHCI-EHCI
USB Protocol Driver API
MS HUB Etc. HID
Linux and WI CE provide
OHC/UHC/EHC HCD driver
USBD Driver
Main class drivers: Hub, HD, Mass storage, Printer, .
W Symbian and #TOS does not
provide USB host stack driver
WSW I!s providers are abIe to
provide soIutions for #TOS
Softconnex, Philog, .
Expensive: (5k$ for a mass
storage solution)
WIt is stiII possibIe to buiId a mini
host from our fuII host:
the SW is only able to drive
some kinds of devices
23
USB TutoriaI
Device USB driver components
USB Device driver !I
!ower
Management
ttach/
Detach
!rocessing
Status
&
ControI
ControI !rotocoI
WStandard #equests
WCIass #equests
WVendor #equests
Endpoint Data
WTransfer !rotocoIs
BuIk In/Out
WIsochronous In/Out
WInterrupt In/Out
!uII-Up
#esistor
CIock
#egisters
USB ControIIer
#egisters
Endpoint FIFO
#egisters
24
USB TutoriaI
Device descriptor
The USB Host stacks uses the descriptor retrieved from the
device to find the corresponding driver.
Windows Iooks for a matching Vendor ID/!roduct ID in its .inf
Iibrary
If not found, it wiII search for a matching cIass driver
If not found then it wiII request the user to insert a CD to instaII
the corresponding driver
Device Descriptor
Configuration Descriptor
Configuration Descriptor
nterface Descriptor nterface Descriptor nterface Descriptor
Endpoint
Descriptor
Endpoint
Descriptor
Endpoint
Descriptor
Endpoint
Descriptor
Endpoint
Descriptor
Endpoint
Descriptor
25
USB TutoriaI
USB cIass drivers
BuiIding on top of the USB specifications, there are Device CIass
Specifications from the Device Working Group
Matching device cIass requirements aIIow use of standard host
cIass drivers provided by Windows or Linux
Each cIass driver specifies the endpoint configurations required
Existing cIass drivers:
- Audio class (speakers, .)
- HD (keyboard, mouse, .)
- Mass Storage (disk on key)
- Printer class
- Smart Card CCD
- Communication Data Class
- .
2
USB TutoriaI
Objectives
#eview USB functionaIities
Be abIe to read a USB trace
Understand the enumeration process
HighIight that cIass drivers are part of the USB success
27
USB TutoriaI
What is happening?
Transaction NACKed -y the device
28
USB TutoriaI
What is the physicaI topoIogy?
How many device connected?
Which device answers?
Where is connected the bus anaIyser?
2
USB TutoriaI
nswer
HUB
Device b 3
Device b 2
ew Device
Bus naIyzer
&SB Wire
D
o
w
n
s
t
r
e
a
m

!
o
r
t
s
U
p
s
t
r
e
a
m

!
o
r
t
The bus analyzer logs all downstream packets from the host
and only upstream packets from the new device