By Jan Axelson
If you’re developing a device that needs
to talk to a PC, the chances are good that
USB will be involved. For each USB device,
the PC assigns a software driver. Windows
provides drivers for devices that fit into
defined USB classes such as human
interface, printer, or mass storage.
If your device doesn’t fit a defined class,
Microsoft’s WinUSB driver is an option.
In this article, I’ll show how to program
and access WinUSB devices. The WinUSB
driver requires a PC with Windows XP SP2
or later, including Windows Vista and
A Transfer Type for
Every USB data transfer is between a PC or
other USB host computer and a device endpoint.
A device endpoint is a buffer that stores received
data or data to transmit. Every device must
support endpoint zero, which is bidirectional.
Additional, optional endpoint addresses each
have a number (1-15) and a direction (IN or
Even though endpoints reside on devices, the
USB specification defines endpoint direction
from the view of the host PC. An IN endpoint
sends data to the PC, and an OUT endpoint
receives data from the PC. This naming
convention can be confusing when writing code
for the device side!
One reason why USB is so versatile is its
support for four transfer types, each with
different strengths. WinUSB supports control,
bulk, and interrupt transfers. Control transfers use
endpoint zero. The other transfer types can use
endpoints one and higher.
Control transfers provide a structured way to
send requests and data and receive responses.
Control transfers are the only type that can pass
information in both directions in a single transfer.
After device attachment — in a process called
enumeration — the host computer uses control
transfers to learn about the device. WinUSB
devices can also use control transfers to send and
receive data in vendor-defined requests. For
example, you can define a request to set or read
a switch, send data to configure device
operation, or receive a sensor reading.
A control transfer has two or three stages. To
learn about a newly attached device, the host
computer uses control transfers to request data
structures called descriptors from the device. In
the Setup stage, the host sends the request. In
the Data stage, the device sends the requested
descriptor. In the Status stage, the host
acknowledges receiving the descriptor. A host
can also use control transfers to send information
to a device in the Data stage, with the device
acknowledging in the Status stage. Some requests
have no Data stage.