cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get STM32G0B1VE USB device work.

Jackle
Associate III

I use STM32CubeIDE1.6.1 to generate USB device (CDC VCP mode) code for STM32G0B1VE. The PC could not recognize the USB. I tried internal HSI48 clock and PLLQ for USB (clock frequency verified by MCO), I pulled up DP through 1.5k resistor by a GPIO after about 2 seconds once starting the code. I'm using Windows 10. Please help!

@Imen DAHMEN​ 

38 REPLIES 38
DWeb_2
Associate III

The Host will try to send info about the baudrate,... via USB to the device. This config needs to be saved somewhere. For some reason, the ST middleware leaves this up to the user (maybe for multiple VCOM on one chip ??). I had the same problems, and found a solution somewhere in the ST Forum. Can't remember where sadly.

Anyway, search for the file "usbd_cdc_if.c". Search for the function "CDC_Control_FS". Replace the following lines into the appropriate cases:

    case CDC_SET_LINE_CODING: //a host sends the line encoding to this device, save it
    	tempbuf[0]=pbuf[0];
		tempbuf[1]=pbuf[1];
		tempbuf[2]=pbuf[2];
		tempbuf[3]=pbuf[3];
		tempbuf[4]=pbuf[4];
		tempbuf[5]=pbuf[5];
		tempbuf[6]=pbuf[6];
    break;
 
    case CDC_GET_LINE_CODING: //a host wants to read the saved encoding for this device
		pbuf[0]=tempbuf[0];
		pbuf[1]=tempbuf[1];
		pbuf[2]=tempbuf[2];
		pbuf[3]=tempbuf[3];
		pbuf[4]=tempbuf[4];
		pbuf[5]=tempbuf[5];
		pbuf[6]=tempbuf[6];
    break;

tempbuf can be static in the function scope or, as I did it, somewhere on global RAM:

/* USER CODE BEGIN PRIVATE_VARIABLES */
uint8_t tempbuf[7];
/* USER CODE END PRIVATE_VARIABLES */

Good luck!

In case that does not solve your problem, try downloading Wireshark. It has a powerful USB sniffer with analytics functions, which might help you.

If I swap DP/DM, then there will be no USB detected even. So, this is not the case. I have tried UART, GPIO, Timer and all work fine.

I don't have a USB example code to try and I don't know where I can find one.

Unfortunately, this doesn't work for me.

I have exactly the same issue.

Sometimes it work, mot 19/20 times, it won't work for me.

I try to switch USB port, then it works...then it does not work any longer.

It seems buggy?

I tried this too. Heap to 0x1000. No luck there as well.

I'm using STM32F373VBT.

Did not fix my issue either.

I have the same issue as you do. But for me, sometimes the PC recognize my USB device. But most of the time...no.

what is the uC partnumber you're using?

If you can connect at least once, it may caused by the noise on the cable. Make sure your cable shield is connected.

Make sure you wait long enough before you pullup the PD line.