STM32G431KB; Fatal problem with USB initialization function
FreeRTOS is currently active. However, the problem occurs before FreeRTOS initialization (before calling osKernelInitialize ()).
The board used is a board written by hand rather than a NUCLEO board. When I activate my Peripheral devices other than USB-PD and run the FreeRTOS application, I confirm that it works correctly.
The point where the problem occurs is inside the USB_DisableGlobalInt function. In the process of masking the interrupt mask to USBx-> CNTR, all interrupts are immediately interrupted (including the SWD of ST-LINK) and the chip is reset after a certain time.
Here is the call stack at the time of occurrence:
[0] from 0x08004b88 in USB_DisableGlobalInt+0 at Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_usb.c:117
[1] from 0x08004aa0 in HAL_PCD_Init+28 at Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pcd.c:169
[2] from 0x08000908 in MX_USB_PCD_Init+32 at Src/main.c:483
[3] from 0x080009b2 in main+34 at Src/main.c:122
The code for each call stack is as follows:
[0]
106 HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx)
107 {
108 uint16_t winterruptmask;
109
110 /* Set winterruptmask variable */
111 winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
112 USB_CNTR_SUSPM | USB_CNTR_ERRM |
113 USB_CNTR_SOFM | USB_CNTR_ESOFM |
114 USB_CNTR_RESETM | USB_CNTR_L1REQM;
115
116 /* Clear interrupt mask */
117 USBx->CNTR &= ~winterruptmask; // << Stucks at this point
118
119 return HAL_OK;
120 }[1]
154 {
155 hpcd->MspInitCallback = HAL_PCD_MspInit;
156 }
157
158 /* Init the low level hardware */
159 hpcd->MspInitCallback(hpcd);
160 #else
161 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
162 HAL_PCD_MspInit(hpcd);
163 #endif /* (USE_HAL_PCD_REGISTER_CALLBACKS) */
164 }
165
166 hpcd->State = HAL_PCD_STATE_BUSY;
167
168 /* Disable the Interrupts */
169 __HAL_PCD_DISABLE(hpcd); // <<< Stucks At This Point
170
171 /* Init endpoints structures */
172 for (i = 0U; i < hpcd->Init.dev_endpoints; i++)
173 {[2]
475 hpcd_USB_FS.Instance = USB;
476 hpcd_USB_FS.Init.dev_endpoints = 8;
477 hpcd_USB_FS.Init.speed = PCD_SPEED_FULL;
478 hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
479 hpcd_USB_FS.Init.Sof_enable = DISABLE;
480 hpcd_USB_FS.Init.low_power_enable = DISABLE;
481 hpcd_USB_FS.Init.lpm_enable = DISABLE;
482 hpcd_USB_FS.Init.battery_charging_enable = DISABLE;
483 if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) // << Stucks at this point
484 {
I don't know if this is a known issue, but I couldn't find it when I tried searching on Google.
Please let me know if there is any additional information you need to solve the problem, such as board configuration or CubeMX settings.
Thanks.
