usb 세미나 - cpci.co.kr

51
1 http://www.daqsystem.com 디에이큐시스템 2011. 11. 30 www.daqsystem.com [email protected] USB 세미나

Upload: others

Post on 01-Mar-2022

6 views

Category:

Documents


0 download

TRANSCRIPT

1 http://www.daqsystem.com

디에이큐시스템 2011. 11. 30

www.daqsystem.com

[email protected]

USB 세미나

2 http://www.daqsystem.com

USB 개요 USB장치의 구성 개발에 필요한 정보

응용 제품

목 차

USB 프로토콜 H/W 설명 Firmware Driver 구조

USB 프로토콜 분석 질의 응답

USB 소개 USB 응용 프로토콜 분석

3 http://www.daqsystem.com

1981년 IBM PC 발표 (Open Architecture) i8086, ISA, Serial(RS232), Parallel(Centronics), IDE Limited Device 1995년 PCI, USB by Intel ISA -> EISA -> PCI->PCI-X (VESA, AGP, PCI-Express) PCMCIA->Card bus RS232,Parallel -> USB(Serial, Power, Speed, Device, PnP

Hot-plug)

USB 소개

USB 개요

4 http://www.daqsystem.com

5 http://www.daqsystem.com

USB 장치의 구성

6 http://www.daqsystem.com

Host - Over all management of USB bus - Enumeration - Device management

Cable

Downstream A Upstream B

7 http://www.daqsystem.com

Device - Add functional capability to Host - Single upstream connection - Data terminal (create or consume)

Hub - A Device has more usb ports - Can connect more device through a usb port

8 http://www.daqsystem.com

Feature - Hot swap (do not require system re-booting) - Maximum 127 Device - High speed data rate(480Mbps, USB2.0 HS) 12Mbps(Full speed), 1.25Mbps(Low speed) - Bus-powered operation(Max 500mA per a Device) - 4-wire serial interface(+5V, GND, D+, D-) - Power management(Power-saving, sleep mode)

9 http://www.daqsystem.com

10 http://www.daqsystem.com

• Device Functionality • Performance requirement (throughput) • Host system(PC, Operating system, Driver) • Power consumtion • USB support chip (Microcontroller, stand alone) • Chip manufacture

(Cypress, Philips, NS, Atmel, TI, Samsung, Microchips, SMSC, Winbond, ST, Point chips etc.)

• Development S/W (OS, Driver, Firmware, Compiler) • Protocol Monitoring

개발에 필요한 정보

11 http://www.daqsystem.com

카메라 지문인식 허브 모뎀

신서사이저 튜너 저장장치 카메라

응용 제품 1

12 http://www.daqsystem.com

센서 GPIB 조이스틱 I/O expander

메모리리더 전화기 키보드 휴대폰

응용 제품 2

13 http://www.daqsystem.com

Topology

USB 응용

USB 프로토콜

14 http://www.daqsystem.com

Physical

15 http://www.daqsystem.com

Signaling

16 http://www.daqsystem.com

IDLE : D+(High), D-(Low) J state : D+(High), D-(Low) after SOP K State : D+(Low), D-(High)

17 http://www.daqsystem.com

18 http://www.daqsystem.com

Device Detect

19 http://www.daqsystem.com

Packet Type PID Value Packet Type Packet Category

0101 SOF Token

1101 SETUP Token

1001 IN Token

0001 OUT Token

0011 DATA0 Data

1011 DATA1 Data

0111 DATA2 Data

1111 MDATA Data

0110 NYET Handshake

0010 ACK Handshake

1010 NAK Handshake

1110 STALL Handshake

1100 ERR Special

1100 PRE Special

1000 SPLIT Special

0100 PING Special

20 http://www.daqsystem.com

• Token ( For Device setup) • Data (Data Transmission) • Handshake (data acknowledgement) • Special

- PRE (For low-speed connection) - SPILT/PING (For HS transaction)

21 http://www.daqsystem.com

Packet Type

Type Important Attributes Maximum Size Example

Interrupt Quality 1024/64/8 Mouse, Keyboard

Bulk Quality 512/64 Printer, Scanner HDD

Isochronous Time 1024/1024 Video, Audio

Control Time and Quality 64/64/8 Device control

22 http://www.daqsystem.com

H/W 설명 USB I/O Device

23 http://www.daqsystem.com

Anchor Chips(Cypress) Ez-usb chip

24 http://www.daqsystem.com

25 http://www.daqsystem.com

Firmware

26 http://www.daqsystem.com

End Point0

End Point1

Other Interfaces

