AnsweredAssumed Answered

STM32F4 Cube USB Device library

Question asked by chauhan.samir on Jan 15, 2015
Latest reply on Feb 3, 2015 by Montassar BEN ROMDHANE
Hi,

I have created a HID class device using STM32F4 Cube USB device library.  Everything is working fine and I am able to exchange data with PC.  However, I would like to turn on/off an indicator LED when device is attached/detached.  I am using the following code:
/**
  * @brief  Connect callback.
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
{
  USBD_LL_DevConnected(hpcd->pData);
  HAL_GPIO_WritePin(USB_LED_PORT, USB_LED_PIN, LED_ON);
}


/**
  * @brief  Disconnect callback.
  * @param  hpcd: PCD handle
  * @retval None
  */
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
{
  USBD_LL_DevDisconnected(hpcd->pData);
  HAL_GPIO_WritePin(USB_LED_PORT, USB_LED_PIN, LED_OFF); //This is not working
}

LED turn on fine when device is attached but HAL_PCD_ConnectCallback is not fired when device is disconnected from USB port.  

Any suggestion about how to accomplish this would be highly appreciated.

Outcomes