cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L1 - USB Connection / Disconnection not provided by API

gilberce
Associate II
Posted on August 27, 2015 at 12:18

Hello there,

Trying to handle USB connection / disconnection event I realize that in stm32l1 usb api, there are no call to HAL_PCD_ConnectCallback neither HAL_PCD_DisconnectCallback as there are in STM32F4 !

The session start/stop only works with HAL_PCD_ResumeCallback/HAL_PCD_SuspendCallback.

These callbacks are called from HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) in stm32l1xx_hal_pcd.c which manage PCD IRQ.

At the moment, it seems there's no USB_ISTR register flag for detecting connection / disconnection.

Do someone find a clean solution for handling these events, especialy regarding power management and safety of use ?

Thx.

#stm32l1 #connection #usb
2 REPLIES 2
Mikk Leini
Senior
Posted on August 27, 2015 at 21:52

Hi,

I have used HAL on F4, but StdPeriphLib on L1 so i can't comment L1 HAL. But what i know is that F4's have dedicated USB Vbus (OTG_FS_VBUS) input pin (PA9) which detects voltage on USB connector. L1's don't have that so they don't have such an interrupt either. If you want to get to know about connection of host or charger immediately then you need to take some spare IO pin and monitor Vbus on your own (e.g. by EXTI). Still, you can get to know about the device configuration/disconnection event but that won't work with charger and configuration always takes some time.

Anyway, the L1 USB peripheral is little bit broken as well. The internal pull up on D+ has bad value so you need external one (see errata).

gilberce
Associate II
Posted on August 31, 2015 at 19:54

Hey Leini,

Thx for sharing that.

I got an interesting one about USB on L1 after digging a little bit on Cube FW 1.0.0

When plugging/unplugging an usb to host, sometimes the Suspended callback is not anymore called and the devices stay in usbd_state_configured although the usb is unplugged.

So it seems in this version there's no clean way to detect properly an USB connection/disconnection status.

I'll try to move my app on Cube 1.3.0, the last one to see if this happens too.

Regards.