You are now ready to run some debugging sessions. Basically I run a debugging session like this:
With the tool paused you can analyse everything that happened during the session in minute detail, including the entire enumeration stage. And the great thing is that the display remembers the devices that you have expanded for viewing between sessions so you can just run it over and over again and only your device will be expanded for viewing in the window. Here’s a snapshot of my custom HID example starting up.
You can clearly see the sequence of descriptors being requested by the host and the responses from my device. When you’re debugging USB you will quickly become intimately familiar with those descriptors.
Finally let’s take a look beyond device enumeration and into device report data exchange with the host. My sample code wakes up every second and sends the string ‘Hello World’ to the host as report id #1. If you refer back to the custom HID report descriptor that I showed earlier you’ll recall that I defined report #1 (IN to the host) as having 12 bytes. That’s 1 byte for the mandatory report ID and the remaining 11 for the string ‘Hello World’. Here is that transfer in the analyser tool:
To see the data you drill down into the Interrupt In Transfer entry and find the Fid_URB_TransferData line. In the Field Data window you’ll see the actual bytes that the host received.
In summary, the free Microsoft Message Analyzer is a vital tool for USB debugging and I would not be without it for a second.
After completing the USB driver code I merged it into the stm32plus C++ library so that you can produce your own custom HID implementation with little effort. A direct link to the device driver template is here.
I was pleased with the efficiency of the results. I managed to get a bare-bones program size of just 5808 bytes versus the same program taking 10796 bytes using ST’s Cube/HAL. Both were compiled with gcc using the -Os
optimisation option.
The full stm32plus custom HID example can be found here. Let’s take a look at how it fits together.