USB 2.0 Star network configuration Only one host Maximum of seven levels of tiers, hub at center Host and hubs provide power to slaves Maximum of 5m per cable Maximum of 127
Trang 1Renesas Electronics America Inc.
Embedding USB - The Implementation Challenges and Limitations
Micriµm
Trang 2Renesas Technology & Solution Portfolio
Trang 4 Universal Serial Bus: Serial bus standard to interface
devices
Peripheral communication protocol of choice for keyboards,
printers, and memories
protocol stack from USB Device protocol stack and
On-The-Go
It goes over the design implications and some solutions.
USB for Embedded Systems
Trang 5USB Products
Trang 61969 Serial port (RS-232C)
1995 The USB consortium is formed by Compaq, DEC, IBM,
Intel, Microsoft, NEC and Nortel
1996 USB 1.0 standard was released Plug Fest
1999 USB 1.1 was released Corrected bugs
2000 USB 2.0 was released specifying the implementation of a
480 Mbps bus
2001 USB On-The-Go (OTG) supplement was added which
allowed devices to talk to each other
2005 Wireless USB standard was released which is a point to
point wireless communications link
Brief History
Trang 7USB 2.0
Star network configuration
Only one host
Maximum of seven levels
of tiers, hub at center
Host and hubs provide power to slaves
Maximum of 5m per cable
Maximum of 127 devices (hubs included)
Host schedules and initiates data transfers
Devices implements one
or more functions
Architecture Topology
USB Speed Low Speed Full Speed High Speed
Speed 1.5 Mbits/sec 12 Mbits/sec 480 Mbits/sec
USB 1.1
Trang 8 USB 1.1
OHCI – Compaq, Microsoft, and National; hardware burden
UHCI – Intel, software burden
EHCI – USB with Intel, simplified software and reduced cost
SuperSpeed - Hewlett-Packard, Intel, Microsoft, NEC, NXP
Semiconductors and Texas Instruments
November 17, 2008
Host Controllers
Trang 9 Device
A device is a logical or physical entity that performs one of more functions.
A composite device has one address but multiple interfaces or
association of interfaces each providing a function (i.e a function printer, scanner, fax, copier)
A compound device contains a hub with one or more
permanently attached devices A host treats the hub and its functions as if they were separate physical devices.
Device
Trang 10Root Hub (RH) = embedded hub part of the Host
Provides 1 or more attachment points (i.e ports)
Equivalent to external Hub – Presents standard hub functions – Presents standard states as other USB devices
Host and Root Hub
Responsible for:
Device connection/disconnection
Device reset
Trang 11 When the Host stack starts, the 1st device to be enumerated
is always the Root Hub (RH)
which contains features supported by the RH
bNbrPorts: Number of downstream facing ports that this hub
supports
Device attachment/detachment event
Port power/enable/reset/suspend/resume events
Host and Root Hub
Enumerating Function 1
Enumerating Hub Hub descriptor
Enumerating Function 2 & 3
bNbrPorts = 2
bNbrPorts = 2
Trang 12Mechanical Specifications
Trang 13Mechanical Specifications
Cable:
• Cable is made of 4 28-AWG conductors:
• Data pair is twisted
• Maximum cable length is 5 meters
Connector:
• Connector Type A connects to host
• Connector Type B connects to device
• Connector power pins are longer for hot-swap
1 2 3 4
Type A USB Connector
Type B USB Connector
1 2
3 4
D+ D- + -
D+
+
D
Trang 14-Mini-B Plug
Mini connectors were added in USB 2.0
and OTG supplement
An alternative to the standard B
connector on handheld and portable
devices The mini-B connecter has a
fifth pin, named ID It is not connected
Trang 15Number
Signal Name
Typical Wiring Assignment
Shell Shield Drain Wire
Micro connector Pin Assignments
OTG Connectors
Micro-A USB Connector
Micro-B USB Connector
1 5
White insulator
1 5
Black insulator
Trang 16Electrical Specifications
Trang 17 The complexities and speed of the USB protocol are such
that it is not practical to expect a general purpose
microcontroller to be able to implement the protocol using
an instruction-driven basis
portions of the specification, and the circuitry grouping which performs this function is referred to as the Serial Interface
Engine (SIE)
Serial Interface Engine
Trang 18Device Detection
Current is limited to 100mA
Either the D+ or the D- line will be pulled high
D+ is high, the device is a full or high speed
Trang 19 The USB bus 5V supply is a very attractive feature A USB
device with a single connection is also attractive to the user
Supply voltage can fall to 4.35V at the device
When other devices are being plugged, there can be transients
lowering the supply voltage by 0.4V
Devices can be classified as:
– Bus powered – Self powered – Hybrid powered
Device Powering
Trang 20 Self-powered devices provide power requirements on descriptor
(see descriptor in the software section) Initially provides 100mA, this can be increased up to 500mA (high power)
Self-powered hubs have a limitation on self-powered devices of
Device Powering
Trang 21 There is a suspend mode (no bus activity) In suspend
mode, devices consume up to 500µA (where 200 µA already used by the pull up and pull-down resistors)
which meets this requirement Do not forget that a badly
placed resistor can very easily draw current which you
hadn't expected Measure your suspend current with a meter
feature enabled are allowed to draw up to 2.5mA during
suspend
device is configured
Device Powering
Trang 22 Place a capacitance of at least 1uF across Vbus and GND to prevent from flyback voltage when unplugging a cable at the far end from the device
GND is limited by the specification to 10uF This is to avoid
other devices to crash because plugging device in, a
capacitance between Vbus and GND will cause a dip in
voltage across the other ports of the hub
with at least 120uF
Hot-Pluggable
Trang 23 If you pull, say D+, high in the absence of Vbus then you
will risk faulty operation with On-The-Go hosts
D+ or D- line above the Vbus voltage supplied This means that you must sense when Vbus is connected
derived from Vbus, or controlled by Vbus in such a way that the resistor never sources current to the data line when
Vbus is switched off
Self-Powered Devices
Trang 24 On-The-Go and Battery Charging Specification both add new powering modes to the USB specification.
Power)
+5 volts DC at up to 6 amps per connector (up to 30 watts)
+12 volts DC at up to 6 amps per connector (up to 72 watts)
+24 volts DC at up to 6 amps per connector (up to 144 watts)
of extra power lines for point-of-sale terminals
More Power
Trang 25SYNC PATTERN PACKET INFORMATION IDLE
SYNC PATTERN PACKET INFORMATION IDLE
SYNC PATTERN PACKET INFORMATION IDLE
(NRZI)
Trang 26 Given that there are 2 data lines, many different conditions are signaled using them:
Bus States
Single Ended Zero (SE0) D+ and D- low Single Ended One (SE1) D+ and D- high
Data J State:
Low-speed Full-speed Differential '0' Differential '1'
Data K State:
Low-speed Full-speed Differential '1' Differential '0'
Idle State:
Low-speed Full-speed D- high, D+ low D+ high, D- low
Trang 27High Speed
Trang 28Packet Sync
Just prior to the packet sync, both data lines are low The sync is sent using the NRZI sequence
KJKJKJKJKJKJKJKJ KJKJKJKJKJKJKJKK
A hub may drop up to 4 bits from the sync pattern After 5 hubs the
sync field of a packet may be only 12 bits long.
Trang 29 On a low or full speed link, a brief Single Ended Zero (SE0) state is used to indicate End Of Packet (EOP), and idle is indicated by a J
condition.
On a high speed link, the idle state is effectively a SE0, so that
state is not available to indicate EOP, and a different method for
indicating the end of packet is used
During normal data transmission there can not be a run of more
than 6 1's in a row, because a 0 is automatically inserted (and will
be removed on reception), for clock recovery reasons.
At high speed, the EOP is indicated, by deliberately sending a byte which contains a bit-stuffing error; '01111111' This applies at the end of all packets except SOF.
Each high speed SOF packet is terminated with 5 NRZI bytes
containing bitstuffing errors: 01111111 11111111 11111111
-11111111 11111111 This pattern allows the 'disconnection
envelope detector' to detect a rise in data amplitude above 625
mV, in the event that the device, along with its termination
resistors, has been unplugged.
End of Packet
Trang 30Negotiating High Speed
A high speed device will always present itself initially as a Full Speed device (by a 1.5K pullup resistor on D+).
The negotiation for High Speed takes place during the Reset, which is the first thing a host (root or tier hub) must do to a device before
attempting data communication.
The high speed detection handshake is initiated by the device A hub will respond to it, if it is high speed capable.
Trang 31High Speed Hubs
with Full and Low Speed Devices
Traffic directed at full or low speed devices uses high speed links, as
high speed split transactions.
Trang 32SYNC IDLE PACKET INFORMATION EOP
PID
Packets
The fundamental element of communications is the packet
A packet is made of three parts: START, INFORMATION, and
END-OF-PACKET (EOP)
At the START of a packet will be a sequence of transitions which is called
SYNC
The SYNC pattern is a chirp of either 8 bits (full-/low-speed) or 32 bits
(high-speed) where each bit is a J or K state:
KJKJKJKJKJKJKJKJKJKJKJKJKJKJKJKJKK
The INFORMATION varies from 1 byte up to 1024 bytes
Trang 33bits long at low and full speed or 32 bits long for high speed and is used to synchronize the clock of the receiver with that
of the transmitter The last two bits indicate where the PID
fields starts
USB Packet Fields
SYNC
Trang 34PID
type of packet that is being sent
USB Packet Fields
PID
Trang 35Group PID Value Packet Identifier
1100 ERR (Split Transaction Error Handshake (reuses PRE value))
1000 SPLIT (High-speed Split Transaction Token)
0100 PING (High-speed flow control probe for a bulk/control Endpoint)
Trang 36 The first byte in every packet is the Packet Identifier (PID)
byte This byte needs to be recognized quickly by the USB
controller This is why it is not included in any CRC checks
It has its own validity check
4 bits by repeating and complementing them, making an 8
bit PID field in total
USB Packet Fields
PID
PID 0 PID 1 PID 2 PID 3 nPID 0 nPID 1 nPID 2 nPID 3
Trang 37ADDR
designated for Being 7 bits in length allows for 127 devices
to be supported Address 0 is not valid, as any device which
is not yet assigned an address must respond to packets sent
to address zero
USB Packet Fields
ADDR
Trang 38ENDP
endpoints Low speed devices, however can only have 2
additional endpoints on top of the default pipe (4 endpoints max)
USB Packet Fields
ENDP
Trang 39 A CRC is a value calculated from a number of data bytes to form a unique value which is transmitted along with the data bytes, and then used to validate the correct reception of the data
a 5 bits long (CRC5)
and
a 16 bits long (CRC16)
algorithms used to compute the CRCs
Cyclic Redundancy Code (CRC)
Trang 40EOP
approximately 2 bit times followed by a J for 1 bit time
USB Packet Fields
EOP
Trang 41 For a general embedded system, silicon vendors have
resolved most of the hardware and electrical issues for the
embedded engineer You need not be concerned with the
detail of syncs, bit stuffing, and End Of Packet conditions
You should just be aware that the Serial Interface Engine
can recognize the start and end of a packet, and that the
packet contains a whole number of bytes
the software realm
USB Controllers
Trang 42Software Specifications
Trang 44 USB has four different packet types:
Start of Frame Packets
Token Packets
Data Packets
Handshake Packets & Split Transaction Special Token Packets
USB Packet Types
Trang 45PID FRAME
NUMBER
CRC 5 SOF
8 11 5
0101
indicate the start of a new
frame The SOF packet
consisting of an 11-bit
frame number is sent by
the host every 1ms ± 500ns
on a full speed bus or every
125 µs ± 0.0625 µs on a
high speed bus
(micro)frame An SOF
allows endpoints to identify
the start of the
(micro)frame and
synchronize internal
endpoint clocks to the host
Start of Frame Packets
Trang 46PID ADDR CRC
5
IN OUT SETUP
8 7 5
1001 0001 1101
EN DP
4
transaction to follow They are always
the first packet in a transaction,
identifying the targeted endpoint, and
the purpose of the transaction
Trang 47 Data packets contain the payload.
transmitting up to 1024 bytes of data
Data0
Data1
Data Packets
Low and Full speed
DATA0 DATA1 DATA2 MDATA
0011 1011 0111 1111
DATA0 and DATA1 PIDs are used in Low and Full speed links as part of an error-checking
system.
When used, all data packets on a particular endpoint use an alternating DATA0 / DATA1 so that the endpoint knows if a received packet is the one it is expecting If it is not the expected
packet, it will still acknowledge (ACK) the packet as it is correctly received, but will then
discard the data, assuming that it has been retransmitted because the host missed seeing the ACK after the previous data packet.
Trang 48 High Speed mode defines two additional data PIDs, DATA2 and MDATA
This data packet token has been added as part of a system for controlling
multiple isochronous IN packets during one microframe at high speed For each isochronous IN packet requested, the suffix of the DATAx PID represents the remaining number of packets to be transferred during the current micro- frame.
This data packet token has been added as part of a system for controlling
multiple isochronous OUT packets during one microframe at high speed All but the last packet sent during a microframe use the MDATA PID The last packet sent uses DATA0, DATA1 or DATA2 depending on whether one, two or three packets were sent.
Data Packets
High Speed
Trang 498
ACK NAK STALL NYET
0010 1010 1110 0110
Handshake packets are used for acknowledging data
or reporting errors There are four type of
handshake packets which consist simply of the PID.
The device is not ready to answer (High Speed only).
Handshake Packets
Trang 50C PORT SE
E T
7
1 1 1 2
Split Transaction Special Token Packets
The split transaction token is used to support split transactions
between the host controller communicating with a hub operating
at high speed with full-/low-speed devices to some of its
downstream facing ports.
Trang 51 Packet
Token: OUT, IN, SOF, SETUP
Data: DATA0, DATA1, DATA2, MDATA
Handshake: ACK, NAK, STALL, NYET
Special: PRE, ERR, SPLIT, PING
Hierarchy of Data
Transfer (Control, Interrupt, Isochronous, Bulk)
Transaction 1 Transaction 2 Transaction 3 … Transaction n
Packet 1 Packet 2 Packet 3 … Packet 1 Packet 2 … Packet 1 Packet 2 …
Trang 52 A successful transaction is
a sequence of three packets which performs a simple but secure transfer of data.
there are only 2 packets;
the handshake packet on the end is omitted This is because
error-checking is not required.
In each of the following illustrations, the packets from the host
Transactions
Trang 53 A successful SETUP transaction comprises three sequential
packets This is similar to an OUT transaction, but the data
payload is exactly 8 bytes long, and the SETUP PID in the
token packet informs the device that this is the first
transaction in a Control Transfer (see standard requests)
packet
SETUP Transaction
Token Packet
Data Packet
Handshake Packet
From Host
ADDR SETUP
E N D P
C R C 5
D A T A 0
8 bytes