NuttX USB Device Trace

Last Updated: March 20, 2011

USB Device Tracing Controls. The NuttX USB device subsystem supports a fairly sophisticated tracing facility. The basic trace cabability is controlled by these NuttX configuration settings:

Trace IDs. The trace facility works like this: When enabled, USB events that occur in either the USB device driver or in the USB class driver are logged. These events are described in include/nuttx/usb/usbdev_trace.h. The logged events are identified by a set of event IDs:

Logged Events. Each logged event is 32-bits in size and includes

  1. 8-bits of the trace ID (values associated with the above)
  2. 8-bits of additional trace ID data, and
  3. 16-bits of additonal data.

8-bit Trace Data The 8-bit trace data depends on the specific event ID. As examples,

16-bit Trace Data. The 16-bit trace data provided additional context data relevant to the specific logged event.

Trace Control Interfaces. Logging of each of these kinds events can be enabled or disabled using the interfaces described in include/nuttx/usb/usbdev_trace.h.

Enabling USB Device Tracing. USB device tracing will be configured if CONFIG_USBDEV and either of the following are set in the NuttX configuration file:

Log Data Sink. The logged data itself may go to either (1) an internal circular buffer, or (2) may be provided on the console. If CONFIG_USBDEV_TRACE is defined, then the trace data will go to the circular buffer. The size of the circular buffer is determined by CONFIG_USBDEV_TRACE_NRECORDS. Otherwise, the trace data goes to console.

Example. Here is an example of USB trace output using apps/examples/usbserial for an LPC1768 platform with the following NuttX configuration settings:

Console Output:

The numbered items are USB USB trace output. You can look in the file drivers/usbdev/usbdev_trprintf.c to see examctly how each output line is formatted. Here is how each line should be interpreted:

In the above example you can see that:

USB Monitor. The USB monitor is an application in the apps/system/usbmonitor that provides a convenient way to get debug trace output. If tracing is enabled, the USB device will save encoded trace output in in-memory buffer; if the USB monitor is also enabled, that trace buffer will be periodically emptied and dumped to the system logging device (the serial console in most configurations). The following are some of the relevant configuration options:

NOTE: If USB debug output is also enabled, both outputs will appear on the serial console. However, the debug output will be asynchronous with the trace output and, hence, difficult to interpret.