Books USB: The Universal Serial Bus Books

Benjamin David Lunt

 

This is a Frequently Asked Question (FAQ) list for USB driver/device development as a companion to USB: The Universal Serial Bus: Volume 8.

This is a list of FAQs about developing software drivers, testing your code, and other questions related to what you read within the book.

If you are looking for Frequently Asked Questions about the book itself, please see the main page for the book.

These answers are to the best of my knowledge. Any errors or omission are unintentional and you should refer to the associated specification for accuracy.

 


This FAQ list is under construction. Please bear with me.


General:
  1. Which controller should I start with?
  2. What emulators support USB?
  3. How do I write and boot my operating system from a USB thumb drive on real hardware?
  4. How do I know what controllers are on my machine?
  5. What is an HID device?
  6. What is an MSD device?
  7. If my device is USB 3.0 compatible, does this indicate that my device is super-speed?
  8. Where can I find the USB specification?
  9. Where can I find the USB Class codes?
UHCI:
  1. Where can I find the UHCI specification?
OHCI:
  1. Where can I find the OHCI specification?
EHCI:
  1. Where can I find the EHCI specification?
  2. What are Companion Controllers?
  3. What are Rate Matching Hubs?
  4. Why won't the EHCI recognize my Mouse?
  5. If I have a machine with one or more EHCI controllers, will I still be able to program for the UHCI or OHCI with little or no knowledge on EHCI controllers?
xHCI:
  1. Where can I find the xHCI specification?
  2. Can I plug a super-speed device into a UHCI root hub and will my UHCI driver see the device?
  3. If I only have a Super-speed controller, will I still be able to program for the Low-speed mouse and keyboard?

General:
  1. Which controller should I start with?
  2. I have mixed feelings about this question. The UHCI and OHCI were released first, though nearly 30 years ago. UHCI in November of 1995 and OHCI a month later. Though most modern emulators will still support these two controllers, most modern hardware will not. The xHCI controller was announced in September of 2007, and is still more than 15 years old, though USB version 3.2 which takes advantage of xHCI, and is more recent, is still a little more than 5 years ago.

    To decide which controller you would like to start with, ask yourself one question: Will I be testing my code on real hardware or using emulation exclusively?

    If your answer is emulation, I suggest the UHCI and OHCI as your beginning. One controller was built to use the hardware with little software intervention, while the other was completely the opposite. It would be a good learning experience to code for both of them to learn the difference. Also, the Bochs emulator, which I'm glad to have had a big part of during that time, will produce a nice debug log file, which is quite helpful in the beginning of your development.

    Next, in my humble opinion, completely skip the EHCI. Again IMHO, it was a hodge-podge piece of hardware put together to allow higher speed devices, but still be backward compatible with UHCI and OHCI. Other than reading over the subject, getting an idea of what it does, I would completely skip the EHCI.

    xHCI, in my opinion, finally got the interface correct. xHCI will support all speeds using this one interface. However, to do so, unlike the UHCI and OHIC where there was a single bit indicating the different speed, xHCI needs quite a bit of setup before allowing that specific speed.
  3. What emulators support USB?
  4. Bochs
    Controllers: UHCI, OHCI, EHCI, and XHCI.
    Emulated devices: Mice, Keyboard, Tablet, Keypad, Floppy, Hard drive, CD-ROM, Printer, external Hub.
    Bochs supports a detailed debugging interface for USB, starting with simple log file entries to an (experimental and evolving) Debugging interface that halts emulation allowing the user to manipulate the USB.
    Bochs supports the MSD Bulk/Bulk/Bulk interface and an (experimental) UASP interface.
    Bochs includes an irregular HID Report for a mouse to test your HID Parser.
  5. QEMU (for Windows)
    Controllers: UHCI, OHCI, EHCI, and XHCI.
    Emulated devices: Mice, Keyboard, Tablet, Keypad, Floppy, Hard drive, CD-ROM, Printer, external Hub, as well as some non-common devices such as a serial port, braille, network card, ccid, audio, and a few others.
    QEMU supports the MSD Bulk/Bulk/Bulk interface and a UASP interface.
  6. VirtualBox
    Controllers: UHCI, OHCI, EHCI, and XHCI. (must install the extension package)
    Devices: VirtualBox allows you to use the Host's physically attached devices. It does not emulate a USB device. This can be a problem for begginers.
    VirtualBox does not support the UHCI.
  7. VMWare
    Controllers: UHCI, OHCI, EHCI, and XHCI.
    Devices: I have not used VMWare, so I don't know.
    VMWare does not support the OHCI. (?)
  8. How do I write and boot my operating system from a USB thumb drive on real hardware?
  9. First, you need an image file that represents a 1.44meg floppy disk or a MBR partitioned image with at least one active partition. To be sure your image will be booted by the BIOS, you must format the floppy image/partitions to a common, known file system, usually a FAT-12, -16, or -32 formatted partition. If you do not use a FAT formatted partition, some BIOSes will not recognize the format and refuse to boot the USB drive. Therefore, to be most compatible, use a FAT formatted drive.

    However, this means that your operating system, or at least the loader, must understand the FAT file system format. This means that your boot code must use a FAT BPB and know how to parse the FAT root directory and FAT table to find the loader. Doing this has an advantage, you now can copy files back and forth to/from this USB thumb drive between your operating system and your host development machine.

    Second, to easily write the floppy or hard drive image file to the USB thumb drive, use either usbimager or rufus. The former can be used on various platforms including Windows and Linux, while the latter is Windows only. You supply the path to the image file in question and the thumb drive indicator (ex, 'E:' in Windows), and either utility will do the rest.

    One more thing, make the the thumb drive is of standard or high quality. A sub-standard (cheap-o, dime-a-dozen) thumb drive tend to not function properly when LBA 0 is read too many times. I don't know why, but have seen it often with cheap hardware. Therefore, by a good brand-name thumb drive. A smaller storage sized 16Gig Sandisk is about $8US, give or take.
  10. How do I know what controllers are on my machine?
  11. Your code must first enumerate the PCI(e) Bus to find any USB compatible controllers. You do this by checking each available device structure within the PCI address space for a USB compatible type and protocol. This is explained in detail in Chapter 2.
  12. What is an HID device?
  13. HID stands for Human Interface Device, and is most any device that interacts with the user to perform a certian function. HID devices may have an HID report that your driver might parse to determine what parts of the human body are used for what purposes. For example, part of the report might state the the index finger on the right hand will manipulate a mouse button. HID device can range from simple three-button mice to elaborate devices such as haptic feedback steering wheels. Most common HID devices are mice and keyboards. You can get the HID specification from here and the Usage Tables from here.
  14. What is an MSD device?
  15. MSD stands for Mass Storage Device, and is usually a storage device such as a thumb-drive, hard drive, CD-ROM, or floppy drive. Most MSD devices support the BBB, or Bulk/Bulk/Bulk interface, also called Bulk only Transport (BoT). Newer device might support the UASP protocol which takes advantage of the xHCI streams and can transfer data at a much higher rate. You can get the MSD specification from here (v1.4 February 2010).
  16. If my device is USB 3 compatible, does this indicate that my device is super-speed?
  17. Not necassarily. Being USB 3.0 compatible does not mean the device can opperate at super-speed. The USB version specification of the device does not specify the speed of the device. A low-speed mouse can be USB 2.0 compliant where as a super-speed MSD device can in fact be USB 1.1 compliant. The USB 2.0 low-speed mouse will operate at low-speed but follow all of the rules that pertain to USB 2.0 low-speed devices. The super-speed MSD device, when plugged in to a UHCI root hub, will be USB 1.1 compliant and should operate at full-speed.

    However, any device must at least enumerate. After enumeration, it can refuse to function if the controller it is plugged in to doesn't support the interface presented to the host. For example, if this same USB 3.0 super-speed device only supports UASP and streams, it will at least enumerate on a UHCI port, but will not do anything else since the UHCI/MSD driver(s) don't understand UASP and streams. All devices must support the Control Pipe, the pipe that is used to enumerate the device. Any other pipes are optional depending on the compatiblility of the device and the port it is plugged in to.
  18. Where can I find the USB specification?
  19. The USB specifications can be aquired from the USBIF website, with the latest from here (.zip file) (USB 4v2).
  20. Where can I find the USB Class codes?
  21. The USB Class codes can be found here.

