I have a brand-new STM32F303 Nucleo144 and cannot get any CubeMX generated apps to work with USB. The app builds and runs fine, and I can see printf output via SWO, but the device never even begins enumeration. The following procedure was used to develop a minimal reproducible example:
- Start new project in CubeMX
- Select Board Selector, Type of Board: Nucelo144, MCU Series: STM32F3, Board NUCLEO-F303ZE
- Under RCC, select HSE = Bypass Clock Source
- Under USB, select Device(FS)
- Under USB_DEVICE, Class for FS IP: Human Interface Class
- Select Clock Configuration tab, allow autoconfiguration, ensure USB clock is correctly set to 48MHz
- Go to Project Settings, change Minimum Heap Size to 0x400, Minimum Stack Size to 0x800
- Choose toolchain to be Makefile (using GCC-ARM for Windows)
- Save file, Generate Source
- Edit main.c to insert some trivial test code (such as the `USBD_HID_SendReport` sample in the "STM32 USB in 10 Minutes" video)
- Run make, verify build success
- Using ST-Link Utility, flash bin file onto device
- Observe the tragic lack of USB enumeration (even no 'Unknown Device')
Plugging and unplugging the device's user USB port does nothing on the PC - not even showing an unknown device. Device Manager does not attempt a refresh (which is visually quite noticeable) when you plug in the device. So the failure is at a very early stage, perhaps not even beginning to enumerate. This leads me to suspect perhaps a clock or interrupt issue.
I have tried many fixes, including the following changes, and nothing helps at all:
- Set heap and stack to much higher values
- Set explicit priorities for SysTick and USB in NVCC (higher and lower)
- Set HSE to crystal (rather than bypass, which it should be according to the docs)
- Switch to using CDC and MSC classes
- Use or disable FreeRTOS
- Comment out SysTick handler
I also tried starting from scratch and following along with the official STM tutorial as shown in this video:
But that didn't work either. Thinking perhaps there was some faulty hardware, I tried another board. Still nothing. I've tried nearly every suggestion I could find in the forums.
The USB HAL code that ships with the SDK is not actually generated by CubeMX (and doesn't have gcc Makefiles) so it's not really that useful.
So is there a minimalist USB example that is actually generated from CubeMX that actually works?