cancel
Showing results for 
Search instead for 
Did you mean: 

USB suspend-resume event

pierreoury9
Associate
Posted on June 01, 2018 at 14:25

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-usb
2 REPLIES 2
Ben K
Senior III
Posted on June 01, 2018 at 22:41

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.

  • The Reset interrupt is a good signal for connection detection. Even though it can be sent many times during a single session, the purpose of it is to reset everything related to the USB connection to a known initial state, which is probably what you do anyway.
  • To detect disconnection I would count the number of consecutive ESOF signals (without SOF between them). If this exceeds 3 and you don't get a Suspend event in between, that means the host isn't present to pull the bus to idle state.
Posted on June 04, 2018 at 12:08

thanks !

My solution are monitoring suspend and resume event at first time, followed by read GPIO pin of USB voltage. That's work !