cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC not being initialized

ym21
Associate II
I have an STM32L4R on a custom PCB. I am able to flash firmware using CubeProgrammer/CubeIDE to it via an ST-LINK SWD connection as well as a DFU Bootloader via a USB D connector. I have a makeshift connection between the USB D connector to a USB C cable to my laptop in order to flash it using USB_DM, USB_DP, and VBUS wires between the D and C connectors. When the PCB is powered, the ST-LINK is connected to my target MCU and my laptop, and my PCB is connected to my device, my laptop is able to recognize the ST-LINK as a VCP and my target MCU as an "STM32 BOOTLOADER", which allows it to be flashed. The ST-LINK connection is critical in the target MCU being recognized by my laptop. I have written CDC initialization code in order to enumerate my target MCU as a VCP and transmit data to my laptop, however, I am having trouble with that...
My code works on the NUCLEO that I have for the STM32L4R. I am also able to step through initialization all the way to the CDC_Transmit() function inside of my while() loop which just sends simple printf() statements to a terminal. Although my target MCU has been flashed with CDC code and I am able to step through it using the Debug session, my laptop is still not able to recognize it.
I added a dynamic printf() statement right at the line where I want to print data to a terminal. This breakpoint tells me the device state of the USB is 1

/* Device Status */

#define USBD_STATE_DEFAULT 0x01U

#define USBD_STATE_ADDRESSED 0x02U

#define USBD_STATE_CONFIGURED 0x03U

#define USBD_STATE_SUSPENDED 0x04U

Which, judging from the code files, means that the USBD state is at its default. 

I am not sure how to approach this problem, I am not sure if it is a hardware, software, or connection issue. Any advice will help. Thank you.

 
1 REPLY 1
Pavel A.
Super User

Debugging USB device is tricky because you can't set breakpoints and step. The USB host requires real-time response. If the target does not respond, host can try to reset it. Slow debug prints can cause the communication timeout as well.