STM32U5 USB Interrupt Based Approach
I am using the STM32U585RIT6 microcontroller with the B-U585I-IOT02A development kit. I need to implement USB functionality using an interrupt-based approach.
In my project, I have configured USB_OTG_FS in Device-only mode, enabled the NVIC global interrupt, and enabled USBX CDC-ACM. I am using bare-metal code (no RTOS or ThreadX).
After completing all the USB configurations, inside the MX_USBX_Device_Init() function I added the following initialization:
RX FIFO and TX FIFO configurations
USBX DCD initialization using _ux_dcd_stm32_initialize()
Started the PCD using HAL_PCD_Start()
In the main while loop, I am calling ux_device_stack_tasks_run(). With this setup, the USB device starts correctly and is detected as a Virtual COM Port.
Now, I want to handle USB connect and disconnect events using interrupts. For this, VBUS sensing may need to be enabled. While referring to the B-U585I-IOT02A schematic, the USB_VBUS_SENSE pin is shown as PF14. However, in the MCU datasheet and in STM32CubeIDE, PA9 is assigned as the VBUS sense pin.
Please clarify what the correct solution is in this case, and how to properly implement interrupt-based USB connect/disconnect handling? If there are any reference examples related to this scenario, it would be helpful, as I could only find CDC-ACM–related examples.