UHCI:
  1. Where can I find the UHCI specification?
  2. The UHCI specification is officially from Intel, but the most common place I have seen is from here (v1.1 March 1996).

OHCI:
  1. Where can I find the OHCI specification?
  2. The OHCI specification is officially from Compaq, Microsoft, and National Semiconductor, and can be found here (.zip file) (v1.0a Sept 1999).

EHCI:
  1. Where can I find the EHCI specification?
  2. The EHCI specification is officially from Intel, and you can get it from them here (v1.0 March 2002).
  3. What are Companion Controllers?
  4. What are Rate Matching Hubs?
  5. Why won't the EHCI recognize my Mouse?
  6. The EHCI only handles High Speed devices. The (standard) EHCI will not communicate with a Full or Low speed device. Therefore, the EHCI's card was designed to have companion controllers, either OHCI or UHCI, to pass on the Full- and Low-speed device traffic. Therefore, each EHCI adapter card had all of the EHCI components and at least one, though usually more than one OHCI or UHCI component. These got a little expensive. Since a common External Hub should be able to have any speed device plugged in to it, the Hub has to handle the speed difference. Therefore, if you plug a High-Speed Hub into an EHCI and then plug all other devices into the HUB, the EHCI adapter card no longer needs the added UHCI or OHCI components. Even better, if you place the external hub directly on the EHCI adapter card, this guarantees that the lower speed controllers are no longer needed. This dramatically decreased the cost as well as the circuity of the EHCI adapter card. The drawback for you and I, as the developer, it is now a requirement that we have a HUB driver in our USB tool box. We can't even get to the Low-speed mouse without it. Another reason to completely skip the EHCI. (EHCI's now include Transaction Translators (TTs) to allow low- and full-speed devices as well.)
  7. If I have a machine with one or more EHCI controllers, will I still be able to program for the UHCI or OHCI with little or no knowledge on EHCI controllers?
  8. Yes. Except for the Rate Matching Hub setup (or TTs) explained above, all EHCI controllers will have at least one UHCI or OHCI controller attached. At bootup, most BIOSes will initialize the EHCI to use these companion controllers by default, allowing your UHCI or OHCI driver to recognize the controller and use an attached Low- or Full-speed device. However, check your system's BIOS setup to be sure.

xHCI:
  1. Where can I find the xHCI specification?
  2. The xHCI specification is officially from Intel, and you can get it from them here (v1.2 May 2019).
  3. Can I plug a super-speed device into a UHCI root hub and will my UHCI driver see the device?
  4. Yes. All USB devices must at least enumerate on the port, no matter the speed of the port or the device. Once a device is enumerated, if the controller doesn't support a given interface, the driver simply reports an error. However, most standard devices will function just fine on a lower speed root hub port. They will simply be slower, in some cases, much slower. An example of when you cannot plug a super-speed device into a lower speed hub, is when the super-speed device uses a Type-C connector, obviously.
  5. If I only have a Super-speed controller, will I still be able to program for the Low-speed mouse and keyboard?
  6. Yes. In one form or another, each controller is backward compatible allowing for any speed device to be plugged in to and used on that controller. My book shows in detail how this is done with each controller.