STM32L496 not raising interruption on USB connection
Hello. I am working on a project that uses a STM32L496VET6 microcontroller and that can work as an USB device. The board has the following usb circuit schematic:

The USB signals are connected directly to the MCU (D+ to PA12, D- to PA11, ID to PA10 and VBUS to PA9). The board is self-powered, so the USB power is not used. The VBUS goes through a voltage divider to reduce the voltage from 5V to approximately 3.14V. I configured the peripheral to work only as a device and the interruptions are also enabled. The middleware is configured to use the USB as a COM port.
Issue
When I plug the USB cable in the board, nothing happens, no interruption raises. Using a logic analyzer, I also saw that on idle, D+ is low and D- is high. When I plug the cable, D- goes low, being the unique change, nothing more happens. When I unplug, a interruption is raised and the disconnect callback function is called.
Attempts to fix
- Clock configuration: I tried different clock configurations to have 48MHz in the USB, including the HSI48 RC source. I don't know if it is causing the problem, but when I enable the LSE clock source or try to use the MSI clock source, my code timeouts in the LSE initialization. It could be a non related issue because, as I said, I tried other sources and the behavior is the same.
- VBUS sensing: I read that for a self-powered device, is mandatory to have the VBUS sensing, so I tried with and without it, also changed the voltage divider resistors and also removed them. I configured the pin USB_OTG_FS_VBUS and also tried to configure it as a GPIO_EXTI9 to see if the interruption is being raised. The callback function worked for both raising and falling edges, but the USB_OTG_FS_VBUS didn't behave as expect.
- External Pull-up on D+: I also added an external pull-up resistor on D+ to force the signal high. This way, my computer (the host) was able to detect the STM32 device but the process to get the descriptor fails. Observing the bus on a logic analyzer, when it tries to begin the USB enumeration process, no response comes out of the MCU, and after a few attempts, the communication stop. I also connected the pull-up resistor to other GPIO to pull-up the D+ line only when a interruption is raised in the VBUS pin, but the behavior was the same, no acknowledge or any other response coming from the MCU. Observing the HAL_PCD_IRQHandler function, I saw that some callbacks are called in this sequence:
- HAL_PCD_SuspendCallback
- HAL_PCD_ResumeCallback
- HAL_PCD_ConnectCallback
- USB_FlushTxFifo
- USB_EP0_OutStart
- USB_ActivateSetup
- USB_SetTurnaroundTime
- HAL_PCD_ResetCallback
The steps 4 to 8 are repeated three times before the host stop trying and the device never reaches any function to send anything (like the ACK to the GET_DESCRIPTOR request). This was the closest I reached to have any signal, because without the external pull-up, nothing happens but the disconnect event. Maybe I am missing something, but I would appreciate any help.
