2016-04-11 08:08 AM
I'm currently having some issues with the USB core on the STM32f4. Before enabling the USB core the VBUS line (GPIO A9) is low as would be expected. when a usb cable is plugged it I detect this and enable my USB core using the following function:
void MX_USB_Init(void){ if(USBState == Disabled){ /* Init Device Library */ USBD_Init(&USBD_Device, &VCP_Desc, 0); /* Add Supported Class */ USBD_RegisterClass(&USBD_Device, USBD_CDC_CLASS); /* Add CDC Interface Class */ USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops); /* Start Device Process */ USBD_Start(&USBD_Device); USBState = Enabled; }}This works fine and the USB appears to communicate correctly with the PC, the problem comes however when I disconnect the USB cable. Originally I wasn't deinitializing the USB core, but it was noticed that if the core was active, VBUS would output 1.9V. I then wrote the following function to disable the USB corevoid MX_USB_Deinit(void){ if(USBState == Enabled){ /* Stop Device Process */ USBD_Stop(&USBD_Device); /* Deinit Device Library */ USBD_DeInit(&USBD_Device); USBState = Disabled; }}However I'm not sure it has fully shut down the USB core as I still have a voltage on USB VBUS (GPIO A9).2016-04-11 08:44 AM
The solution appears to be removing the ''USBD_DeInit(&USBD_Device);'' line and just calling the USBD_Stop function.