1 / 58

Embedding USB technology Limitations , challenges and compliance

Embedding USB technology Limitations , challenges and compliance. USB Device, enumeration and classes. November 29 2012 Christian Légaré. Enumeration. Device attachment. Once the device is attached, enumeration starts Host requests a number of data structures called descriptors

richardr
Download Presentation

Embedding USB technology Limitations , challenges and compliance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedding USB technologyLimitations, challenges and compliance USB Device, enumeration and classes November 29 2012Christian Légaré

  2. Enumeration Device attachment • Once the device is attached, enumeration starts • Host requests a number of data structures called descriptors • Enumeration occurs on the default bidirectional endpoint 0 • Host assigns a unique 7-bit address to the device Reset device Get device descriptor Reset device Assign address Get configuration descriptor Get other descriptors Select device driver Set Configuration

  3. Descriptors Device Descriptor: bcdUSB: 0x0110 bDeviceClass: 0x00 bDeviceSubClass: 0x00 bDeviceProtocol: 0x00 bMaxPacketSize0: 0x08 (8) idVendor: 0x058F idProduct: 0x9380 bcdDevice: 0x0100 iManufacturer: 0x01 iProduct: 0x02 iSerialNumber: 0x00 bNumConfigurations: 0x01 ConnectionStatus: DeviceConnected Current Config Value: 0x01 Device Bus Speed: Full Device Address: 0x04 Open Pipes: 2 Endpoint Descriptor: bEndpointAddress: 0x01 Transfer Type: Bulk wMaxPacketSize: 0x0040 (64) bInterval: 0x00 Endpoint Descriptor: bEndpointAddress: 0x00 Transfer Type: Control wMaxPacketSize: 0x0507 (1287) wInterval: 0x0282 bSyncAddress: 0x40 • Describes attributes about the peripheral • Peripherals typically have more than one descriptor • It is typically stored in an EEPROM in the device’s circuit • There are few types of descriptors: • Standard • Class • Vendor • Among the standard descriptors: • Device descriptor - general information about device • Configuration descriptor - device configuration • Interface descriptor – number of endpoints • Endpoint descriptor - properties of an endpoint

  4. Valid request sequence • Device states • Default • After reset but before receiving Set Address. • In the Default state, the only valid requests are Get Descriptor, and Set Address. • Addressed • After the device has been assigned an address via Set Address. • Now the device must recognize the following additional requests: • Get Configuration • Set Configuration • Set Feature • Clear Feature • Get Status • Set Descriptor (optional) • Configured • After the host has sent Set Configuration with a non-zero value, to select a configuration. The device is now operational. • In the Configured state, only Set Address is not a valid request. Three additional requests are restricted to Configured state only: • Get Interface • Set Interface • Synch Frame • This is only a brief overview. The complete USB specifications is a lot more complex and complete.

  5. Enumeration Device Descriptor General Configuration Descriptor 1 Interface 0 Descriptor Endpoint Descriptor 1 Configuration Descriptor 1 wTotalLength Endpoint Descriptor 2 Interface 1 Descriptor Endpoint Descriptor 1 Endpoint Descriptor 2 HID Configuration Descriptor 2 Configuration Descriptor 2 wTotalLength Interface 0 Descriptor HID Descriptor Endpoint Descriptor 1 Configuration Descriptor n…

  6. Standard descriptor requests A control transfer starts with a SETUP transaction which conveys 8 bytes. These 8 bytes define the request from the host. Token Packet Handshake Packet Data Packet CRC5 ENDP DATA0 CRC16 8 bytes SETUP DATA ADDR ACK SETUP 1 SETUP transaction From Host From Device

  7. Standard descriptor requests The SETUP transaction data is divided into five fields

  8. Standard requests Host standard requests. The first 5 columns are the SETUP transaction fields in order, and the last column describes any accompanying data stage data which will have the length wLength.

  9. Get Descriptor Get device descriptor First request received by the Device (with the descriptor type set to Device) , just after the first USB reset. Table of wValues defining the descriptor type.

  10. Device descriptor

  11. SET ADDRESS Assign address The host issues a SET_ADDRESS request to the device, so that each device on the bus has a unique address to respond to. SET_ADDRESS is a simple, outward direction request in a control transfer with no data stage. The only useful information carried in the SETUP packet is the required address. When implementing this request in firmware: • All other requests must be answered before the status stage is completed. • In the case of SET_ADDRESS, the device address should not change until after the status stage. The status stage will not succeed unless the device is still responding to address 0 while it is taking place. • The device then has 2ms to get ready to respond to the new address.

  12. Get Descriptor (Configuration) Get configuration descriptor • The Get Descriptor (Configuration) returns a Configuration Descriptor and some or all of a number of other descriptors: • Interface Descriptor • Endpoint Descriptor • OTG Descriptor • Class-specific Descriptors • Vendor-specific Descriptors • A Get Configuration Descriptor fetches the descriptors for just one configuration depending on the descriptor index in wValue of the SETUP packet. Most devices only have one configuration, because built-in Windows drivers always select the first configuration. • The position of class descriptors is defined in the appropriate class specification, and of course vendors descriptor positions would be up to the vendor concerned. • An OTG descriptor position is not defined but typically appears immediately after the configuration descriptor.

  13. Configuration Descriptor Configuration descriptor format

  14. Interface Association Descriptor (IAD) Get other descriptors Interface association descriptor format

  15. Interface Association Descriptor (IAD)Multi-interface Function Device Class Codes The Device Descriptor must contain the Multi-interface Function Device Class Codes for the host to identify devices that use IAD: bDeviceClass = 0xEF (miscellaneous device class) bDeviceSubClass = 0x02 (common class) bDeviceProtocol = 0x01 (interface association descriptor) Video Class and Audio 2.0 devices must use IAD. IAD precedes the interface descriptors that the IAD specifies. The interface numbers of associated interfaces must be contiguous.

  16. Interface Descriptor Get other descriptors Interface descriptor format

  17. Endpoint Descriptor Get other descriptors

  18. Get Descriptor (String) Get other descriptors • There are several strings which a host may request. The strings defined in the device descriptor are: • Manufacturer String • Product String • Serial Number String • These strings are optional. If not supported, the corresponding index in the device descriptor will be 0. Otherwise the host may use the specified index in a Get Descriptor (String) request to fetch the descriptor. • Get Descriptor (String), with a descriptor index of 0 in the low byte of wValue, is used to fetch a special string language descriptor. This contains a series of 2-byte sized language identifiers. In theory, if the language of your choice is supported in this list, you can use the index to this language ID to access the string descriptors in this language by specifying this in wIndex of the Get Descriptor (String) request. In practice, with Windows, you will have difficulties if you do not ensure that the first language specified is English (US).

  19. String Descriptor String Descriptor Zero(Specifies supported string languages) String Descriptor

  20. SET_CONFIGURATION Set Configuration When the host has got all the information it requires it loads a driver for the device based on the VID/PID combination in the device descriptor, or on the standard class defined there or in an interface descriptor. The driver may also ask for the same or different information using Get Descriptor requests. Eventually it will decide to configure the device using the SET_CONFIGURATION request. Usually ( when there is one configuration) the Set Configuration request will have wValue set to 1, which will select the first configuration. Set Configuration can also be used, with wValue set to 0, to deconfigure the device. GET_CONFIGURATION • This request compliments Set Configuration, and simply allows the host to determine which configuration it previously set.

  21. Configured Device Once a device has been configured, it is allowed to respond to other transfer types than Control transfers. The other transfer types are • Interrupt Transfers • Bulk Transfers • Isochronous Transfers There may now also be new class or vendor-specific requests which may now be supported on the control endpoint in addition to the standard requests. All these additional transfers perform the functionality that the device was designed for.

  22. Other enumeration messages

  23. Device Driver Select device driver The host loads the appropriate driver using a PID/VID (Product ID/Vendor ID) combination used during the enumeration. [Windows] Abstract from a .inf file: [DeviceList] %USB\VID_8765&PID_1234.DeviceDesc%=USBBulkInstall, USB\VID_8765&PID_1234

  24. HID Enumeration Request for Device Descriptor Request for Report Descriptor Set Configuration Request for Configuration Descriptor USB Host (PC) MCU HID Driver CONTROL pipe Endpoint 0 (EP0) CONTROL endpoint Reply with Device Descriptor Reply with Configuration Descriptor(s) Reply with Interface Descriptor(s) Reply with Endpoint Descriptor Reply with HID Descriptor Reply with Report Descriptor IN Packet Endpoint 3 (EP3) INTERRUPT-IN endpoint INTERRUPT-IN pipe IN Report Connect USB cable

  25. USB Functions The USB standard makes references to USB functions which can be seen as USB devices which provide a capability or function such as a Printer, Mass Storage Drive, Scanner, Modem or other peripheral. In Software, Classes implements the Functions.

  26. A USB Class describes a group of devices or interfaces with similar attributes or services. It is a software interface for common devices. A Class Specification defines the requirements for such a related group. A single device can belong to multiple classes Currently more than 13 device classes specified by the USB specification, and growing (plus the subclasses) Class

  27. Approved Class Specification Documents Source: http://www.usb.org/developers/devclass_docs#approved

  28. Approved Class Specification Documents Source: http://www.usb.org/developers/devclass_docs#approved

  29. Approved Class Specification Documents Source: http://www.usb.org/developers/devclass_docs#approved

  30. Host Driver support Windows • Windows supports most of the USB classes with the exception of DFU, IrDA bridge, Personal Healthcare, Test and Measurement.

  31. Windows Source: http://www.microsoft.com/whdc/connect/usb/USBFAQ_intro.mspx

  32. Windows Source: http://www.microsoft.com/whdc/connect/usb/USBFAQ_intro.mspx

  33. Linux Source: http://www.linux-usb.org/devices.html

  34. MacOS The Apple USB Class Drivers are based on the Device Class Specifications that are available from the USB-IF Device Class Documents web page. Source: http://developer.apple.com/mac/library/qa/qa2004/qa1370.html

  35. Very Popular Classes

  36. Human Interface Device (HID) • HID exchange data in reports • Introduction of a Report Descriptor • Size of each report data • Usage values for report data • HID Usage Tables contains Usage-tag values for • Keyboards, pointing devices, game controllers, displays, telephone controls and more • Class Definition for Physical Interface Devices (PID) • Force-feedback joysticks

  37. Human Interface Device (HID) • Montior Control • Display user controls and power management • Usage Tables for HID Power Devices • Typical usage is UPS devices • Other devices where the host monitors and controls batteries or other power components • Point of Sale (POS) Usage Tables • Barcode reader, weighing devices and magnetic stripe reader

  38. Human Interface Device (HID) Device Descriptor Configuration Descriptor 1 Interface 0 Descriptor Endpoint Descriptor 1 Endpoint Descriptor 2 Report Descriptor 1 Report Descriptor n

  39. Mass Storage Mass Storage communications are complex Many possible transport protocols Recommended to Use bulk transfer to exchange data Use bInterfaceSubClass = 0x06 (generic SCSI Media) bInterfaceProtocol = 0x50 (bulk-only) Have a serial number in a USB string descriptor Allows to retain the driver letter and access policies when moving the MSD or having mutliple MSD with the same VendorID and ProductID

  40. Mass Storage Mass storage has 2 or 3 stages: • Command transport • Data transport (optional) • Status transport • Command Block Wrapper (CBW) • Data • Command Status Wrapper (CSW)

  41. Mass StorageCommand Block Wrapper

  42. Mass StorageCommand Status Wrapper

  43. Personal Healthcare Personal Healthcare Devices may send data that is episodic Data can be collected and stored and transmitted to the host only when connected Examples: heart-rate monitor blood-pressure monitor glucose meter pulse oximeter motion sensors pill monitors

  44. Personal Healthcare Device Descriptor Configuration Descriptor Interface Descriptor Endpoint Descriptor Bulk IN QoS Descriptor Optional MetaData Descriptor Endpoint Descriptor Bulk OUT QoS Descriptor Optional MetaData Descriptor Optional Endpoint Descriptor Interrupt IN QoS Descriptor Optional MetaData Descriptor Function Descriptor Function Extension Descriptor

  45. Communications Telecommunications • Virtual COM-port • Analog phones and modems • Digital phones (including cell phones) • ISDN terminal adapters Networking • ADSL modems • Cable modems • Ethernet adapters and hubs

  46. Communications SubClasses • ATM – Asynchronous Transfer Mode • EEM – Ethernet Emulation Model • ECM – Ethernet Control Model • ISDN – Integrated Service Digital Network • PSTN – Public Switched Telephone Network • WMC – Wireless Mobile Communications • Microsoft defined Network Driver Interface Specification (NDIS) for using USB and other buses to configure network interfaces and carry Ethernet data. Remote NDIS defines a protocol to manage communications with network adapters and higher-level drivers. NDIS and RNDIS are supported on Windows only.

  47. Communications Device Descriptor bDeviceClass = 02h Device Descriptor bDeviceClass = EFh bDeviceSubclass = 02h bDeviceProtocol = 01h OR Configuration Descriptor Configuration Descriptor Interface Association Descriptor Communication Interface Other Interface for Data (content) and corresponding descriptors Data Interface OR Bulk or Interrupt Network control Endpoint Bulk or Isochronous Endpoint Header Function Descriptor Bulk or Isochronous Endpoint Function-Specific Functional Descriptor … Function-Specific Functional Descriptor … Optional

  48. Communications CDC are often composite devices • For example, network control generally use an interrupt pipe. • Data interface use bInteraceClass = 0x0A • For performance, some Virtual-COM port devices use vendor specific drivers and thus cannot be considered as part of the communications device class.

  49. Communications - Interface Descriptor bInterfaceSubClass

  50. Communications - Interface Descriptor bInterfaceProtocol

More Related