Browse over 10,000 Electronics Projects

USB HID device development on the STM32 F042

USB HID device development on the STM32 F042

Testing USB devices

Testing a USB device is by no means straightforward. The protocol defines strict timing requirements for state changes and response times, some of which are sub-second. When I was developing the custom HID support for stm32plus debugging it was difficult. As soon as you pull DP high to signal device insertion then it will start raining requests from a very impatient host.

Breakpoints set during this device enumeration stage are typically one-shot. That is, you can hit the breakpoint you need when you need it but when you pause to look at the state in the debugger then the host will quickly get upset and fail enumeration so you have start all over again for further debugging.

What we need is a tool that can spy on the protocol and as luck would have it there is one and it’s free. Download and install a copy of Microsoft Message Analyzer.

Here’s a quick tutorial on how to setup and use the tool to debug a USB device.

Microsoft Message Analyzer

The first step is to run the tool and you’ll see the main screen looking like this.

I’ve closed the View Filter tool window because I don’t need it and opened up the Field Chooser window (Tools -> Windows -> Field Chooser).

Click on the New Session button and you’ll get a dialog box.



Advertisement1


Click on the Live Trace button and then from the Trace Scenario drop-down box select USB 2 if you’ll be plugging into a USB 2 hub or USB 3 if you’re plugging into a USB 3 hub.

There’ll be a short pause while it fills in some provider information and then you can click Start to get started. The main window will quickly fill up with data. Locate the Stop icon in the toolbar and press it.

Now that data collection is stopped we will customise the view to contain only USB device information. Close the Session Explorer tool window and type ‘usb’ into the Field Chooser text box to filter the options like this:

Double-click on all the fields that start with ‘UsbDevice’ so that they are added to the main window. The Source and Destination fields are of no use so right-click on those column headers and select Remove so that they disappear. Now find the UsbDevice column header, right click on it and select Group. This is the key step to understanding message flow as it will separate out devices by their PID/VID combination. The Field chooser can now be closed to maximise your screen area for actual data.

Pages: 1 2 3 4 5 6 7 8 9

 


Top