Interface0

Interface1

Other Interfaces

Configuration0

Interfaces

Configuration1

Other Configurations

USBDevice

27 http://www.daqsystem.com

28 http://www.daqsystem.com

Driver

USB Application USB Application

HIDCLASS.SYS

HIDUSB.SYS

USBHUB.SYS

USBD.SYS

PCI Enumerator

Physical Interface(Cable)

UHCD.SYS OpenHCI.SYS

User Mode

Kernel Mode

29 http://www.daqsystem.com

Root Hub

Host

HUB

HUB Keyboard

Speaker

Disk

Printer

2 types of peripherals: - HUB - Function - Up to 127 peripherals

A master/slave architecture USB 2.0 spec supercedes USB 1.1 spec

- USB 2.0 LS ( USB1.1 at 1.5Mbps) - USB 2.0 FS ( USB 1.1 at 12Mbps) - USB 2.0 HS (480 Mbps)

Power Management - Different device class: bus powered or self powered - Vbus > 4.35V. 100mA, (500mA after negociation),

500uA in suspend mode - Host disables power to ill-behaved peripherals

30 http://www.daqsystem.com

• The Transaction Protocol is Host Based

• Host based token polling – Data from host-to-function and function-to-host – Host handles most of the protocol complexity – Peripheral design is simple and low-cost

• Robustness – Handshake to acknowledge data transfer and flow control – Very low raw physical bit error rate (< 10 –10) – CRC protection plus hardware retry option – Data toggle Sequence bits

• Bounded transfer characteristics – Data transfer bandwidth and latency prenegociated – Flow control for peripheral buffer management

• No asynchronous message/interrupt from the peripheral

31 http://www.daqsystem.com

• USB Topology

• A unique device address is assigned to each USB device • Physical tiered start network:

Logical network:

Each device sees all traffic generated by the host A device does not see data sent by another peripheral

HOST

Root Hub @: 1

Hub @: 2

Dok @: 3

Mouse @: 4

IP phone @: 5

Logical link

HOST Hub @: 2

Dok @: 3

Mouse @: 4

IP phone @: 5

Root Hub @: 1

USB cable Keyboard @: 6

Keyboard @: 6

HID Driver

MSD Driver

HUB Driver

Audio Driver

A driver has no information on the topology of the physical network

32 http://www.daqsystem.com

• USB transfer

• A device has several endpoints • Each endpoint is assigned to a logical pipe with the host • Each pipe is characterized by:

– Device address – Endpoint number – Transfer type

• Transfer type:

Control: configuration/command/status type communication Bulk: large amounts of data at highly variable times Isochronous: constant-rate, error tolerant transfers Interrupt: send or receive data infrequently but with bounded service periods

Type Direction Packets per frame Max Packet SizeControl Bidir Several 64 BytesBulk Unidir Several 64 BytesIsochronous Unidir One 1024 BytesInterrupt Unidir One max 64 Bytes

A 1ms USB Frame

SOF @6EP1 @5EP0 @6EP2

33 http://www.daqsystem.com

• USB pipes

• Device address is affected by the host • Endpoint configuration depends on the device implementation • Time multiplexing of transfer is under host control

Hub

Mouse

Disk On Key Control Transfer Bulk IN Transfer Bulk OUT Transfer

Ep0 Ep1 Ep2

Device Address 3

Control Transfer Iso IN Transfer Iso OUT Transfer

Control Transfer Interrupt IN Transfer Ep0

Ep3

Device Address 4

IP Phone Ep0 Ep1 Ep2

Device Address 5

Device Address 2

Host

Ep0 Ep1

Control Transfer

Interrupt IN Transfer

34 http://www.daqsystem.com

• Example of USB controller

35 http://www.daqsystem.com

• USB transactions

• A transfer is composed of one or several transactions • Example of control transfer (several transactions)

Example of bulk transfer (one transaction)

Setup Stage Data Stage

Status Stage

36 http://www.daqsystem.com

• USB Transactions (1)

• A transaction is made of 3 packets – Token: device address, endpoint number, transfer type – Data : data to be sent – Handshake: acknowledge

• Example of bulk transaction: Token Data Transfer Handshake

37 http://www.daqsystem.com

• USB Transactions (2)

• Example of bulk OUT transaction:

Device Address Endpoint Address

Host

Device

PID

Token

Data

Handshake

Token Data Transfer Handshake

38 http://www.daqsystem.com

• Summary

• The host affects an address to the device • The device has several endpoints • To each endpoint corresponds a pipe and a type of transfer • Transfer is made of one or several transactions • Transactions are composed of 3 packets

