STM32 controller hangs when USB is not connected

90 views Asked by At

I'm using a STM32G0B1 controller. For coding I use STM32CubeIDE. I also used CubeMX to do basic configuration of the hardware. Based on the provided middleware I was able to configure a USB compoiste device (CDC and HID). I also use FreeRTOS, configured by CubeMX. USB is clocked by HSI48. Clock Recovery is turned of (I want to turn it on later but at the moment it's disabled to reduce error sources). All other clocks are based on HSI RC and the PLL to create a 64MHz SYSCLK.

Everything runs fine as long as a computer is connected to the USB port. As soon as the USB connection is disconnected, no Freertos tasks are executed anymore. I can still stop and debug but it only stops in the osDelay function. When I want to step into a function, it won't continue. Hitting F8 will execute something and I can pause and debug at another place again.# When I replug USB again, everything continues.

When USBD_Start(&hUsbDeviceFS) is not called during initialization all tasks are still executed.

My first idea was that the missing USB host could trigger an IRQ which is not reset anymore, resulting to stay in the IRQ. I checked the USB IRQ register USB_ISTR. Every bit is zero. In USB_CNTR, SUSPRDY and SUSPEN are set. With the host connected, both flags are not set.

I also checked the global ISRPENDING and VECTPENDING flags. All I can see here is the IRQ for TIM17, which is configuredas Timebase Source in CubeMX. ISPR and ICPR are both set to 0x400000, again it's TIM17.

I set breakpoint in all IRQ handlers, explicit in void HardFault_Handler(void) and void USB_UCPD1_2_IRQHandler(void). They are not active after unplugging the host.

Any ideas what might block te tasks?

0

There are 0 answers