Introduction To USB: By: Enrico Marinoni
Introduction To USB: By: Enrico Marinoni
it Enrico Marinoni
________________________________________________________________________________
Introduction to USB
• Introduction
• Pin Out
• USB 2.0 Standard
• USB Topology
• USB Device attachment & speed detection
• USB Device Power
• USB Suspend mode
• USB Transaction
• USB Transfer
• USB Control Transfer
• USB Bulk Transfer
• USB Interrupt Transfer
• USB Isochronous transfers
• Host constraints for Interrupt & Isochronous Transfers
• USB High-Speed mode specific features PING/NYET
Protocol
• USB High-Speed mode specific features SPLIT Protocol
• LINK
NOTE:
This short introduction to USB was made using info from WikipediA and Developing USB
applications using the STM32 ARM Cortex-M3 microcontroller by:Anis BEN ABDALLAH
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
Introduction
Universal Serial Bus (USB) is an industry standard developed in the mid-1990s that
defines the cables, connectors and communications protocols used in a bus for
connection, communication, and power supply between computers and electronic devices.
Pin Out
WikypediA source
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
• USB keeps high compatibility at protocol level between all supported speeds
• Bus components
◦ USB host or Root hub: initiates all the transaction on the bus
◦ USB function: is a device with one or more interfaces that expose capabilities
to the host (ex: mouse, keyboard,..)
◦ USB hub: allows to connect multiple devices to the USB host. It has an
upstream port for communication with the host and multiple downstream ports
for direct connection to devices
USB Topology
• The 1.5K pull-up allows the host to detect the device attachment and its supported
speed
• High-speed device is detected first as full-speed device then high-speed capability
is detected through bus handshake mechanism called “chirp sequence”
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
• USB device should enter in USB Suspend mode when the bus is in idle state for
more than 3 ms
• In suspend mode, when the device is bus powered, the current drawn from VBUS
power shouldn’t exceed 2.5mA
• USB host prevents device from entering in suspend mode by periodically issuing
Start of Frame (SOF) or Keep Alive for LS
◦ For High-speed, SOF is sent every micro-frame: 125us +/- 65ns
◦ For Full-speed, SOF is sent every frame: 1ms +/- 500ns
◦ For Low-speed, Keep Alive (End of Packet) is sent every 1ms in
absence of low-speed data
• Exist from Suspend mode can be
◦ Initiated from host by issuing the resume signaling
◦ Initiated from device by issuing the remote wakeup signaling
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
USB Transaction
• Token packet (SETUP, IN, OUT) always issued by the host, includes:
◦ PID (IN: Device to host data transaction or SETUP/OUT: host to device data
transaction)
◦ Target device address
◦ Target endpoint number CRC
• Data packet (DATA0, DATA1, DATA2, MDATA) includes:
◦ PID: DATA0, DATA1, DATA2 or MDATA (DATA2 and MDATA are used only in HS
mode)
◦ Carries the data payload of a transaction sent by the host or device
◦ DATA PID toggle used to synchronize HOST and DEVICE to avoid repeated
packet transfer in case of corrupted or lost handshake
◦ CRC
• Handshake packet (ACK, NAK, STALL, NYET)
◦ ACK: packet reception acknowledged (sent from host or device)
◦ NAK: packet reception not acknowledged (sent from device only)
◦ STALL: control request not supported or endpoint halted (sent from device only)
◦ NYET: device not ready to accept further packets (only for high-speed device)
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
USB Transfer
• Used for standard control requests during device enumeration process or during
class operation
• All devices should support control transfer through endpoint 0 (bidirectional)
• It is given reserved bus bandwidth for 10% for FS/LS and 20% for HS
• Control transfer has 3 stages
◦ SETUP stage: one SETUP transaction for issuing the control request (ex: Get
Descriptor)
◦ Optional DATA stage IN or OUT: one or multiple data transactions
The maximum data packet size during the optional data stage is 8 bytes for LS
and 64 bytes in FS/HS
◦ Status stage: one IN or OUT transaction with a Zero Length data packet to
check if control transfer request executed correctly or not.
• Transfer error management done through handshake packet and data PID toggle
mechanism
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
• Used to transfer large amount of data without guaranteed delivery rate (sending
data to printer, drive,..)
• Lowest priority transfer with no reserved bus bandwidth but can occupy the full
bandwidth if no other transfer on the bus
• Supported only by full-speed and high-speed devices
• Consist of one or more IN or OUT transactions during each frame/micro-frame
(unidirectional)
• The max packet size is 64 bytes for FS and 512 bytes for HS
• Transfer error management done through handshake packet and data PID toggle
mechanism
• Interrupt transfers are used to poll devices to determine if they have data that needs
to be transferred (mouse, keyboard,..)
• Interrupt IN or OUT data transfers are scheduled periodically within a maximum
polling period negotiated during device enumeration but host is free to initiate more
IN/OUT transactions if there is bandwidth available
• Limited reserved bandwidth for Low/Full speed devices
◦ For low-speed the packet max length is 8 bytes with a guaranteed maximum
latency of up to 1 packet each 10 frames => 800 Bytes/s
◦ For full-speed the packet max length is 64 bytes with a guaranteed maximum
latency of up to 1 packet each frame => 62.5 KBytes/s
• High bandwidth with high-speed
◦ For high-speed the packet max length is 1024 bytes with up to 3 packets each
micro-frame
• Transfer error management done through handshake packet and data PID toggle
mechanism
• Used mainly for streaming real-time data like audio and video
• Needs a guaranteed bandwidth with a constant transfer rate but there is no error
checking
• The requested bandwidth is negotiated between host and device during
enumeration
• Transfer is in one direction and can consist of one or more data OUT or IN
transactions with no handshake packet
◦ In FS, the max packet length is 1023 bytes with a maximum of one packet per
frame
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
◦ In HS, the max packet length is 1024 bytes with a maximums of 3 packets per
frame
• Devices that use isochronous transfer need in most of the cases to establish a
synchronous connection (ex: speaker, microphone, video camera,...)
◦ Minimal or no data buffering
• The synchronization between the data source (producer) and the sink (consumer)
can be achieved by
◦ Having the source and sink clocks synchronized to the SOF packet
◦ Doing a clock adaptation either on the source
• The host may not be able to provide the requested bandwidth to device, in this case
the host will try other possible configurations with lower bandwidth requirements (if
provided by the device)
• If still no bandwidth available, the host will refuse device configuration
• Host software may have some latency for processing data and issuing transfer
requests on time due to other processes taking CPU time
• In order to avoid multiple SW calls for handling data to be transmitted or received,
large chunks of data transfers should be scheduled
• For control and bulk transfers, when a high-speed device is not ready to receive
further data OUT packets, it can send the NYET handshake
• When the host receives the NYET handshake, it should send the PING packet
periodically to check if device is ready or not to resume receiving data packets
• When ACK is received for a PING request, the host will resume sending data
packet
• The SPLIT protocol is used when the HS host need to communicate with a
low/full speed device which is connected to a high-speed hub
• The host will do the data transaction with the HS hub in high-speed, then the hub as
a host will initiate the same transaction in low/full speed with the device
• The data transaction done by the host with the HUB is preceded with the Start
SPLIT (SSPLIT) token
• The host will later use CSPLIT token to retrieve the device response from the HUB
INDEX
By: www.emcu.it Enrico Marinoni
________________________________________________________________________________
LINK
INDEX