ece 371 – unit 20 universal serial bus (usb). references 1. universal serial bus specification,...

57
ECE 371 – UNIT 20 Universal Serial Bus (USB)

Upload: kevin-stephens

Post on 27-Dec-2015

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

ECE 371 – UNIT 20

Universal Serial Bus (USB)

Page 2: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 3: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World
Page 4: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 5: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 6: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

USB Components

• Host computer provides two components:– A host controller– A root hub

Page 7: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 8: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Topology

Page 9: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 10: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example Host with 2 Peripherals

Page 11: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example PC with 6 Peripherals

Page 12: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example – Host with 15 Peripherals

Page 13: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Connectors

Type A

Type B

Page 14: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 15: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

USB 1.0

• Full Speed

• 12 Megabits/sec

• Low Speed

• 1.5 Megabits/Sec

Page 16: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

USB 2.0

• High Speed

• 480 Megabits/Sec

Page 17: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Bus States

• “Differential 1” : D+ is more positive that D-

• “Differential 0” : D- is more positive than D+

Page 18: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 19: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 20: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

USB 2.0 Bus States(High Speed)

• Vout high min = .360 v

• Vout low max = .010v

Page 21: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 22: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 23: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example of NRZI

0: Voltage change

1: No voltage change

Page 24: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 25: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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)

Page 26: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example of Frame

SOF Transaction Transaction. . . SOF Transaction

1 ms or125 us

Frame Number is incremented from One Frame to the Next

Page 27: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 28: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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)

Page 29: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 30: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Example Transfers

Page 31: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Four Types of Transfers

• Control Transfers

• Bulk Transfers

• Interrupt Transfers

• Isosynchronous Transfers

Page 32: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 33: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 34: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Interrupt Transfers

Used for devices that must have attention periodically, without large delay such as:

• Mice

• Keyboards

• Joysticks

Page 35: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 36: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 37: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 38: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Start of Frame Packet

(One of the 4 Token Packets)

Packet ID

One’s complement of Packet ID

1010 0101

Page 39: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Format for Other 3 Token Packets (Out, In, Setup_

Select 1 of 127 devicesSelect 1 of 16 device endpoints

Page 40: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Device Addresses

• ADDR – 7 bits

• Each device is assigned a 7-bit address

• Assigned addresses are 1, 2, …, 127

Page 41: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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

Page 42: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Data Packet

Page 43: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Handshake Packet

Page 44: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

CRC Error Checking

• CRC5 – 5-bit Cyclic Redundancy Check

• CRC16 – 16-bit Cyclic Redundancy Check

Page 45: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Token Packets - 4 Kinds

Page 46: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Date Packets - 4 Kinds

Page 47: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Handshake Packets - 4 Kinds

Page 48: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Special Packets - 4 Kinds

Page 49: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 50: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 51: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Packet

SYNC Packet EOP

Page 52: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

Summary of Transfer Format

Page 53: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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)

Page 54: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 55: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 56: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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.

Page 57: ECE 371 – UNIT 20 Universal Serial Bus (USB). References 1. Universal Serial Bus Specification, Revision 2.0. This specification is available on the World

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