cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496 not raising interruption on USB connection

Mailson97
Associate II

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:

usb_circuit.png

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

  1. 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.
  2. 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.
  3. 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:
    1. HAL_PCD_SuspendCallback
    2. HAL_PCD_ResumeCallback
    3. HAL_PCD_ConnectCallback
    4. USB_FlushTxFifo
    5. USB_EP0_OutStart
    6. USB_ActivateSetup
    7. USB_SetTurnaroundTime
    8. 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.

3 REPLIES 3
AScha.3
Chief III

Hi,

just question: you generate project with IDE +  HAL etc ?  

+ is  

 MX_USB_DEVICE_Init();

in main ?

If you feel a post has answered your question, please click "Accept as Solution".

Yes. I forgot to mention this detail, but I am using the STM32CubeIDE to generate the whole project and HAL drivers. Also, this MX_USB_DEVICE_Init() function is in the main.c file and the initialization seems fine, all the steps inside this function are executed with no erros.

I just asked because i had never this problem (using IDE+HAL).

Maybe look in IDE menu help->configuration -> manage...packages : is there a update for L4 (-> 1.18.1) ?

If you feel a post has answered your question, please click "Accept as Solution".