cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to shut down the USB core

georgeclarkson5
Associate II
Posted on April 11, 2016 at 17:08

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 core

void 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).
1 REPLY 1
georgeclarkson5
Associate II
Posted on April 11, 2016 at 17:44

The solution appears to be removing the ''USBD_DeInit(&USBD_Device);'' line and just calling the USBD_Stop function.