cancel
Showing results for 
Search instead for 
Did you mean: 

How to debug an USB-Connection?

THe1
Associate

Hello everyone,

I am trying to expand the STM32Cube USB library which comes with the generated Code from STM32CubeMX. There are still some bugs in the Code but it is really hard to find them without appropriate debugging tools. The normal debugger can not be used while the host disconnects the device if there is no answer. I also figured out that printf-Debugging with UART is also complicated because it is too slow.

Could you recommend a suitable method to debug an USB connection?

Thank you for helping!

4 REPLIES 4
KnarfB
Principal III

UART speeds up to 921600 baud worked reliably for me in similar settings.

Depending on the chip series you might redirect printf to SWO which can be even faster than that.

Use a high resolution timestamp (extra timer or DWT cycle counter avail. on some cores) for timestamping you logs.

You may also set aside a larger text (char) buffer in RAM and log to RAM (sprintf) with very little overhead and inspect/dump the RAM buffer later.

Might combine this with setting breakpoints at some critical points in the code and inspect the RAM buffer then.

If you have spare pins, you might add a logic analyzer (LA) and set some pins aside for signalling certain states of the connection.

There are SW tools that act like a software LA using a RAM buffer technique. Search for TraceX or https://gitlab.com/KnarfB/timedoctor.

A host side tool like wireshark may capture USB data on the wire.

Add assertions to your code to catch design flaws early.

hth

KnarfB

> You may also set aside a larger text (char) buffer in RAM and log to RAM (sprintf) with very little overhead and inspect/dump the RAM buffer later.

Or implement it as a large FIFO buffer and UART/SWO running asynchronously at it's own pace.

THe1
Associate

Thank you for the suggestions! I will try these.

Lubos KOUDELKA
ST Employee

Hello,

if you deal often with USB, external USB protocol analyzer could be good option for you. On our side we're using Ellisys USB Explorer 260 or LeCroy Mercury T2. It can show you all communication translated also into nicely readable form also with timestamps. Possible to use in both host and device configuration. (if STM32 is acting as host, PC USB analyzer cannot be used)

Best regards,

Lubos