Pipe/Endpoint •Endpoint number •Endpoint type

Device •Device address

Offers

Transfer

Control Bulk Iso Int

2+ 1+ 1+ 1+

Transaction Token pkt Data pkt

Handshake pkt

Handles

39 http://www.daqsystem.com

• Control transfer

The device is not ready… The device does not acknowledge the transaction

The host retries… The device has Acknowledged the transaction

40 http://www.daqsystem.com

• USB scheduling(1)

• USB transfers occurs in a millisecond time-frame window • The host sends a Start Of Frame (SOF) Packet at the beginning of each frame • This is the host which starts a transfer with a logical peripheral • Transactions are time multiplexed in one or several frames • This is the host which do the transaction arbitration

Time

A 1ms USB Frame

SOF SOF SOF SOF @3 @5 @5 @5 @6 @6 @6 @2

-Host handles most of the protocol complexity -Peripheral design is simple and low-cost

41 http://www.daqsystem.com

• USB scheduling (2)

• The bus allocation depends on the host controller • A constant interval width is allocated to isochronous and interrupt

transfer • A minimum interval width is reserved for control transfer • The rest of interval is for bulk transfer

Control transfers

Iso + Interrupt transfer Bulk transfer

Fixed width Variable width Valible width

-A host can refuse a new peripheral which requests large isochronous transfer size -Such peripheral offers several configurations

42 http://www.daqsystem.com

• Theorically up to 1216 bytes can be transferred through a bulk endpoint in a frame

• In practice ~950 bytes

• Bandwidth

1ms frame

43 http://www.daqsystem.com

• Device detection

• The host (hub) downstream port integrates 2 pull-downs (15Kohms). The bus state is SE0 (DP = DM = 0V) • When a device is connected, the bus state is idle (DP = 3.3V DM = 0V). DP is forced by the device pull-up (1.5Kohms). • The hub/host detects the port status change and forces a bus reset to the new device (DP = 0V DM = 0V). • Then the host sends requests to the device through the default control endpoint (endpoint number 0). A newly

connected device address is 0.

DM

DP

15 Kohms

15 Kohms

3.3V

1.5 Kohms

DP

DM

HOST

Device

44 http://www.daqsystem.com

• Enumeration

Host Hub Device

Attached

Powered

Default

Addressed

Configured

Connect Cable Status Change

Query Change

Port Enable

Reset Device

Get Device Descriptor via default Pipe and Address

Assign a Unique Address

Read all Configuration Information

Configure and Assign Configuration Value

• Enumeration is the Process of Assigning Addresses and Setting Configurations

45 http://www.daqsystem.com

• Enumeration trace

Default Address, default control endpoint

Enter Address State

Enter Configured State

46 http://www.daqsystem.com

• USB Device State

After 3ms of bus inactivity the device must enter Suspended state and drain less than 500uA

47 http://www.daqsystem.com

• Standard requests

• A setup transaction includes an 8-byte formatted data packet

n Standard requests are defined in Chapter 9 of the USB spec

48 http://www.daqsystem.com

• Device USB driver components

USB Device driver API

Power Management

Attach/ Detach Processing

Status & Control

Control Protocol •Standard Requests •Class Requests •Vendor Requests

Endpoint Data •Transfer Protocols Bulk In/Out •Isochronous In/Out •Interrupt In/Out

Pull-Up Resistor

Clock Registers

USB Controller Registers

Endpoint FIFO Registers

49 http://www.daqsystem.com

• Device descriptor

• The USB Host stacks uses the descriptor retrieved from the device to find the corresponding driver.

• Windows looks for a matching Vendor ID/Product ID in its .inf library • If not found, it will search for a matching class driver • If not found then it will request the user to insert a CD to install the corresponding driver

Device Descriptor

Configuration Descriptor Configuration Descriptor

Interface Descriptor Interface Descriptor Interface Descriptor

Endpoint Descriptor

Endpoint Descriptor

Endpoint Descriptor

Endpoint Descriptor

Endpoint Descriptor

Endpoint Descriptor

50 http://www.daqsystem.com

• USB class drivers

• Building on top of the USB specifications, there are Device Class Specifications from the Device Working Group

• Matching device class requirements allow use of standard host class drivers provided by Windows or Linux

• Each class driver specifies the endpoint configurations required • Existing class drivers:

– Audio class (speakers, …) – HID (keyboard, mouse, …) – Mass Storage (disk on key) – Printer class – Smart Card CCID – Communication Data Class – …

51 http://www.daqsystem.com

Thanks!