Sunteți pe pagina 1din 22

What is a USB?

The Universal Serial Bus was invented and standardized by a group of computer and
peripherals manufactures in 1995.
The idea was to tae the whole area of serial port and serial bus and update it with the
twenty!first century technology.
"t is true that there were many standards of communication between host computers and
peripherals# but the goal was to create a technology that combines low speed and high
speed bus activity. The technology enables shared access for both speeds# a technology
which provides robust protocol# automatic configuring of devices and a serial bus which
is simplified and easy to plug into. $ll those re%uirements were met with the USB
standards.
The USB has become a very popular e&pansion to the personal computer. "t is important
to remember the USB isn't a serial port it is a serial bus# a fact that enables a single port
on the computer to be a lin for a myriad of devices# (up to 1)* devices in a USB
system+. ,e can easily chain one device to another and use one port as a connecting
point of many devices by using a hub. $ll these enables us to loo at the USB system as a
small networ of devices.
The plug and play capability of the USB is one of its advantages over other serial buses.
This capability enables automatic detection of a new device# which is attached into the
system# an automatic configuration of it by the host# and an automatic detection of it-s
detachment from the system. The fle&ible attachment and detachment of devices to and
from the system allows mobility on the bus and ad.ustment of the system to new devices
without the need of restart the whole system each time a new device is detected.
$nother important aspect of the USB is it-s mid and high speed fle&ibility. This feature
refers to the ability of the USB to support simultaneously medium!speed devices# (which
wor in 1.5/bps+# and high!speed devices# (which wor in 1)/bps+.
The simultaneously wor of the USB system finds e&pression also in the dual support in
both isochronous and asynchronous bandwidth allocation methods. "sochronous means
that the necessary bandwidth is guaranteed# whenever the device re%uires it ' it will be
available. $synchronous on the other hand means that there is no guarantee ' the data
will be sent whenever it will be possible to send it. 0evices# such as video and audio
multimedia# that use stream transfer# will use the isochronous method while devices that
use bul transfer# such as printers and scanners will use the asynchronous method.
The USB is robust. Through all the different protocol layers there is an error detection
and recovery mechanism# which guarantees low error rate. The USB provides detection
of faulty devices and flow control mechanism# which is built in the protocol.

A typical USB system


