Skip to main content
DCorn
Associate II
January 12, 2023
Solved

USB STM32G0B1KCT6 not working

  • January 12, 2023
  • 7 replies
  • 5409 views

Hi

I have used STMCubeIDE 1.11.0 (Cube 1.6.1) to generate the code for USB CDC interface for STM32G0B1.

The code is as CubeMX would generate. I have not modified the code at all.

When I plug the device into a PC I get "USB device not recognized" I have increased the heap and stack to be 0x1000. without any luck.

What can I try to try to figure out what the issue is.

Thanks,

Best answer by DCorn

Hi.

It is now working. I used a STM32G474 example code to figure out what is wrong.

There was 3 errors in the auto generate code.

The 48MHz clock was not started.

Missing USBD_Clock_Config();

in void MX_USB_Device_Init(void))

The USB interrupt was not enabled

Missing

HAL_NVIC_SetPriority(USB_UCPD1_2_IRQn , 6, 0);

HAL_NVIC_EnableIRQ(USB_UCPD1_2_IRQn);

in void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle))

The USB interrupt Handler was not present.

void USB_UCPD1_2_IRQHandler(void)

{

 HAL_PCD_IRQHandler(&hpcd_USB_DRD_FS);

}

Thanks

7 replies

Ghofrane GSOURI
Technical Moderator
January 13, 2023

Hello @DCorn​ 

First let me thank you for posting.

For the USB CDC, it is important to configure the USB clock to the correct frequency, typically 48 MHz This clock is derived from the system clock, so it is also important to ensure that the system clock is configured to the correct frequency as well.

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DCorn
DCornAuthor
Associate II
January 13, 2023

Hi

As you can see the internal 48MHz clock is by default linked to the USB. So that's not the issue I think. I have even tried setting Pclk to be 48MHz still did not work.

David

0693W00000Y8AbdQAF.png

Ghofrane GSOURI
Technical Moderator
January 13, 2023

Hello again @DCorn​ 

Let's try this :

-Make sure that the USB cable you are using is functioning properly.

-Make sure that all the necessary drivers are installed on the PC, and that the device is listed in the device manager.

-You can also try using different USB port or computer to check if the problem is with your PC or the device.

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DCorn
DCornAuthorBest answer
Associate II
January 16, 2023

Hi.

It is now working. I used a STM32G474 example code to figure out what is wrong.

There was 3 errors in the auto generate code.

The 48MHz clock was not started.

Missing USBD_Clock_Config();

in void MX_USB_Device_Init(void))

The USB interrupt was not enabled

Missing

HAL_NVIC_SetPriority(USB_UCPD1_2_IRQn , 6, 0);

HAL_NVIC_EnableIRQ(USB_UCPD1_2_IRQn);

in void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle))

The USB interrupt Handler was not present.

void USB_UCPD1_2_IRQHandler(void)

{

 HAL_PCD_IRQHandler(&hpcd_USB_DRD_FS);

}

Thanks

Mischa
Associate
August 31, 2023

Thanks @DCorn!

I also added the missing clock configuration and increased heap size to 0x1000. The IRQ is now as you mentioned (FW_G0_V1.6.1). But I still get the message "USB device not recognized".

Interestingly, I can measure a 1.5 k pull-up on D- pin instead of D+ pin like it's a low speed device (the pin-out is correct).

Have you got suggestions what else to check?

Thank you!

Ghofrane GSOURI
Technical Moderator
January 16, 2023

Hello @DCorn​ 

Let's do those steps :

1-Create project in CubeMX 

2-USB-->Device FS

3-RCC-->Select HSE clock-->(Bypass clock source )

4- Select CDC class in MiddleWares 

5-Go to clock configuration --> Set 8 MHz as input frequency

6-Make sure that the frequency for USB CDC is 48Mhz

Please try this solution and I will be waiting for your feedback don't hesitate to raise any question

Thx

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Visitor II
November 17, 2025

for me, I got USB device not recognized when init project too and I just enable interrupt in NVIC than it work

somsinchai_0-1763386729085.png

 

Associate
November 19, 2025

Hi Guys,

 

I tried all the above proposals, but it still does not resolve the issue for me.

Using CubeMX, and STM32F103C8T8 (and G0 & G4). Issue unfortunately still persists.

Any other proposals/ideas?

 

Thanks in advance.