USB : Overview    USB Facts of Life  

Page 1


It’s important to understand that USB is a Master/Slave technology. The PC is the Master, and your peripheral device is the Slave.

The PC "polls" the peripheral device: it can send OUT data to the device any time it wants, and the PC expects to be able to read IN data from the device any time it wants. The device can only wait with its data until the PC host decides to ask the device for it. (Despite the fact that one of the USB transfer types is called “Interrupt” type, the slave device cannot actually interrupt the PC at all.)

This Master/Slave relationship between the PC Master and the peripheral Slave means that the USB hardware on each end is very different. A USB peripheral device does not have the right kind of USB hardware to command another USB peripheral, so please don’t expect to be able to turn your inexpensive microcontroller-based USB peripheral device into something that can control another USB device like a printer.

It can’t happen, unless you buy a more complicated micro that contains special hardware that can enable it to act as a USB "Host," and go through all the steps to program it to do all the extra work that a Host needs to do.





Page 2


Probably because the PC is the Master, the "IN" direction is defined as toward the PC host, and the "OUT" direction is defined as away from the PC host.

  Click on the image for page view.




Page 3


When the PC host senses that your USB peripheral device has been connected, the host sort of "taps the device in the shoulder" and asks the device to describe itself.

The peripheral device then provides all sorts of information about itself: who made it, how its Configurations, Interfaces, and Endpoints are organized (see the following slides if you're not familiar with these terms), and other information about the type of device it is and the amount and nature of the data that the device expects to send and receive.

The device provides this information to the PC in the form of tables of numbers called Descriptors.

The PC Host looks at this information very carefully. If it thinks the device is okay, then the Host will locate and run whatever device drivers may be needed for this device, then start exchanging data with the device as needed.

On the other hand, if the Host does NOT like what it sees, it will ignore the device and never start it up. Depending on the operating system version, it may give the user some indication that the device has a problem, but it won't tell what specifically is wrong.

  Click on the image for page view.




Page 4


A USB Endpoint is a little like an electrical terminal or a wiring junction for USB data in a USB peripheral device.

An Endpoint is a part of the hardware: usually a set of memory registers that can temporarily hold multiple bytes of data on their way in or out. A USB peripheral hardware device, like the PIC 18F4550 microcontroller, contains a limited number of Endpoints. Endpoints usually come in pairs, e.g. Endpoint 1 In and Endpoint 1 Out. The USB hardware does not have to be programmed to use all of its Endpoints.

One set of Endpoints that is special, which must always be turned on and always available, is the pair Endpoint 0 In and Endpoint 0 Out. These are used for the basic Control Transfers that communicate basic commands to all USB devices.

  Click on the image for page view.




Page 5


A USB Interface is one independent entity in a USB peripheral device that can send or receive, like what you would usually think of as being one device.

In Microsoft Windows software, an Interface is what your user-mode program can tell Windows to “open,” and with which your program can communicate.

Just like you can open multiple files at once, and read and write data to each one separately, Windows can open multiple Interfaces at one time, and communicate with each Interface separately.

  Click on the image for page view.




Page 6


Endpoints are assigned to Interfaces. An Interface's Endpoints provide the way that the Interface communicates with the PC. The choice of which Endpoint number gets assigned to a particular Interface is arbitrary, and is completely up to the designer of the peripheral device.

The simplest kind of USB devices only have a single Interface.

If you like, HIDmaker FS can easily make devices that have more than one Interface, and therefore more than one set of Endpoints. These are called USB Composite devices.

Usually, the separate Interfaces in a Composite device are used for separate kinds of functionality, like the Printer part of one of those Printer / Fax / Scanner combination devices you see at office supply stores.

However, you can also use extra Interfaces as just different data channels if you want.





Page 7


A USB Configuration is a container for one or more Interfaces in a USB peripheral device.

A USB Configuration seems to have been intended to be a kind of “setup” or “operating mode” for the device.

Most devices have only one Configuration, but it’s possible for a device to have more than one. (A device having more than one USB Configuration is called a "Complex" device.) Even so, such a device can only operate in one Configuration at a time.

  Click on the image for page view.




Page 8


Here are some examples of devices that could have more than one Configuration:

  • A device might be able to operate usefully by turning off some of its circuitry (and thus some of its functionality) if the USB controller cannot grant it all the supply current it needs. A device like that could offer a Low Power Configuration and a Full Power Configuration.

  • Another device might offer different Configurations to adjust its functionality according to the amount of USB bandwidth available.




Page 9


As defined by the USB specs (and especially as implemented by Microsoft in Windows), it’s not easy to change the device from one Configuration to another. There is no Microsoft API that a regular user-mode program can call to tell a USB device to change to a different Configuration: this must be done from a device driver.

In practice, the situation is even worse. According to well known author and device driver expert Walter Oney, Microsoft hasn’t even been able to get its own Windows USB code to work properly with devices having multiple Configurations. In the Second Edition of his book Programming the Microsoft Windows Driver Model, he says:

“Microsoft drivers invariably work with just the first configuration of a device. The Microsoft support for composite devices won’t engage if the device has multiple configurations. Consequently, multiconfiguration devices seem to be rare in practice, and Microsoft discourages people from designing new ones.”





Page 10


To get around the problems that Windows has with "Complex" (i.e., multiple Configuration) devices, HIDmaker FS can make Soft Detach devices that provide the same capabilities without the problems.

Soft Detach capability fools the USB system into thinking that your USB peripheral has been detached, and then re-attached, which forces the host to re-enumerate the device.

 

  Click on the image for page view.




Page 11


When this happens, the device can show the host a different set of descriptors than the last time, containing a single (different) Configuration which might contain multiple Interfaces.

 

  Click on the image for page view.




Page 12


Windows thinks that this is a new Normal or Composite device.  The device is effectively changed to a new Configuration.

This gets around the problems that Complex devices usually have, at a cost of perhaps 30 seconds of time that the PC host will need to re-enumerate the device. This process is triggered in the software of the peripheral device. Depending on how you write that software, it could happen in response to some special command from your PC side program, or from some adjustment (like a button press) made to the peripheral device.

A Soft Detach device designed in HIDmaker FS can have two (2) Configurations, each with up to three (3) Interfaces.

  Click on the image for page view.




Page 13


USB defines various Classes of commonly used devices and Interfaces, such as Printers, Cameras, Audio devices, Mass Storage devices, and Human Interface Devices.

Many of these USB classes require you to write a custom Windows device driver, to enable the PC to communicate with your device. Writing a Windows device driver is a difficult, complex, time consuming, and frankly, risky undertaking.

Frankly, even using a USB class that requires a custom device driver is a risky undertaking:

Requiring your end users to install device drivers is more complex, and some customers will invariably run into trouble.  When they do, they will call your company's Tech Support number. This will cost your company money.

When new versions of the PC operating system are rolled out, your custom device driver is likely to fail, leaving your end users unable to use your device.  For example, device drivers supplied by one major microcontroller company were unable to work with Windows Vista for 9 months. Is that what you want to subject your company to?

 





Page 14


However, one of the USB classes, the Human Interface Device (HID) class, does not require custom device drivers. HID class is supported by highly developed device drivers that are already present in every version of Windows since Windows 98, and are built in to all popular PC operating systems.

You will never have to write, nor even have your end users install, a device driver for a HID class device.




Text Author: Dr. Bob Miller   Copyright Notice and Author Information