cancel
Showing results for 
Search instead for 
Did you mean: 

What diagnostics can be run on PC and STM32 to debug failing USB virtual COM port?

KHarb.1
Senior II

I have an STM32G4 board that is to function as a virtual COM port via USB.  This is my first attempt at implementing USB. Within CubeIDE, I enabled the USB feature and configured a middleware device for the virtual COM port. I’m not seeing the PC react in any way when I connect the board. I’m not sure where to begin to debug and I don't see any examples for the STM32G, so I'm also not sure if I've completed all the needed steps for it show up as a PC device.

Can I observe connection progress with the PC via the USB registers? 

If I had an electrical failure on the USB connection, what diagnostics could I run in software from the PC?

1 ACCEPTED SOLUTION

Accepted Solutions

@KHarb.1 wrote:

 

 Debug: I don't have a good example for the G4, 


And did you look for examples?

BarryWhit_0-1722487220409.png

> let alone documentation for the USB code. 

And did you look for documentation?

BarryWhit_1-1722487286550.png

 

As far as getting the device to simply enumerate, there's no real need for an example. You just configure the USB peripheral as a CDC device in Cube and generate the code. On the software side of things, nothing more is required for the board to show up as a COM Port in windows device manager.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.

View solution in original post

17 REPLIES 17
TDK
Guru

Are you using a USB data cable? A power-only cable will give you the response you're reporting.

Which board? Ensure it is wired up correctly and appropriate pins are connected to the USB header you are using.

You can debug the code to see progress in the USB connection. You can also use a USB monitoring tool on the PC. But if nothing is happening, the PC tool isn't likely to show anything.

If you feel a post has answered your question, please click "Accept as Solution".

Data cable: Yep known good.

 

Board: STM32G473. As far as I know it's wired correctly, but again, this is my first attempt at using USB.

 

Debug: I don't have a good example for the G4, let alone documentation for the USB code. I suspect I'd hit timeouts while debugging as well, which would make the process a nightmare.

 

PC Monitoring tool: Can you give me an example? A first diagnostic I'd like to run is detecting that something connected, but there was some error.  Specifically, I'm powering the board via the USBC connection successfully, so when I connect to the PC, I'd like to at least like to detect when current draw begins.  Is there something that does this?

> I suspect I'd hit timeouts while debugging as well, which would make the process a nightmare.

You'll hit breakpoints, but you can see what the code is doing. I wouldn't say it's a nightmare. Gives a whole lot more insight than just guessing at what is happening. Hit play, let it run past the point where it should connected, then hit pause and examine what is happening.

> PC Monitoring tool: Can you give me an example?

USB Monitor Pro. I have no affiliation here. Wireshark can also do USB.

These won't measure current draw. Computer doesn't have access to that information.

If you feel a post has answered your question, please click "Accept as Solution".

You really can't run a debugger on such things, you need to instrument with output to a serial port, so you can observe the dynamic behaviour without interfering with it. You can print out registers periodically, or say in response to a button push.

On the PC side, when I was doing such things, I wrote a Filter Driver for the Windows USB stack to see and report URB's seen as they traverse. The tools TDK mentions is likely doing a similar thing. Then there are USB Analyzers that sit externally and monitor things at a more electrical / signal level.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

You'll hit breakpoints, but you can see what the code is doing.

USB connection is time sensitive so breakpoints cannot really be used. If the device stops on breakpoint the host will  be upset, it may drop connection and reset the device. So, only traces, quick and short, to ITM or something like.

This is what I figured.  If I had a way to check on the connection drop from the host side it would be good start.


@KHarb.1 wrote:

 

 Debug: I don't have a good example for the G4, 


And did you look for examples?

BarryWhit_0-1722487220409.png

> let alone documentation for the USB code. 

And did you look for documentation?

BarryWhit_1-1722487286550.png

 

As far as getting the device to simply enumerate, there's no real need for an example. You just configure the USB peripheral as a CDC device in Cube and generate the code. On the software side of things, nothing more is required for the board to show up as a COM Port in windows device manager.

- If someone's post helped resolve your issue, please thank them by clicking "Accept as Solution".
- Please post an update with details once you've solved your issue. Your experience may help others.
bm2
Associate III

When You have problems with USB, You can make the following points to find out the problem. But first, when you stop the application with a breakpoint, the USB communication is also broken und is not work. The timing in the USB communication is hard.

  • check if your VCOM on the PC successful enumerated: this can you see in the windows hardware manager and in the global state variable of the USB device
  • you can trace the USB communication: with wireshark, for this you must connect the USB device which runs wireshark, or you use a USB protocol analyser, I use Beagle USB 480 Protocol Analyzer from Total Phase
  • if the enumeration successful finished and you can send/recive some data over VCOM?
  • please check that you dosn't use a USB stack from ST with bugs.
  • please check that you use the correct USB connection on the NUCLEO board. For USB devices exists two USB connectors, one for the debugger and VCOM from the debugger and the other from the STM32 device
  • you can use the USB VCOM implementation for other devices, it is the same middle ware, so you can use a other demo with VCOM implementation
KnarfB
Principal III

You may use WireShark on the PC side CaptureSetup/USB - Wireshark Wiki

hth

KnarfB