USB_Device/HID_Standalone Example project crashes on USB disconnect on B-L475E-IOT01A2
Hi, I have a B-L475E-IOT01A2 board and I would like to implement an USB HID application on it. I use the example project found in the Github repository [1]. The application compiles and the USB device is detected on my computer as an input device. The problem is that upon a USB disconnect, the PC seems to jump to 0x0. When plugging the USB cable in again, the application runs again, but it seems I cannot run any code (in, e.g., the main while loop) after a USB disconnect interrupt while the cable is disconnected.
I see this problem both with STM32CubeIDE with ST-Link as well as with SEGGER j-link and Ozone.
In Ozone, I can set a breakpoint in the PCD Interrupt Handler for disconnect events (using USB_OTG_GINTSTS_OTGINT), which will trip upon disconnect. If I step through, I can finish HAL_PCD_IRQHandler to get back to OTG_FS_IRQHandler. As far as I can see, the PC clears to 0x0 after the POP {R7, PC} instruction which returns from the exception handler "OTG_FS_IRQHandler".
It can also be seen visually if I toggle an LED in the main while loop. After a USB disconnect, the blinking stops.
Steps to reproduce:
- Clone [1]
- Open STM32CubeIDE, go to File->Import
- Select 'Existing Projects into Workspace', Click Next and navigate to STM32CubeL4/Projects/B-L475E-IOT01A/Applications/USB_Device/HID_Standalone in the Git repo
- Debug the project, run it and plug in the USB OTG cable
- The device will enumerate as "STMicroelectronics HID Joystick in FS Mode" and your mouse will move
- Now disconnect the USB OTG cable and pause the execution
- Disassembly will fail as the PC is at 0x0
Any help regarding this issue would be greatly appreciated.
Thank you.
