cancel
Showing results for 
Search instead for 
Did you mean: 

USB OTG CDC Device busy when trying to send

bm
Associate II
Posted on September 17, 2016 at 15:15

hey guys,

so I am using an STM32F411 as an USB device. It's connected via VCOM to a PC. I am using HAL V2.4.1 from19-June-2 In general it works good, but when I quickly connect and disconnect the usb plug on the device for a few times in a row and then re-connect with my terminal PC tool the device is no longer sending data because

USBD_CDC_TransmitPacket

returnsUSBD_BUSY only! I have no idea how handle this case. Should I somehow reset the USB driver? Is this an indication that s/t is messed up with my implementation? Why is it busy? What can cause such a state? Any help is appreciated. Let me know if you need more information on this.
1 REPLY 1
Walid FTITI_O
Senior II
Posted on October 26, 2016 at 12:23

Hi moll.benjamin,

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() and HAL_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:

  • VBUS (PA9) pin should be connected to VBUS (5V) pin of the USB connector (for OTG_HS on on-chip FS PHY, VBUS (PB13) pin)
  • Enable the Vbus sensing (vbus_sensing_enable is 'ENABLE'd in USBD_LL_Init() )

-Hannibal-