STM32F4 Usb fails to work only when in debug mode
I am working on a basic USB FS HID device on an STM32F411 Discovery Board, the USB code is the only code on the board. When I run the code from the STM32CubeIDE, the device fails to enumerate and Windows says "Device Not Recognized". I have no breakpoints, delays or anything else set in the program that would cause a pause. When I plug the device in outside of debug mode, the device works as expected, and I can receive data fine in the desktop application.
The device ALWAYs works as expected outside of the IDE even in Windows and Linux on different computers. I changed all of my debug settings for debug connections (connect under reset, etc), but it still has the same issue. I'd like to get this to work as the SWO output is useful to debug the OUT packets the device receives.
The only way I can seem to get the device to work properly in Windows is if I change the VID or PID, then it enumerates fine. But if I run it again, it seems to fail, so I'm wondering if this is related to something Windows is doing with the driver or device manager settings.
I've tried resetting the USB control registers, I've tried resetting the PORTA to its init values explicity, and I've tried holding PA12 (USB DP) to low as suggested here:
https://community.st.com/t5/stm32-mcus-products/usb-cdc-dont-work-in-debug/td-p/464797
Has anyone encountered this issue before? It's really frustrating because it's making it impossible to debug my device without constantly changing the VID or PID.
