cancel
Showing results for 
Search instead for 
Did you mean: 

USB STM32G0B1KCT6 not working

DCorn
Associate III

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,

1 ACCEPTED SOLUTION

Accepted Solutions
DCorn
Associate III

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

View solution in original post

7 REPLIES 7
Ghofrane GSOURI
ST Employee

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

DCorn
Associate III

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
ST Employee

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

DCorn
Associate III

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

Ghofrane GSOURI
ST Employee

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

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!

Hi,

Struggling with the same problem here. I think @DCorn solution was pointed in the right direction but didn't work for me because some of the functions to add just doesn't exist in my environment.

 

I fixed it in the graphical Pinout & Configuration tool:

go to 'System Core' -> 'NVIC' and enable 'USB, UCPD1 and UCPD2 global interrupts'. Save the configuration to regenerate the code and try again.