Showing results for 
Search instead for 
Did you mean: 

USB stopping method referring to hUsbDeviceHS created in STM32CubeIDE. (@usb_cdc_if.c)

Associate III


As the title, hUsbDeviceHS is one of the structures automatically created by STM32CubeIDE. Currently, I connect the USB port with this structure name, and I want to stop the USB port when there is a switch input. (I confirmed that the function is USBD_Stop(&hUsbDeviceHS); or USBD_DeInit(&hUsbDeviceHS);.)

When trying to operate after checking the external GPIO, an error occurs when referencing it because it is attempted to be implemented in a separate source file after initialization. The structure name declaration (USBD_HandleTypeDef hUsbDeviceHS;) is usb_device.c, and the external reference declaration (extern USBD_HandleTypeDef hUsbDeviceHS;) is usbd_cdc_if.c, both of which are in the source file.


The problem is that an error occurs when you try to include the source file (duplicate function declaration=multiple definition), making it difficult to use.
I don't know why the external reference was inserted into the source file rather than the header file.

Is there a solution to this?