ece 371 – unit 20 universal serial bus (usb). references 1. universal serial bus specification,...
TRANSCRIPT
ECE 371 – UNIT 20
Universal Serial Bus (USB)
References• 1. Universal Serial Bus Specification, Revision 2.0. This
specification is available on the World Wide Web site http://www.usb.org.
• 2. Universal Serial Bus Device Class Definition for Printing Devices, Version 1.1. This specification is available on the World Wide Web site http://www.usb.org.
• 3. Jan Axelson, USB Complete: Everything You Need to Develop Custom USB Peripherals, Second Edition, ISBN 0-96508-5-8, Lakeview Research, Madison, WI 53704, 2001.
• 4. Microchip PIC16C745/765. This single chip computer supports USB. Data sheets and application notes are available on the World Wide Web site http://www.microchip.com.
USB Overview
• Universal Serial Bus (USB) is a fast and flexible interface.
• Connects up to 127 devices to a personal computer.
• All recent PCs are marketed with at least one and often several USB ports.
USB Overview
• The USB interface is versatile enough to support all standard peripherals such as keyboards, printers, mice, network interfaces, RS 232 serial, cameras, and disk drives.
• The older standard interfaces such as the parallel port, the COM ports, the PS2 ports, and infrared ports are slowly being eliminated on newer PCs and being replaced with USB as the standard interfaces to peripherals.
USB Components
• Host computer provides two components:– A host controller– A root hub
USB Topology
• USB uses a “tiered star” configuration for connecting hubs and devices to the Root Hub
• Hub is the center of each star
• Hubs provide the data path between the device and the root hub
• Root Hub is limited to 127 devices
• Tree cannot be more than 6 levels deep.
Topology
Host Centric Architecture
• USB is a host centric architecture
• Host is always the master
• Devices are allowed to transmit only when specifically instructed to by the host
• Devices are polled by the host.
Example Host with 2 Peripherals
Example PC with 6 Peripherals
Example – Host with 15 Peripherals
Connectors
Type A
Type B
USB Cable Wiring
• There are 4 wires in the cable
• 2 Power (+5 Volts, ground)
• 2 Signal wires (–D, +D)
• Low Power Devices and Hubs can be powered from 2 power wires
USB 1.0
• Full Speed
• 12 Megabits/sec
• Low Speed
• 1.5 Megabits/Sec
USB 2.0
• High Speed
• 480 Megabits/Sec
Bus States
• “Differential 1” : D+ is more positive that D-
• “Differential 0” : D- is more positive than D+
Relation Between Bus States and Data States
Bus State Data State
Low Speed Full Speed High Speed
Differential 0 J K K
Differential 1 K J J
USB 1.0 Bus States(Low Speed and Full Speed)
• Vout high min = 2.8 v
• Vout low max = .3v
• Vin high min = 2.0 v
• Vin low max = .8v
USB 2.0 Bus States(High Speed)
• Vout high min = .360 v
• Vout low max = .010v
Data Encoding – NRZI
• NRZI defines logic “0” as a voltage change and a logic “1” as a voltage that remains the same.
• The least significant bits are transmitted first.
• The receiver is automatically synchronized with the transmitter by transitions in the signal.
NRZI with Bit Stuffing
• Insure synchronization.
• A logic “0” is automatically inserted after 6 “1”s on transmission
• A logic “0” is deleted automatically after 6 “1”s on receive.
Example of NRZI
0: Voltage change
1: No voltage change
Frames
• The host schedules transactions within 1-millisecond frames for low speed and full speed.
• For high speed, 125 microsecond frames are used.
• Each frame begins with a Start-of-Frame packet followed by transactions that transfer data to or from device endpoints.
• The host can schedule transactions anywhere inside a frame.
Sta
rt o
f fr
ame
Dev
ice
1,en
dpoi
nt 2
Dev
ice
2, E
ndpo
int
0
Dev
ice
2, E
ndpo
int
2
Unu
sed
TransactionsStart of Frame Packet
Token Packet: (First Packet in Each Frame)
Example of Frame (1 msec)
Example of Frame
SOF Transaction Transaction. . . SOF Transaction
1 ms or125 us
Frame Number is incremented from One Frame to the Next
Define: “Transfer”
The process of making and carrying out a communication
request.
• A complete transfer may take place over multiple frames
• Each transfer consists of 1 or more Transactions.
Define: “Transaction”
Delivery of service to an end-point
( the host’s sending a chunk of data to a device or the host’s
requesting and receiving a chunk of information from the device)
• No other other communication on the bus can break into a
transaction
• Each transaction consists of 1 - 3 phases (packets)
•
Define: “Packet”
A block of information with a fixed format
• All packets start with a packet id, which identify the packet type
• Other information that may be included in packet:
- Endpoint Address
- Data
- Status Information
- Frame Number
- Error Checking Bits
Example Transfers
Four Types of Transfers
• Control Transfers
• Bulk Transfers
• Interrupt Transfers
• Isosynchronous Transfers
Control Transfers
Used by the host to:
• Read information about a device
• Set a device’s address
• Select configurations and other settings
• Send custom requests that send and receive data for any purpose.
Bulk Transfers
• Intended for situations where the transfer rate is not critical, such as:
• Sending a file to a printer
• Receiving data from a scanner
Interrupt Transfers
Used for devices that must have attention periodically, without large delay such as:
• Mice
• Keyboards
• Joysticks
Isosynchronous Transfers
• Used for applications that must have a guaranteed delivery time, such as
- Transferring audio files that must be played in real time.
• Guarantees a fixed amount of data at a fixed rate.• Trades off guaranteed data accuracy for
guaranteed timeliness.• No data checking is performed, and the loss of
data is not catastrophic.
3 Types of Transactions
• Status– For sending control/transfer requests to a
device
• In
- For receiving data from a device
• Out– For sending data to a device
4 Types of Packets(each type has 4 sub-types, for a total of 16 kinds of
packets)
• Token– Identifies the transaction type
• Data
- Carries data or status information• Handshake
– Carries status information
• Special
Start of Frame Packet
(One of the 4 Token Packets)
Packet ID
One’s complement of Packet ID
1010 0101
Format for Other 3 Token Packets (Out, In, Setup_
Select 1 of 127 devicesSelect 1 of 16 device endpoints
Device Addresses
• ADDR – 7 bits
• Each device is assigned a 7-bit address
• Assigned addresses are 1, 2, …, 127
End Points
• ENDP – 4 bits
• End points are device registers
• Each device has 1 to 16 End Points
• Assigned end points are 0, 1, …, 15
• End point 0 is device control
• Up to 16 IN End Points
• Up to 16 OUT End Points
Data Packet
Handshake Packet
CRC Error Checking
• CRC5 – 5-bit Cyclic Redundancy Check
• CRC16 – 16-bit Cyclic Redundancy Check
Token Packets - 4 Kinds
Date Packets - 4 Kinds
Handshake Packets - 4 Kinds
Special Packets - 4 Kinds
Handshake Packets
• PING and NYET packets require High Speed (USB 2.0).• ACK – Packet was received correctly.• NAK – The NAK is sent for a number of reasons.• Packet was received correctly but the host should
resend data because of a temporary condition such as a buffer overflow caused a loss of data.
• Sender can not send data.• Sender has no data to send.• If packet was received in error, then no response is sent.
Packet Coding
• Prior to transmitting a packet, line is in the Idle State (J).
• Each packet begins with a SYNC character and is terminated with an End-of-Packet signal.
• For low and full speeds, the SYNC is eight bits and is KJKJKJKK.
• For high speed, the SYNC is 32 bits: 15 KJ repetitions following by KK.
Packet
SYNC Packet EOP
Summary of Transfer Format
Enumeration (Overview)
• Enumeration is the process that the host uses to either identify a hub or device whenever it is connected to or disconnected from a hub.
• USB Enumeration is started whenever a hub or device is plugged into USB hub port or system powers up.
• Enumeration includes (among other things):– Hub determines speed of device (High, Full, or Low)– Hub determines class of device (e.g, printer, keyboard, camera,
etc.)– Hub assigns address to device
– (Full list of Enumeration step are shown on following slides)
Enumeration (in detail)
• Enumeration is the process that the root uses to either identify a hub or device whenever it is connected to or disconnected from a hub.
• 1. USB Enumeration is started whenever a hub or device is plugged into USB hub port or system powers up.
• 2. Hub detects the device.• D+ = High, D- = Low – full speed device or high
speed• D+ = Low, D- = High – low speed device• 3. Host sends the hub a Get_Port_Status and other hub
class-class requests for information.• 4. Hub returns speed in response to Get_Port_Status
request from host.
Enumeration
• 5. Host sends a Set_Port_Feature to instruct hub to reset the port.
• Reset = D+ = D- = Low for at least 10 milliseconds
• 6. Host determines if full-speed device supports high speed.
• Device sends Chirp K.• High speed hub responds with Chirp
KJKJKJ• Device detects Chirp KJKJKJ and
performs all further communications at High Speed.
Enumeration
• 7. Host establishes signal path between host and device
Host sends Get_Port_Status until the hub exits reset state
Device now in Default state.Responds to Address = 0, Endpoint = 0
• 8. Host sends Get_Descriptor to get device’s maximum packet size.
• 9. Host assigns an address with Set_Address request.
Enumeration
• 10. Host sends one or more Get_Descriptor request to learn the identify of the device and the device’s abilities.
• 11. Host assigns and load a device driver.
• 12. Host send Set_Configuration to selects a configuration supported by driver