For the last six months I have been involved in the development of the first USB device in my life and the application software for it, and now I want to share my understanding of how everything works there: a microcontroller, a driver, an application software. I will also raise the issue of choosing the VID / PID. The list of useful links for those who want to understand the topic in more detail is attached.
Context
An electronic device is being developed, which, when connected to the sensor, performs microdisplacement measurement and transmits the result to a PC, where it is displayed in an operator-friendly graphical form. The scope of the measuring device is mechanical engineering.
A little bit about how it works

The diagram shows the main actors involved in the life of the developed device.
The microcontroller is the main element of the device, which sends control signals to the sensor and receives the response, which calculates the measurement result. With the help of the implemented USB stack, data exchange with the host is practically reduced to working with read and write buffers. Due to the fact that the measuring algorithm does not require large computational powers and the period of one measurement is 100-150 ms, the
at90usb162 microcontroller (8 bits, 16 MHz, 16 kB) is selected. This MK has hardware support for USB, which greatly simplifies the software implementation of the USB stack. In other matters, I didn’t have to implement the stack and initialize the MK due to the example of the USB Generic HID Implementation from the accompanying
software package . Alternatives to branded AVR examples include the
LUFA framework (MIT license) for AT90USBxxxx and ATMEGAxxUx and the fully software implementation of the
V-USB stack (GPL or commercial license), which allows you to work with AVRs without USB hardware.
')
A little bit about the abbreviation
HID . This is a class of USB devices designed for human input: keyboard, mouse, game controllers. It is assumed that such devices have a small amount of information transmitted, as well as the device being developed: packets of 8 bytes with an interval of 100-150 ms. The main convenience of working with devices of this class is the presence of a standard driver in the OS, which frees you from writing your own.
The host (master, master) in my case is the PC, or rather the USB controller built into the motherboard. According to the descriptor (description) of my device, the host polls it for new parcels with a period of about 20 ms. The application software collects the data received by the host, carries out a small processing and draws indicators resembling automotive speedometers, which show the measured values. A list of connected sensors and their settings that can be changed are displayed: the changes will be transferred to the device and saved in non-volatile memory.
One of the ideas of the application is cross-platform, so it is developed in the
Qt framework in C ++, and the OS calls for reading and transmitting data are made through the
libusb library. The last few months there has been an active development of the libusb v1.0
backend for blame , they are already writing about the pre-release status and, more importantly, everything seems to work with it for me. There is also a libusb v0.1 port for Windows -
LibUsb-Win32 . The topic of work through WinAPI is detailed and with examples on Visual Basic and Visual C # disclosed in the book USB Complete (
about the book ). I tried WinAPI and did not like it.
VID and PID
When releasing your USB device to the light, the company should assign it a manufacturer identifier (vid - vendor id) and product (pid - product id, not to be confused with the serial number). Formally, uniqueness is necessary to prevent conflicts between device drivers in the OS. Although I have a suspicion that this is more likely one of the ways to make money for the creators of the standard than the only possible technical solution. However, I, of course, will not condemn them for their desire to earn money on the standard they have created.
So, for the manufacturer of the periphery, there are
two ways to get your own vid:
- pay $ 2000 for vid at a time
- or become a member of USB-IF for $ 4000 per year.
For those who are not able to pay such money, chip manufacturers provide various options for using their vid and pid:
- Atmel . The faq lists the rules by which you can use the vid / pid chip for your device.
- FTDI . In addition to using the built-in vid / pid, the company offers to send a request for a free allocation of pid.
- Microcip also offers to send a request for the allocation of pid.
- Silicon Labs . Here is what they write on the forums :
- "SiLabs provides a ready-made package for generating a driver with your own description of the device, but the vid / pid will be from SiLabs (vid 10C4, pid EA60)."
- “If the usb-com adapter is from Sylabs, then you can get vid / pid for free from them. We have already received two. It is necessary to write a letter in English, in response they will send a questionnaire. Answers to the questionnaire - by letter again to the Silabs, and two days later send a vid / pid. But it is necessary, of course, to describe the project in detail (start date, volumes) and indicate your site (preferably * .com). ”
- Chips that implement the usb protocol only hardware can use the built-in hardware vid and pid. For example, this applies to FTDI chips.
Main sources of information
A great introduction to USB (
eng. ,
P. P. ) For peripheral developers - 30 pages instead of many hundreds in the
standard . More information about the development of USB peripherals and drivers for it can be found on the
Lakeview Research website, especially I want to mention the book
USB Complete: The Developer's Guide, by Jan Axelson .