Browse over 10,000 Electronics Projects

USB HID device development on the STM32 F042

USB HID device development on the STM32 F042

You are now ready to run some debugging sessions. Basically I run a debugging session like this:

  1. Start the Eclipse/OpenOCD debug session. During the flash programming stage the device will disconnect from the PC and I’ll get the ‘ding-dong’ sound from Windows as a confirmation.
  2. The program is automatically halted by the debugger after reset so now I click the start option (F5) in the analyser tool. Data is now being collected.
  3. I release my program in Eclipse and whatever I’m debugging will happen.
  4. When I’m happy that I’ve gone past the point where I’ve exchanged the data I want with the host then I go back to the tool and click stop (Shift-F5). I can now analyse the data I’ve collected.

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.



Advertisement1


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.

Using the stm32plus custom HID driver

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.

Pages: 1 2 3 4 5 6 7 8 9

 


Top