usb-test

usb test


更新記錄

item note
20161026 第一版

目錄


The Linux USB sub-system

The Linux USB sub-system

  • The host uses a master / slave protocol to communicate with attached USB devices.
  • This means that every kind of communication is initiated by the host and devices cannot establish any direct connection to other devices.

USB Devices and Transfer Characteristics

  • USB host controllers

    • Open Host Controller Interface (OHCI, by Compaq)
    • Universal Host Controller Interface (UHCI, by Intel)
  • Data Flow Types

    • Data directed from the host to a device is called downstream or OUT transfer.
    • The other direction is called upstream or IN transfer
  • device type different transfer variants are used

    • Control transfers
      standard commands

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      GET_STATUS
      CLEAR_FEATURE
      SET_FEATURE
      SET_ADDRESS
      GET_DESCRIPTOR
      SET_DESCRIPTOR
      GET_CONFIGURATION
      SET_CONFIGURATION
      GET_INTERFACE
      SET_INTERFACE
      SYNCH_FRAME
    • Bulk transfers

    • Interrupt transfers
    • Isochronous transfers

Enumeration and Device Descriptors

  • Whenever a USB device is attached to the bus it will be enumerated by the USB subsystem
  • i.e an unique device number (1-127) is assigned and then the device descriptor is read.

Human Interface Devices (HID)

The HID class consists primarily of devices that are used by humans to control the operation of computer systems

  • ex
    1
    2
    Keyboards and pointing devices for example, standard mouse devices, trackballs, and joysticks.
    Front-panel controls for example: knobs, switches, buttons, and sliders.

USB Test

kernel config

Linux version 3.4.35_hi3535
記得開啟kernel config(CONFIG_USB_DEVICEFS=y)

1
mount -t usbfs none /proc/bus/usb -o devmode=0666

log

  • lsusb -v -d 1a86:5523
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    $ sudo lsusb -v -d 1a86:5523

    Bus 001 Device 006: ID 1a86:5523 QinHeng Electronics CH341 in serial mode, usb to serial port converter
    Device Descriptor:
    bLength 18
    bDescriptorType 1
    bcdUSB 1.10
    bDeviceClass 255 Vendor Specific Class
    bDeviceSubClass 0
    bDeviceProtocol 2
    bMaxPacketSize0 8
    idVendor 0x1a86 QinHeng Electronics
    idProduct 0x5523 CH341 in serial mode, usb to serial port converter
    bcdDevice 3.04
    iManufacturer 0
    iProduct 0
    iSerial 0
    bNumConfigurations 1

    Configuration Descriptor:
    bLength 9
    bDescriptorType 2
    wTotalLength 39
    bNumInterfaces 1
    bConfigurationValue 1
    iConfiguration 0
    bmAttributes 0x80
    (Bus Powered)
    MaxPower 96mA
    Interface Descriptor:
    bLength 9
    bDescriptorType 4
    bInterfaceNumber 0
    bAlternateSetting 0
    bNumEndpoints 3
    bInterfaceClass 255 Vendor Specific Class
    bInterfaceSubClass 1
    bInterfaceProtocol 2
    iInterface 0
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x82 EP 2 IN
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0020 1x 32 bytes
    bInterval 0
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x02 EP 2 OUT
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0020 1x 32 bytes
    bInterval 0
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x81 EP 1 IN
    bmAttributes 3
    Transfer Type Interrupt
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0008 1x 8 bytes
    bInterval 1
    Device Status: 0x0000
    (Bus Powered)

example (FT232)

  • FT232

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Device Descriptor:
    | bNumConfigurations (1)
    |---------------------------------------
    |
    Configuration Descriptor:
    | bNumInterfaces (1)
    |
    |----------------------------
    |
    Interface Descriptor:
    | bNumEndpoints (2)
    |
    |----------------------------------------------------
    | |
    Endpoint Descriptor: Endpoint Descriptor:
  • lsusb -v -d 0403:6001

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    $ lsusb -v -d 0403:6001

    Bus 001 Device 012: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
    Couldn't open device, some information will be missing
    Device Descriptor:
    bLength 18
    bDescriptorType 1
    bcdUSB 2.00
    bDeviceClass 0 (Defined at Interface level)
    bDeviceSubClass 0
    bDeviceProtocol 0
    bMaxPacketSize0 8
    idVendor 0x0403 Future Technology Devices International, Ltd
    idProduct 0x6001 FT232 Serial (UART) IC
    bcdDevice 6.00
    iManufacturer 1
    iProduct 2
    iSerial 3
    bNumConfigurations 1
    Configuration Descriptor:
    bLength 9
    bDescriptorType 2
    wTotalLength 32
    bNumInterfaces 1
    bConfigurationValue 1
    iConfiguration 0
    bmAttributes 0xa0
    (Bus Powered)
    Remote Wakeup
    MaxPower 90mA
    Interface Descriptor:
    bLength 9
    bDescriptorType 4
    bInterfaceNumber 0
    bAlternateSetting 0
    bNumEndpoints 2
    bInterfaceClass 255 Vendor Specific Class
    bInterfaceSubClass 255 Vendor Specific Subclass
    bInterfaceProtocol 255 Vendor Specific Protocol
    iInterface 2
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x81 EP 1 IN
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0040 1x 64 bytes
    bInterval 0
    Endpoint Descriptor:
    bLength 7
    bDescriptorType 5
    bEndpointAddress 0x02 EP 2 OUT
    bmAttributes 2
    Transfer Type Bulk
    Synch Type None
    Usage Type Data
    wMaxPacketSize 0x0040 1x 64 bytes
    bInterval 0

其它

FTDI: Simplified Description of USB Device Enumeration

  • 名詞定義
    USB: Universal Serial Bus
    USBDP: USB Data line plus
    USBDM: USB Data line minus
    USB HOST: The port that controls the USB interface - the master
    USB Device: The peripheral that connects to the USB host port - the slave

參考