usb tutorial[1]

Upload: ajoaomv

Post on 14-Apr-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 USB Tutorial[1]

    1/29

    1

    USB Tutorial

  • 7/27/2019 USB Tutorial[1]

    2/29

    2

    USB Tutorial

    Objectives Review USB functionalities

    Be able to read a USB trace

    Understand the enumeration process

    Highlight that class drivers are part of the USB success

  • 7/27/2019 USB Tutorial[1]

    3/29

    3

    USB Tutorial

    Few generalities on USB Tiered start topology

    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

    Host

    HUB

    HUB

    Root Hub

    Keyboard

    Speaker

    Disk

    Printer

  • 7/27/2019 USB Tutorial[1]

    4/29

    4

    USB Tutorial

    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

  • 7/27/2019 USB Tutorial[1]

    5/29

    5

    USB Tutorial

    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

    HOSTHub @: 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

  • 7/27/2019 USB Tutorial[1]

    6/29

    6

    USB Tutorial

    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 Di rec tion Packets per fram e M ax Packet Size

    Control Bidir Several 64 Bytes

    Bulk Unidir Several 64 BytesIsochronous Unidir One 1024 Bytes

    Interrupt Unidir One max 64 Bytes

    A 1ms USB Frame

    SOF @6EP1@5EP0 @6EP2

  • 7/27/2019 USB Tutorial[1]

    7/297

    USB Tutorial

    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 KeyControl TransferBulk IN TransferBulk OUT Transfer

    Ep 0Ep 1Ep 2

    Device Address 3

    Control Transfer

    Iso IN TransferIso OUT Transfer

    Control TransferInterrupt IN Transfer Ep0

    Ep 3

    Device Address 4

    IP Phon eEp 0Ep 1Ep 2

    Device Address 5

    Device Address 2

    Host

    Ep 0Ep 1

    Control Transfer

    Interrupt IN Transfer

    Logical Pipe

  • 7/27/2019 USB Tutorial[1]

    8/298

    USB Tutorial

    Example of USB controller

  • 7/27/2019 USB Tutorial[1]

    9/299

    USB Tutorial

    USB transactions A transfer is composed of one or several transactions

    Example of control transfer (several transactions)

    Example of bulk transfer (one transaction)

    Setup StageData Stage

    Status Stage

  • 7/27/2019 USB Tutorial[1]

    10/2910

    USB Tutorial

    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

  • 7/27/2019 USB Tutorial[1]

    11/2911

    USB Tutorial

    USB Transactions (2) Example of bulk OUT transaction:

    Device Address

    Endpoint Address

    Host

    Device

    PID

    Token

    Data

    Handshake

    Token Data Transfer Handshake

  • 7/27/2019 USB Tutorial[1]

    12/2912

    USB Tutorial

    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

    DeviceDevice address

    Offers

    Transfer

    Control Bulk Iso Int

    2+ 1+ 1+ 1+

    Transaction

    Token pkt

    Data pkt

    Handshake pkt

    Handles

  • 7/27/2019 USB Tutorial[1]

    13/2913

    USB Tutorial

    Control transfer

    The device is not ready

    The device does not

    acknowledge the transaction

    The host retries

    The device hasAcknowledged the transaction

  • 7/27/2019 USB Tutorial[1]

    14/2914

    USB Tutorial

    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

  • 7/27/2019 USB Tutorial[1]

    15/2915

    USB Tutorial

    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

    Controltransfers

    Iso + Interrupt transfer Bulk transfer

    Fixed width Variable widthValible width

    -A host can refuse a new peripheral which requestslarge isochronous transfer size

    -Such peripheral offers several configurations

  • 7/27/2019 USB Tutorial[1]

    16/2916

    USB Tutorial

    Theorically up to 1216 bytes can be transferred through a bulk

    endpoint in a frame

    In practice ~950 bytes

    Bandwidth

    1ms frame

  • 7/27/2019 USB Tutorial[1]

    17/2917

    USB Tutorial

    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 busreset 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

  • 7/27/2019 USB Tutorial[1]

    18/2918

    USB Tutorial

    Enumeration

    Host Hub Device

    Attached

    Powered

    Default

    Addressed

    Configured

    Connect CableStatus Change

    Query Change

    Port Enable

    Reset Device

    Get Device Descriptor via default Pipe and Address

    Assign a Unique AddressRead all Configuration Information

    Configure and Assign Configuration Value

    Enumeration is the Process of Assigning Addresses and Setting

    Configurations

  • 7/27/2019 USB Tutorial[1]

    19/2919

    USB Tutorial

    Enumeration traceDefault Ad dress, default con trol endpo int

    Enter Ad dress State

    Enter Conf igu red State

  • 7/27/2019 USB Tutorial[1]

    20/2920

    USB Tutorial

    USB Device State

    After 3ms of bu s inact iv i tythe device mus t enter

    Suspended state and d rain lessthan 500uA

  • 7/27/2019 USB Tutorial[1]

    21/2921

    USB Tutorial

    Standard requests A setup transaction includes an 8-byte formatted data packet

    Standard requests are defined in Chapter 9 of the USB spec

  • 7/27/2019 USB Tutorial[1]

    22/2922

    USB Tutorial

    Host software architecture

    Host

    Controller

    regs

    Host Controller Driver (HCD)

    OHCI-UHCI-EHCI

    USB Protocol Driver API

    MS HUB EtcHID

    Linux and WIN CE provide

    OHCI/UHCI/EHCI HCD driver

    USBD Driver

    Main class drivers: Hub, HID, Mass storage, Printer,

    Symbian and RTOS does notprovide USB host stack driver

    SW IPs providers are able toprovide solutions for RTOS

    Softconnex, Philog,

    Expensive: (65k$ for a mass

    storage solution)It is still possible to build a minihost from our full host:

    the SW is only able to drivesome kinds of devices

  • 7/27/2019 USB Tutorial[1]

    23/2923

    USB Tutorial

    Device USB driver components

    USB Device driver API

    PowerManagement Attach/DetachProcessing

    Status&Control

    Control ProtocolStandard RequestsClass Requests

    Vendor Requests

    Endpoint DataTransfer ProtocolsBulk In/Out

    Isochronous In/Out

    Interrupt In/Out

    Pull-UpResistorClockRegisters USB ControllerRegistersEndpoint FIFO

    Registers

  • 7/27/2019 USB Tutorial[1]

    24/2924

    USB Tutorial

    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

    EndpointDescriptor

    EndpointDescriptor

    EndpointDescriptor

    EndpointDescriptor

    EndpointDescriptor

    EndpointDescriptor

  • 7/27/2019 USB Tutorial[1]

    25/29

    25

    USB Tutorial

    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

    -

  • 7/27/2019 USB Tutorial[1]

    26/29

    26

    USB Tutorial

    Objectives

    Review USB functionalities

    Be able to read a USB trace

    Understand the enumeration process

    Highlight that class drivers are part of the USB success

  • 7/27/2019 USB Tutorial[1]

    27/29

    27

    USB Tutorial

    What is happening?

    Transact ion NACKed by the device

  • 7/27/2019 USB Tutorial[1]

    28/29

    28

    USB Tutorial

    What is the physical topology?

    How many device connected?

    Which device answers?

    Where is connected the bus analyser?

  • 7/27/2019 USB Tutorial[1]

    29/29

    USB Tutorial

    Answer

    HUB

    Device Nb 3

    Device Nb 2

    New Device

    Bus Analyzer

    USB Wire

    D

    ownstreamPorts

    UpstreamPort

    The bus analyzer logs all downstream packets from the hostand only upstream packets from the new device