1. USB
USB stands for Universal Serial Bus. It is a standard by which data and
power can be transmitted between computing devices. Originally created
as a connector for computer peripherals such as keyboards, mouse, and
external storage devices, charging portable devices like
wireless phones and tablets
It was developed by Compaq, Intel, Microsoft and NEC, joined later by
Hewlett-Packard, Lucent and Philips
The main goal behind usb implementation is to replace all the the
various connectors of communication protocols to unique connector that
can support all the data that can transmit with better speed
2. USB Speeds
• High Speed - 480Mbits/s
• Full Speed - 12Mbits/s
• Low Speed - 1.5Mbits/s
3. • Every transaction in USB consists of 3 packets
• Token Packet
• Data Packet
• Handshake Packet
4. Types of USB Packets
Token Packet:
there are 3 types of token packets
IN: if the PID field contains IN token it implies that host is ready to accept data from
device
OUT: if the PID field of token packet contains OUT packet it indicates that the host is
writing some data into the endpoint of device
SETUP: this token is used to begin the control transfer while sending standard requests
Data Packet:
there are 4 types of data packets used in this stage
Data0,Data1 is used during low/full speed mode
Data2,Mdata are used while high speed mode
during low speed 8bytes of data can be transferred
during full speed mode 1023 bytes that this data stage can transfer through
with high speed data mode maximum of 1024 bytes is allowed
in this stage total size of data is transmitted as multiples of chunks of buffer size
5. Hand Shake Packet: there are 3 possible handshake PIDs
ACK: Acknowledgment that the packet has been successfully received.
NAK: it results in negative acknowledgement while transaction
STALL: this is received when there is intervention from the host
6. This is the table for PID field where it can be identified which token it is
Various Fields in each transaction
7. Sync field: All packets must start with a sync field. The sync field is 8 bits long
at low and full speed or 32 bits long for high speed and is used to synchronise
the clock of the receiver with that of the transmitter.
PID field: It indicates what type of packet is being sent this PID field is 8 bits
long, the first 4 bits are used to represent the type of packet being sent and rest
4 bits are the compliment of first 4 bits , for error checking as it has NZRI
decoding technique
Address field: this field indicates the address of device to which it is
transmitting, it is 7-bit long so that it can support for maximum upto 127
devices and by default address 0 is is not used for configuring, it will be the
default address during enumeration until an unique address is set that that
device.
Endpoint: for a single device there might be possibility that having various
interfaces each having multiple endpoints, it is a 4-bit long so 16 possible
endpoints.
8. CRC: it is the error checking mechanism for the transmitted data it is 5 bits long
with token packet and 16-bit long with data packet .
EOP: this indicates the end of packet, in that particular transaction
NOTE: every USB transaction must start with sync field and end with EOP field
End Points: Each USB device has a number of endpoints. Each endpoint is a
source or sink of data. A device can have up to 16 OUT and 16 IN endpoints.
OUT always means from host to device.
IN always means from device to host.
Endpoint 0 is a special case used for controlling the device until an unique address
is assigned for it. All devices must support endpoint zero.
Each end point is having some buffer to which the host writes the data and the
hardware collects/writes data to this particular end point,
End points are lies at the device side only.
9. Pipe: A logical data connection between the host and a particular endpoint,
Pipes will also have a set of parameters associated with them such as
• how much bandwidth is allocated to it
• what transfer type (Control, Bulk, Iso or Interrupt) it uses
• direction of data flow (IN or OUT)and
• maximum packet/buffer sizes.
USB defines two types of Pipes
Stream Pipe: stream pipe is unidirectional and has no defined structure, Data
flows sequentially and has a pre-defined direction, either in or out. Stream pipes
will support bulk, isochronous and interrupt transfer types. Stream pipes can either
be controlled by the host or device.
Message Pipe:
• message pipe is bi-directional and has a defined structure
• message pipe will support only control transfer types
• Message pipe will be controlled by the host only
10. Data Flow Types: there are 4 types of data flow in USB, it can also be defined as
end point types
• Control Transfer type
• Interrupt Transfer Type
• Isochronous transfer type
• Bulk transfer type
Control Transfer Type: control transfer is mainly used for sending
commands/requests and status signals,
control transfer comes up with 3 stages
• Setup Stage: token packet of this stage will have a setup token in PID field
indicates to the device that it is a setup request and host is requesting for
something
11. • Setup token packet consist of these fields
this setup token is directed to the default endpoint of endpoint0 of that
device indicating that it is a setup request , it is fallowed by data packet
• Data Packet consist of these fields
Here the address and endpoint fields are not required as bus is connected to
the destination endpoint, this data0 contains the request to the device, it is
fallowed by the handshake packet
Handshake Packet consist of these fields
Handshake packet acknowledges with status of entire transaction with
appropriate PID
SYNC PID ADDR ENDP CRC5 EOP
SYNC PID DATA0 CRC16 EOP
SYNC PID EOP
12. Upon completion of this transaction device will able to decode the received data
and understands what is to sent in reply ,places that data in endpoint buffer, after
receiving IN token from the host it will load the data from endpoint buffer to the
data packet and sent
the host will send an IN token to the destination of the device with data data
packet to hold that data
After this transaction bus is connected with the destination endpoint of the device
and it is fallowed by the data packet
Software loads the data of maximum of 8bytes in this data field ,if the data to be
sent is exceeding this limit the whole data will be transmitted in chunks of multiples
of 8bytes, if the last data packet is less than 8bytes then padding is done with zeros
and after this it is fallowed by handshake packet
Host acknowledges with a handshake packet with appropriate PID field
SYNC PID ADDR ENDP CRC5 EOP
SYNC PID DATA1 CRC16 EOP
SYNC PID EOP
13. Once the data is sent, a status transaction follows. If the transactions were successful, the
host will send a zero length packet indicating the overall transaction was successful. The
function then replies to this zero length packet indicating its status
IN token to the designated endpoint
device reply with zero length data packet
acknowledge after this status stage
Interrupt Transfer Type:
it has a limited latency to or from a device. It continuously polls from the
device to update status or coordinates of mouse with polling rate between
1ms and 255ms for full and low-speed
125μs to 4096ms for high-speed endpoints.
The maximum packet size for the interrupt endpoint data is:
64 or less bytes for full-speed
1024 or less bytes for high-speed
SYNC PID ADDR ENDP CRC5 EOP
SYNC PID DATA1 CRC16 EOP
SYNC PID EOP
14. Interrupt transfer type is used for updating some information or status from some
devices like mouse or keyboard etc..
Isochronous transfer type:
used for transmitting real-time information such as audio and video data, and must
be sent at a constant rate. USB isochronous data streams are allocated a dedicated
portion of USB bandwidth to ensure that data can be delivered at the desired rate.
An Isochronous pipe sends a new data packet in every frame, regardless of the
success or failure of the last packet.
The maximum packet size for the isochronous endpoint data is:
• 1023 or less bytes for full-speed
• 1024 or less bytes for high-speed
Isochronous Transfers have no error detection. Any error in electrical transmission
is not corrected.
15. Bulk Transfer Type:
• Used to transfer large data.
• Error detection via CRC, with guarantee of delivery.
• No guarantee of bandwidth.
• Stream Pipe is used which is unidirectional.
• Full & high speed modes only it supports.
For full speed endpoints, the maximum bulk packet size is either 8, 16, 32 or
64 bytes long.
For high speed endpoints, the maximum packet size can be up to 512 bytes
long.
If the data payload falls short of the maximum packet size, it doesn't need to
be padded with zeros.
For example if the data is sent to printer comes under bulk transfer type and
as long as data receiving it prints the whole
16. • USB Descriptors:
Upon plugging the device host will send few standard requests to that
particular device requesting device descriptor, configuration descriptor,
Interface Descriptor all these happens during enumeration through
which that the host able to know what kind of device it is and then a
suitable driver is loaded for that device and sets the configurations
17. Every control Transfer type starts with setup transaction ,These 8 bytes
define the request from the host ,there are 3 standard requests related
with control transfer type
• Standard Device Request
• Standard Interface Request
• Standard Endpoint Request
• Suitable Request can be made from host in data packet field of 8
bytes after setup token in every control transfer type
On decoding that the device will able to understand which standard
request type that host has sent
18. The data packet of control transfer is shown in the table below
Bmrequest Type specifies the type of request and direction transfer
and recipient type
Prefix b and w represents group of 8 bits and 2 bytes used to
represents the whole one field
19. • Following are the valid device requests listed below
Upon requesting the GET_STATUS device will return a 2byte of data in
that DO bit contains the status of configuration whether it is self
powered or bus powered.
20. GET_CONFIGURATION: upon sending this standard device request to
the destination end point of device it returns 1 byte of data in the data
packet of next IN token indicates not configured if it receives zeros, and
configured if it receives non-zero value
SET_CONFIGURATION: Set Configuration is used to enable a device. It
should contain the value of bConfigurationValue of the extracted
configuration descriptor in the lower byte of wValue to select which
configuration to enable.
21. Device Descriptor:
After sending a standard device request requesting GET_DESCRIPTOR command
from the Host , it results in in 18 byte descriptor It specifies some information
about the device such as the supported USB version, maximum packet size,
vendor and product IDs and the number of possible configurations the device
can have.
22. Configuration Descriptor:
After sending a standard device request requesting
GET_CONFIGURATION command to the device , it results in in 9 byte
descriptor The configuration descriptor specifies how the device is
powered, what the maximum power consumption is, the number of
interfaces it has. Therefore it is possible to have two configurations,
one for when the device is bus powered and another self powered.
23. Interface Descriptor:
After sending a standard interface request requesting GET_INTERFACE
command from the Host , it results in in 9 byte descriptor it indicates the
possible each interface number and maximum end points ,class, sub class and
protocol of each interface it passes this information to the host
Here bnumendpoints indicates how many endpoints are there for this device
And binterface number indicates current interface number.
Bnumendpoints indicates number of endpoints used by this device.
24. Endpoint Descriptor:
Upon requesting standard endpoint request to the device by sending
appropriate command listed in the table was sent in data packet of standard
request, during the next transaction of OUT token from that particular endpoint
data to loaded into data0/data1 packet and host decodes the received data and
able to know the status of request
this table lists the fallowing commands for appropriate standard
requests
25. After sending the required standard endpoint request to destination
endpoint it may result it status as shown