cancel
Showing results for 
Search instead for 
Did you mean: 

USB_HS CONNECTION AND DICONNECTION CABLE

SITARAM
Associate III

I AM USING IN USB_HS DEVICE MODE ,WHEN I CONNECT USB CABLE TO THE PC THEN I WANT  TO KNOWE WHERE IT IS DETECT AND AFTER THAT I REMOVE USB CABLE THEN WHRE IT IS DETECT GIVE ME ANY REGISTER OR CALL BACK FUNCTION ONLY TELL ME IN DEVICE MODE

1 ACCEPTED SOLUTION

Accepted Solutions

Hello, 

To monitor the connection and disconnection events of a USB device, you can implement the callback functions HAL_PCD_ConnectCallback() and HAL_PCD_DisconnectCallback(). These functions are triggered when the USB cable is connected and disconnected, respectively, allowing you to detect these events in device mode.

Please refer to the snipped code below to implement this function: 

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
  /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */

  /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */

  /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */

  /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */
}

 

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
  /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */

  /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */

  /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */

  /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */
}

 You can refer also to the example provided in STM32Cube firmware H7 in this link

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

View solution in original post

5 REPLIES 5
Saket_Om
ST Employee

Hello @SITARAM 

 

Could you please provide additional details about the specific MCU product and the version of the Cube firmware that you are currently utilizing?

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

 

HERE I AM USING STM32CubeMX 5.4.0 VERSION AND STM32H743ZI PRODUCT USE

SITARAM
Associate III

PC0 - USB_OTG_HS_ULPI_STP
PC2_C - USB_OTG_HS_ULPI_DIR
PC3_C - USB_OTG_HS_ULPI_NXT
PA3 - USB_OTG_HS_ULPI_D0
PA5 - USB_OTG_HS_ULPI_CK
PB0 - USB_OTG_HS_ULPI_D1
PB1 - USB_OTG_HS_ULPI_D2
PB10 -USB_OTG_HS_ULPI_D3
PB11 - USB_OTG_HS_ULPI_D4
PB12 - USB_OTG_HS_ULPI_D5
PB13 -USB_OTG_HS_ULPI_D6
PB5 - USB_OTG_HS_ULPI_D7

AND STM32H743ZI  AND STM32CubeMX 5.4.0 VERSION USE

Hello, 

To monitor the connection and disconnection events of a USB device, you can implement the callback functions HAL_PCD_ConnectCallback() and HAL_PCD_DisconnectCallback(). These functions are triggered when the USB cable is connected and disconnected, respectively, allowing you to detect these events in device mode.

Please refer to the snipped code below to implement this function: 

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
  /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */

  /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */

  /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */

  /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */
}

 

#if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#else
void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
#endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
{
  /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */

  /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */

  /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */

  /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */
}

 You can refer also to the example provided in STM32Cube firmware H7 in this link

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

Hello @SITARAM 

 

Did my answer solve your issue? If yes, please mark my answer as “Solution" by clicking on the “Accept as Solution" button, this can be helpful for Community users to find this solution faster.

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar