AnsweredAssumed Answered

CubeMx, STM32F103VC, USB-VCP

Question asked by Altinordu.Zekeriya on Dec 6, 2016
Latest reply on Feb 2, 2017 by Sirma Siang

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.


int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU
Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the
Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_SPI2_Init();
MX_WWDG_Init();
MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */
I2C_Configuration();
loadDefaults();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_Delay(1000); //CORRECTION FOR AFTER RESET STATE, USB CABLE IS PLUGGED
HAL_WWDG_Start(&hwwdg);
while (1){


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 cfgidx)
{
uint8_t ret = 0;
/* Open EP IN */
USBD_LL_CloseEP(pdev,CDC_IN_EP);
/* Open EP OUT */
USBD_LL_CloseEP(pdev,CDC_OUT_EP);
/* Open Command IN EP */
USBD_LL_CloseEP(pdev,CDC_CMD_EP);
/* DeInit physical Interface components */
if(pdev->pClassData != NULL)
{
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
USBD_free(pdev->pClassData);
pdev->pClassData = NULL;
}
HAL_Delay(100); //CORRECTION FOR USB CABLE UNPLUG & PLUG
return ret;
}


I do not know how good a solution is, but the problem is getting out of hand. Where can this delay be permanently added?

Thank you

Outcomes