With the code generated with CubeMX, the USB virtual com port connection on the STM32F103VC processor is very problematic on Windows. Exclamation marks are very common in the device manager. With the method I learned in the forum, I was able to prevent the problem that occurred after the reset. I added a delay for this after the reset.
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* Reset of all peripherals, Initializes the Flash interface and the
/* Configure the system clock */
/* Initialize all configured peripherals */
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_Delay(1000); //CORRECTION FOR AFTER RESET STATE, USB CABLE IS PLUGGED
If the problem occurred after the USB cable was disconnected and plugged (exclamation mark in the Windows device manager), I could prevent it with a delay added to the USBD_CDC_DeInit function. However, this change is lost when CubeMX generates code again.
static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev,
uint8_t ret = 0;
/* Open EP IN */
/* Open EP OUT */
/* Open Command IN EP */
/* DeInit physical Interface components */
if(pdev->pClassData != NULL)
pdev->pClassData = NULL;
HAL_Delay(100); //CORRECTION FOR USB CABLE UNPLUG & PLUG
I do not know how good a solution is, but the problem is getting out of hand. Where can this delay be permanently added?