Posted on November 09, 2017 at 16:12Hi Mikolaj,
I had the same problem, this function solved it :
HAL_PWREx_EnableUSBVoltageDetector() .
Please add this function call to usb_device.c file like this.
void MX_USB_DEVICE_Init(void)
{
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library,Add Supported Class and Start the library*/
USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS);
USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC);
USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS);
USBD_Start(&hUsbDeviceFS);
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
HAL_PWREx_EnableUSBVoltageDetector(); /* USER CODE END USB_DEVICE_Init_PostTreatment */
}
Hope it helps!
Marina