2024-07-31 01:14 AM
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?
Solved! Go to Solution.
2024-07-31 09:43 PM - edited 2024-08-08 02:46 AM
@KHarb.1 wrote:
Debug: I don't have a good example for the G4,
And did you look for examples?
> let alone documentation for the USB code.
And did you look for documentation?
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.
2024-07-31 06:09 AM
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.
2024-07-31 10:53 AM
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?
2024-07-31 12:22 PM
> 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.
2024-07-31 01:42 PM
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.
2024-07-31 03:01 PM
> 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.
2024-07-31 03:35 PM
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.
2024-07-31 09:43 PM - edited 2024-08-08 02:46 AM
@KHarb.1 wrote:
Debug: I don't have a good example for the G4,
And did you look for examples?
> let alone documentation for the USB code.
And did you look for documentation?
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.
2024-07-31 10:28 PM
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.
2024-07-31 10:55 PM