Skip to main content
Associate III
May 1, 2024
Solved

USB_HS CONNECTION AND DICONNECTION CABLE

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

This topic has been closed for replies.
Saket_OmBest answer
ST Technical Moderator
May 9, 2024

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. 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om

5 replies

ST Technical Moderator
May 8, 2024

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?

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
SITARAMAuthor
Associate III
May 9, 2024

 

HERE I AM USING STM32CubeMX 5.4.0 VERSION AND STM32H743ZI PRODUCT USE

SITARAMAuthor
Associate III
May 9, 2024

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

Saket_OmBest answer
ST Technical Moderator
May 9, 2024

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. 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
ST Technical Moderator
May 15, 2024

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.​

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om