2021-05-20 10:30 PM
Hi.
I have mk. stm32h743 self-powered from its own 3.3V power supply. With the help of a cube, I raised a virtual com port. I can not understand how you can understand that the device is disconnected from the USB? When you connect Usb, it calls "CDC_Init_FS" and hUsbDeviceFS.dev_state is set to 3, which corresponds to "USBD_STATE_CONFIGURED". But when you disconnect the USB there is no callback "HAL_PCD_DisconnectCallback (PCD_HandleTypeDef * hpcd);" ... Why "HAL_PCD_DisconnectCallback (PCD_HandleTypeDef * hpcd);" not called when USB is disabled?
2021-05-20 10:40 PM
Hi,
When you install the driver stack for USB Host, there would be an internal state machine to handle connection/disconnection of USB stick. The state machine would notify these events to user via callback as following:
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
{
/* USER CODE BEGIN CALL_BACK_1 */
switch(id)
{
case HOST_USER_SELECT_CONFIGURATION:
break;
case HOST_USER_DISCONNECTION:
Appli_state = APPLICATION_DISCONNECT;
break;
case HOST_USER_CLASS_ACTIVE:
Appli_state = APPLICATION_READY;
break;
case HOST_USER_CONNECTION:
Appli_state = APPLICATION_START;
break;
default:
break;
}
/* USER CODE END CALL_BACK_1 */
}
As you can see, when it is disconnected, the state machine would call this callback with id = HOST_USER_DISCONNECTION.
For this to work, remember to enable your interrupt in the setting.
2021-05-20 10:46 PM
I use a virtual com port for communication between the microcontroller and the computer. I don't have USBH_UserProcess
2021-05-21 12:35 AM
Oh Ya, my bad I missed that :beaming_face_with_smiling_eyes: