2024-05-01 03:28 AM
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
Solved! Go to Solution.
2024-05-09 09:28 AM
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.
2024-05-08 04:05 AM
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?
2024-05-08 09:32 PM
HERE I AM USING STM32CubeMX 5.4.0 VERSION AND STM32H743ZI PRODUCT USE
2024-05-08 09:41 PM
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
2024-05-09 09:28 AM
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.
2024-05-15 02:21 AM
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.