A typical USB system consists of:
1ne host ' there is only one host in the USB system# which is responsible to the whole
comple&ity of the protocol (simplifies the designing of USB devices+. The host
controls the media access ' no one can access the bus unless it got an approval re%uired
from the host.
2ub ' lie the hubs used for computer networ. The hub provides an interconnect
point# which enables many devices to connect to a single USB port. The logical
topology of the USB is a star structure# all the devices are connected (logically+
directly to the host. "t is totally transparent to the device what is its- hub tier (the
number of hubs the data has to flow through+. The hub is connected to the USB host in
the upstream direction (data flows 'up' to the host+ and is connected to the USB device
in the downstream direction (data flows 'down' from the host to the device+. The hubs-
main functionality is the responsibility of detecting an attachment and detachment of
devices# handling the power management for devices that are bus!powered (get power
from the bus+# and responsibility for bus error detection and recovery. $nother
important role of the hub is to manage both full and low speed devices. ,hen a device
is attached to the system the hub detects the speed# which the device operates in# and
through the whole communication on the bus prevents from full speed traffic to reach
low seed device and vice versa ' prevent from low speed traffic to reach full speed
device.
0evice ' everything in the USB system# which is not a host# is a device (including
hubs+. $ device provides one or more USB functions. /ost of the devices provide only
one function but there may be some# which provides more than one and called
compound devices. ,e refer to two inds of devices ! self powered or bus powered
devices. $ device that gets its power from the bus is called bus powered and on the
other hand a device which supplies its own power is called self powered. $s was
mentioned before there are two inds of devices3
4ull!speed devices ! operates in 1)/bps
5ow!speed devices that wor in 1.5/bpsec.

USB Communication Layers
4ollowing the USB communication layers model as shown in the specifications3



USB communication flow
The logic communication between the client software on the host and the function on the
device is done through pipes. $ pipe is the association between a specific endpoint on the
device and the appropriate software in the host. $n endpoint is the source or destination
of the data that transmitted on the USB cable. $n interface is composed of endpoints
grouped together into a certain set. The client software whishes to transmit data between
the buffers in the host and the endpoints in the device and by that manages the specific
interface (which is associated with specific endpoints+. '
6ommunication flow on the bus can be done is two directions3
1UT ! data flows from the host to the device.
"7 ! data flows from the device into the host.

I. The Physical Layer
Signaling on the us
The physical layer is the physical interface to the USB cable. The main responsibility of
the physical layer is to transmit '8' as '8' and '1' as '1' and to receive '8' as '8' and '
1' as '1'.
The USB cable is 9 wire cable# signaling on the bus is done by signaling over two wires
(differential pair+. There is a 0
:
wire and a 0
!
wire# in a way that if we want to transmit '
8' over the bus we will eep 0
:
low and 0
!
high and vice versa to transmit '1' we need to
eep 0
!
low and 0
:
high. The other two cables are ;bus (:5v+ and <70 ('5v+ to deliver
power to the device. Bits are send into the bus 5SB first.
There are few uni%ue types of signaling on the bus# which are identified as special cases3
=eset signaling3 The host can reset the device. This is done by signaling S>8 (single
ended zero ! 0
:
and0
!
are ept low+ for more than ).5'sec. ,henever the device
recognizes such a signaling on its upstream port of the bus it treats it as a =>ST signal.
Suspend signaling3 the host can enter the device into a suspend mode# in which the
device won-t respond to the USB traffic. $ device will begin the transition to a suspend
mode whenever it will recognize an idle state on the bus for more than ?msec# the
device will actually be suspended no more than 18msec bus inactivity. =ecognizing
signaling on its upstream ports will tae the device out from the suspend mode.
=esume signaling3 $ device# which in suspended state# will resume its operation
whenever it will recognize a @ signaling (differential A8A for full speed devices and
differential A1A for low speed devices+ on the bus. ,henever the host wishes to waeup
the device it sends =>SU/> signaling for at least )8msec. $ device can also waeup
itself ! we call that feature Aremote waeup capabilityA# which allows the devices#
which in suspend mode# start sending @ signaling on the bus and resume its own
activity.
>1B signaling3 >1B is transmitted as S>8 for ) bit times (defined differently for low!
speedC high!speed devices+ followed by D signaling(differential A1A for full!speed
devices and A8A for low!speed devices+ for 1 bit time.
0ata encoding and decoding is done using 7=E" method. "n 7=E" coding if we want to
transmit '1' we don't change the level of the signaling (if the differential pair
represented logic '1'# it will remain in this level also for the ne&t cloc+# on the other
hand if we want to transmit '8' we will flip the value of the differential pair. (There will
be toggle in the level in a way that if the current value represented is differential '1' the
ne&t value will be differential '8'+.
1ne of the affects of the data encoding represented above# is that sending a string of ones
will cause a continuous mode of transmission (the transmission lines will stay static '
with no change for that period+. "n order to prevent such a continuous state# bit staffing is
performed before the 7=E" decoding. The bit staffing is made by inserting a zero after
si& successor ones. "n the decoder that zero is recognized as part of the bit stuffing and is
ignored.

SI! " Serial Interface !ngine
The S"> is part of both the host-s and the device-s physical layer. 0ata is transmitted on
the bus as a serial bit stream. The S"> is responsible for the serialization and
deserialization (converting the data stream to a parallel one+ of the USB transmissions.
"ncoming data stream is 7=E" and bit stuff decoded# the outgoing traffic is 7=E" and bit
stuff encoded# the S"> is responsible for those operations of decoding and encoding. The
S"> is also responsible for generating 6=6 for the outgoing data and verify 6=6 for the
incoming stream. The S"> also detect the B"0 (pacet-s id+ as well as S1B# >1B# =>S>T
and =>SU/> signaling on the bus.

#C " #ost Controller
The host is the AsmartestA element in the USB system and plays a uni%ue role in the
system. The host initiates all the transactions# controls the media access and is the main
engine for the protocol-s flow# as we will se later on. That is why the host controller# an
additional hardware# is re%uired to ensure that everything# which is transmitted on the
bus# is correct and within the specifications.
The host controller serves both the USB and the host and has the same functionality in
every USB system.
4ollowing some of the 26 functions3
4rame generation3 The host controller is responsible to partition the USB time into
time units# in a way that each time unit is 1msec and is called a AframeA. The host
controller issues# periodically# S14 (Start 1f 4rame+ pacet every 1msec (after the
transmission of the S14 the 26 can transmit any other transaction for the rest of the
frame period+. The S14 contains the current frame number# which is maintained by the
26.
0ata Brocessing3 The 26 handles the re%uests for data to and from the host.F
Brotocol >ngine3 2andling the USB protocol level interface.
>rror handling3' The 26 handles errors such as3
Timeout ! the function in the device is not responding
6=6 error
Une&pected data payload
=emote waeup3 The 26 is able to enter the USB into a suspend state# and to detect a
remote waeup signaling on the bus.

II. The Protocol !ngine Layer
The middle layer in the communication layers model has an important role. The layer is
responsible for the translating the data between the application layer (client software on
the host and function on the device+ and the USB transactions protocol. The layer wraps
and unwraps the data according to the protocol.
The layer is referred differently in the USB host (is called the AUSB system softwareA
layer+ and in the USB device (is called AUSB logical deviceA layer+# which is %uite
reasonable due to the different roles the two components perform in the system.
'
The USB System SW
Beside the responsibilities described above# the USB system is also responsible for the
bandwidth allocation and bus power management in order to enable devices to access the
bus.
The USB System S, is composed of the host software and two additional software
interfaces3
The 2ost 6ontroller 0river (260+3 is an interface to the host controller. The purpose
of using such aninterface is to mae it transparent for the host software which host
controller the device is connected to.
The USB driver (USB0+3 The client software (the top layer of the host
communications layer+ re%uest data from the USB0 in a form of "=Bs ("C1 =e%uest
Bacets+ which consist of a re%uest to sendC receive data through a certain pipe. The
USB0 handle those re%uests. $nother important role of the USB0 is to supply the
client software a general description of the device which the software is about to
handle. The USB0 is re%uired to handle the enumeration process (a process which is
activated the moment the device is attached to the bus and in the end of it the device is
fully configured# is a part of the USB system and can response to the traffic on the
bus+# investigate the different configurations of the device and supply this nowledge
to the client software. $s a part of this role the USB0 owns the default pipe# since
when a device .ust enters the system# the only way to communicate with it is through
the default pipe.

The USB Logical $e%ice
The USB logical device is composed of a collection of independent endpoints. >ach
endpoint is given a uni%ue address (endpoint number+ at the design time# the USB logical
device is also uni%uely addressed at the end of the enumeration process. $n endpoint is
unidirectional (e&cept from endpoint number zero+# it may be "7 type (supports data
transfer from the device to the host+ or 1UT type (supports data transfer from the host to
the device+# this means that for bi!directional flow we need two endpoints each for a
different direction. The combination of the USB logical device address# the endpoint
number and the direction of the endpoint define uni%uely a certain endpoint. $n endpoint
is characterized with a transfer type. $s we will see later on# there are four types of
transfers on the USB# each endpoint is associated with only one transfer type# and by that
characterized with its bandwidth allocation re%uirements.
$ll USB devices must support communication through the default pipe. The default pipe
plays an important role in the enumeration process# and is the only communication
channel to the device at attachment. The default pipe is associated with endpoint number
zero (that is why endpoint number zero must be included as part of the device and must
be of a control type+. >ndpoint number zero is and composed of two endpoints (one "7
and one 1UT+ that share the same endpoint number and are referred as one.'
5ow speed devices can support two additional endpoints (beside endpoint number zero+
which may be control or interrupt type. 4ull speed devices# on the other hand# can support
up to ma&imum of 15 additional "7 endpoints and 15 additional 1UT endpoints. The
additional endpoints can be used only after the devices has been fully configured.


III. The Application Layer
The application layer appears as the client software in the host and as the function in the
device. The function in the device is composed of collection of interfaces and controls the
functionality of the device. The client software manages the appropriate interface by
transferring data from its buffers to the endpoints associated with the appropriate
interfaces. The client software wors with a specific device function# independent of the
other device functions in the system.'

The USB Protocol
The USB host handles most of the comple&ity of the USB protocol# which maes the
peripherals design simple and low cost. 0ata flow can be from host to device and from
device to host.
USB transactions are done through pacets. >ach transaction is composed usually from
three phases3
Toen phase ! the host initiates toen indicating the future transaction type.
0ata phase ! the actual data is transmitted through pacet. The data direction matches
the direction indicated by the toen that was transmitted previously.
2andshae phase ! (optional+ ! handshae pacet is sent# indicating the success or
failure of the transaction.
The USB uses a polling protocol. ,henever the host whishes to receive data from the
device it issues a toen (a pacet types that we will discuss later+ addressed to that
specific device. "f the device has data to send it sends it after receiving the toen and the
host (if the handshae phase is included on the transfer+ will respond with handshae
pacet. "t the device doesn-t have anything to send the host issues the toen to the ne&t
device. "f# on the other hand# the host whishes to send data to the device# it will send the
appropriate toen and data pacet following it. The device will response by a handshae
pacet (if handshae phase is included+. 1nce again# the moment the host finishes
transmitting data to that device# it issues a new toen to the ne&t one.
,hen we tal about the USB protocol# we can-t ignore its robustness. The protocol
includes handshae mechanism# timeout rules (to prevent deadloc in the system+# low
control mechanism and very low physical bit error rate (G 18
!18
+. >ach pacet transmitted
on the bus includes chec bits and 6=6 protection.
There are four main USB transfer types3
Isochronous transfer 3 "sochronous transfer# as was mentioned previously# is used for
multimedia devices such as audio# video# etc. "mportant characteristic of the transfer is
that bandwidth is guaranteed ! the re%uired bandwidth is reserved for the devices uses
this transfer type. "n isochronous transfers there is less attention to the success of the
transfer (whether or not the whole data arrived on time+ since the traffic included in
this transfer type has a high tolerance for errors.
Bul& transfer' Bul transfer is consisted of massive amount of data and is used by
devices re%uires it such as printers# scanners# etc. The bandwidth allocated in each
transaction of the transfer varies according to the bus resources at the time. Bul
transfers are done in reliable mode ! there is great deal of awareness to errors.'
Interrupt transfer' "nterrupt transfer is a limited!latency transfer and used for devices
such as mouse# .oystic that needs to report short event notification# characters or
coordinates. $ USB device that wors in an interrupt transfer mode defines# as part of
its configuration# the time interval it wants to send or receive information. The host is
responsible to turn to device at that specific rate# and then the device is allowed to send
or receive the necessary data.'
Control transfer' 6ontrol transfers are used to configure a device. The configuration
is done at the enumeration process but can be done also at any state of the
communication process. ,hen a device enters the system the host needs to learn about
it and configure it at the appropriate configuration# all this communication is done
using the control transfers. 6ontrol transfer can also includes special messages defined
by the vendor.
5ow!speed devices support control and interrupt transfers while full!speed devices
support all of the above transfers.

Pac&et (iel) (ormats
Before learning the different types of pacets used by the protocol# let us view the
different fields in the pacets3

S*+C (iel)
The SH76 field appears at the start of each pacet. "t appears on the bus as idle followed
by A@D@D@D@@A (encoded in 7=E" encoding+.' The SHS6 (synchronization+ field
allows the receiving peripheral synchronize its internal cloc to the incoming data. The
following pacets description will ignore this field (for simplicity+ but we mustn-t forget
its e&istence.
PI$ " Pac&et I)entifier (iel)
The B"0 field contains the identity of the pacet# Since there are many types of pacets
we need to indicate at the start of the pacet# which pacet it is. The B"0 field is
composed of eight bits as is shown in the following diagram. The first four bits are used
to notify the actual id of the pacet# and the ne&t four are used as chec bits (are one-s
complements of the first four bits+ and used for error detecting.

The B"0 types are divided to three main groups3
Toens3 Toen pacets can be 1UT# "7# S14 and S>TUB.
? 1UT toen indicates that the following data will be transmitted from the host
to the device.
? "7 toen indicates that the following data will be transmitted from device to
host.
? S14 toen indicates start of frame.
? S>TUB toen indicates that the following pacet will be sent from host to
device and will contain setup command (used for configuration+.
0ata3 0ata B"0 appears in data pacets. 0ata B"0 can be either
0$T$8C0$T$1# the different B"0 is used for data toggle synchronization.
2andshae3 2andshae B"0 is used is handshae pacets# in order to indicate
the success C failure of the transfer. 2andshae B"0 can be either $6@#
7$@# ST$55.
? $6@3 The receiver received error free pacet.
? 7$@3 The receiver is unable to receive the data (for e&ample due to overflow
problem+# or the sender is unable to send data (underflow problem for
e&ample+.
? ST$553 The specific endpoint is halted or the specific S>TUB command is not
supported.

A))ress (iel)
The address field is divided into two fields3
$ddress field ($00=+3 This field contains the actual address of the function (normally
the device itself+# assigned to it at the enumeration process. >ach function in the system
has its uni%ue address and there can be up to 1)* different addresses in the system
(address zero is reserved and is used as an initial address of a function# it is not allowed
to use address zero as a permanent address+.

>ndpoint 4ield (>70B+3 The endpoint number field contains the number of the
endpoint referred. >ach endpoint in a specific function is identified uni%uely with an
endpoint number. "n low!speed device there can be two additional endpoints (beside
endpoint number zero+ and for full!device there can be up to 1I endpoint at any type
(including endpoint number zero+. The endpoint field is used in 1UT# "7 and S>TUB
toens.

(ame +umer (iel)
The frame number field is composed of 11 bits indicating the number of the current
frame. The filed is contained only in S14 toen indicating the start of the frame.
$ata (iel)
The data field contains the data transmitted in the transaction. The data field can contain
up to 18)? bytes.

C,C fiel)
The 6=6 (cyclic redundancy chec+ field is uses to protect all the fields in a toen pacet
(e&cept of B"0 field+ and to protect the data in the data pacets. The 6=6 field in a toen
pacet is composed of 5 bits while in data pacets is composed of 1I bits.

Pac&et (ormats
5et us view the different pacets format3

To&en Pac&et
$s was mentioned before# each transaction begins by issuing a toen by the host. The
$00= and >70B field uni%uely defines the endpoint that is about to receive the
following data pacet in S>TUB or 1UT transactions# and on the other hand specifies the
endpoint that is about to send data in "7 transactions.'


Start -f (rame Pac&et
The host issues a S14 pacet every 1msec'8.8885msec. the pacet contains the frame
number field which indicated the number of the current frame. S14 toen can be used as
a trigger to process isochronous 1UT endpoints.

$ata Pac&ets
0ata pacets are composed of B"0 (indicating that the pacet is a data pacet+# data field#
which contains the actual data to be transmitted and 6=61I to protect the data field.



#an)sha&e Pac&ets
2andshae pacets are composed only of B"0 indicating the results of the previous stage.
$6@# which indicates that the pacet was received with no 6=6 or bit stuff errors# can
be used at the handshae phase of a S>TUB# 1UT transfers (sent by the device+ or in "7
transfer (sent by the host+.
7$@# which is used for flow control# can be sent in the handshae phase of 1UT or "7
transfers.
ST$55# which indicates some problem in the transfer (endpoint halted or control
command not supported+# is not allowed to be used by the host.


Transaction (ormat
Control Transfer
$ control transfer is composed of three or two phases3 setup# data (optional+ and status#
each of those phases is composed of three phases (toen# data# handshae+.
The setup stage role is to indicate the device which setup command the host whishes to
send. There are many inds of S>TUB commands such as3
S>TJ$00=>SS 3 setting a permanent address to a function.
<>TJ0>;"6>J0>S6="BT1=3 the host whishes to get the device descriptor# which
contains details concerning the device ! how many configurations# interfaces it has# is
the device is selfC bus powered etc.
<>TJ6174"<U=$T"17J0>S6="BT1=3 the host whishes to learn about a specific
configuration of a device.
<>TJ6174"<U=$T"173 the host detects which configuration is active at the
moment in the device.
S>TJ6174"<U=$T"173 the host sets a specific configuration on the device.
$t the beginning of a setup stage the host issues a S>TUB toen# followed by the setup
command pacet# The device must response with an $6@ pacet.
The data stage (if included+ contains the flow of the data# which direction (from host to
device of from device to host+ indicated in the setup stage. The data stage is composed of
one or more "7 or 1UT transactions (all the transactions in the data stage must be in the
same direction ! all "7 or all 1UT+. >ach transaction in the data stage begins with
"7C1UT toen issued by the host# afterwards data is sent (in the appropriate direction+
and the transaction ended with a handshae pacet.
The status stage reports the host the results of the previous stages3 setup and data stages.
The report is always from the device to the host. "mportant characteristic of this stage is
that the data flow direction in it is opposite to the one in the data stage (if there wasn-t
data stage the direction will be "7+.
"f the direction of the status stage is "7 then the report is done in the data phase of the
transaction# if it is 1UT then the report is done in the handshae phase.

>&ample of 6ontrol transfer3 (<etJ0eviceJ0escriptor as S>TUB command+



Bul& Transfer
Bul transfers are composed of one or more three phases transactions.
>ach transaction starts with a toen sent from the host indicating the direction of the data
transfer in the following phase. "n the ne&t phase# data is transmitted according to the
direction indicated by the toen. "f there was no detection of data error while receiving
the data# the last phase is the handshae phase# in which a report concerning the success
of the transaction is being sent. "f error was detected no handshae pacet is sent.
There are two inds of bul transfers3
"7 transfer ! in which the host ass for data from the device ! data flow direction is
from the device into the host.
1UT transfer ! in which the host whishes to send data to the device ! data flows from
the host out to the device.
,henever the host whishes to receive data from the device# it initiates an "7 toen and
sends it to the device# when the device receives the toen# it sends data as response to the
toen and the host responds with an $6@ pacet if the data was received error free and
doesn-t send any handshae in case of error detection. "n case the device can-t send the
re%uired data (underflow ! data needs to be sent but the transmit 4"41 is empty# or any
other function problem+# the device won-t responds with a data pacet but with 7$@ or
ST$55 indicating its inability to answers the host demands. This situation results two
phase transaction.
"f# on the other hand# the host wishes to send data to the device# it initiates an 1UT toen
and sends# in the ne&t stage# the data it wished to send. The device# after receiving the
data response with a handshae pacet.
There are three inds of handshae responds by the device3 $6@ indicates that data was
received without any errors# and was accepted by the device. 7$@ indicates that data was
received error free# but could not be accepted by the device# due to temporary problem in
the device (overflow# underflow# etc.+# the host should retry the transmission. ST$55
indicates that the device could not accept the data due to error condition on the function#
the host should not retransmit the data.
Bul transfers are highly reliable due to the handshae and timeout (which was
mentioned earlier+ mechanisms. "f there is any problem in the USB system# the host will
detect it and prevent deadlocs in the system.

>&ample of Bul 1UT transfer3


>&ample of Bul "7 transfer3




Interrupt Transfer
"nterrupt transfers are very similar to bul transfers. $s in bul transfers data can be sent
from host to device and from device to host.
"f the host wishes to now which interrupt is pending on the device# it initiates an "7
toen to the appropriate endpoint. "f there is a pending interrupt# the function will send
details concerning the interrupt# as a data pacet in the following stage. "f the information
was received error free by the host# it will initiate an $6@ pacet in the handshae phase.
"n case of error detection no handshae will be transmitted.
"f# on the other hand# the host has initiated an "7 pacet but there are no pending
interrupts and the endpoint has no information to send# the function will return a 7$@
pacet. "n case of an error condition in the function a ST$55 pacet will be sent.
The host will initiate an 1UT toen in case it wishes to transmit data to the device (data
to serve the interrupt for e&ample+# following the toen a data pacet will be sent. The
device# upon receiving the data# detects for errors# if the data is error free the device will
response with $6@# 7$@ or ST$55 (as in bul transfer+. "f the data was corrupted no
handshae will be sent.

>&ample of "nterrupt transfer3




Isochronous Transfer
"sochronous transfers are composed of one or more two phases transactions. $s was
mentioned earlier# there is no handshae phase in isochronous transfers. The host initiates
either an "7 toen# in order to receive data from the device# or an 1UT toen to send
data. "n the ne&t stage data is transmitted in the direction indicated by the toen which
was sent before.
>&ample of "S1 transfers3



,eference
USB >&plained by Steven /c0owell K /artin 0.Seyer 1999.
Universal Serial Bus Specification =evision 1.1 Sep 199L (6ompac# "ntel# /icrosoft#
7>6+
4or more details you can refer to USB "mplementers 4orum web page at3
http3CCwww.usb.org

S-ar putea să vă placă și