2018-06-01 05:25 AM
Hello,
I have a problem to monitoring USB connexion state on STM32F7.
We try to use suspend/resume events to monitor the USB state.
The interrupt function 'HAL_PCD_IRQHandler' should allow us to monitoring connexion state.
If USB is plug off, the flag 'Suspend Interrupt' is up and the function 'HAL_PCD_SuspendCallback' should be call.
If the USB is plug on, the flag 'Resume Interrupt' is up and the function 'HAL_PCD_ResumeCallback' should be call.
However in my case, the event 'suspend' is called just after the initialisation, and during the plug on and plug off sequences these tow events 'Suspend Interrupt' and 'Resume Interrupt' are called at the same time.
At other time, the suspend event is up when the USB is plug off, but the resume event is up few seconds after, unless plug on.
To resume, the resume and suspend event are greatly trigged by the plug action, but the behavior is some
unpredictable and don�t allow the monitoring of USB plug state.
There are also tow other function 'HAL_PCD_ConnectCallback' and 'HAL_PCD_DisconnectCallback' but there are never called.
I tried to modify the interrupt priority level, without result. I tried to startup the USB with minimal configuration values, with no more results.
I�ve read the document 'STM32Cube USB device library.pdf' but I�ve not find solution for me.
What do you suggest as a solution to resolve the monitoring of the USB plug ?
Thanks !
#stm32f7-usb2018-06-01 01:41 PM
If USB is plug off, the flag 'Suspend Interrupt' is up and the function 'HAL_PCD_SuspendCallback' should be call.
If the USB is plug on, the flag 'Resume Interrupt' is up and the function 'HAL_PCD_ResumeCallback' should be call.
The suspend and resume events aren't suitable to detect device connection, as the bus state of suspend or resume doesn't match the bus state of a disconnected device.
There are also tow other function 'HAL_PCD_ConnectCallback' and 'HAL_PCD_DisconnectCallback' but there are never called.
I know that the naming there is very misleading, initially I believed the same of them. However sadly they only work if the peripheral is used in OTG mode.
The most straightforward way to detect the USB connection is to connect the USB 5V to a 5V tolerant pin, and use an EXTI interrupt.
If you don't have access to it, or the hardware is already fixed, you could use other interrupt signals to detect USB connection state.
2018-06-04 05:08 AM
thanks !
My solution are monitoring suspend and resume event at first time, followed by read GPIO pin of USB voltage. That's work !