2016-10-18 02:43 PM
I'm working on USB on an STM32L4 chip and cannot seem to reliably trigger when a USB Device is both Connected and Disconnected. I trigger the interrupt overall and handle it, but I need changes to happen as soon as a device is connected and then handle some special case for when a USB is disconnected. USBD_LL_DevConnected() will trigger off reset for the very first connection of USB, but never again after when I unplug and re-plug in the USB and USBD_LL_DevDisconnected() never seems to trigger. Has anyone else found a way around this? Overall, my OTG_FS_IRQHandler() does get called and connects to the device correctly. Does anyone know if there is a setting I am missing that would enable the detection of both of these states?
Thank you. #stm32 #stm32l4 #usb2016-10-18 11:42 PM
Common way to do that is poll USB connection every second.
2016-10-19 01:19 AM
Hi kenney.jacob
,If you want to know if you have a device is either connected or disconnected, use can a global variable inside both HAL_PCD_ConnectCallback() andHAL_PCD_DisconnectCallback()
.
If USBD_LL_DevConnected status is USBD_OK you should change the value of the global variable to 1 (or whatever you prefer). You should write the code to update this global variable into every related callbacks.HAL_PCD_CconnectCallback() is called inside HAL_PCD_IRQHandler() (stm32fxx_hal_pcd.c), by GOTGINT.SEDET (session end detected) interrupt
.To ensure this interrupt is fired you need the following requirement:
-Hannibal-
2016-10-19 06:50 AM
I have vbus_sensing_enable ENABLED and have VBUS (5V connection brought down to 3.3V to not damage the processor, that wouldn't cause a problem, would it?) connected to PA9. However, HAL_PCD_ConnectCallback() will only get called on the initial USB plugged in and never again when I unplug and re-plug in the device and HAL_PCD_DisconnectCallback() never gets triggered in this interrupt, are there additional settings elsewhere I may need?
Where can I configure the interrupt to trigger on both the rising and falling edge for the HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS)?