cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L032CB: USB COM VCP; device is not identified on host computer. Clock and CDC Settings not correct?

FaikN
Associate II

Hi,

I am using STM32L032CB MCU and a USB-C port and would like to achieve a virtual port com with CDC. I have generated the project with CubeMX where i enabled usb mode and configuration and assigned two pins DM and DP. Furthermore, i have enabled usb_Device there also with default parameter settings. on the freertos tasks, i use cdc_transmit_fs to send a message to host device terminal. However, my computer(mac osx) does not recognise the attached usb for communication. I have attached the system clock configuration from main.c and also hal_pcd_mspinit for pin configuration of usb dm and dp pins. Is the problem due to clock configuration? if yes, how it should be? otherwise what can be the sources of problem?

Many thanks in advance.

Regards,

Faik

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Configure the main internal regulator output voltage 

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /* Initializes the CPU, AHB and APB busses clocks*/

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI48;

 RCC_OscInitStruct.HSEState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_3;

 RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_3;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /* Initializes the CPU, AHB and APB busses clocks*/

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_USB;

 PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;

 PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_HSI48;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

}

/* MSP Init */

void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)

{

 if(pcdHandle->Instance==USB)

 {

 /* USER CODE BEGIN USB_MspInit 0 */

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 __HAL_RCC_GPIOA_CLK_ENABLE();

 /* Configure USB DM and DP pins.

   This is optional, and maintained only for user guidance. */

 GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);

 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 /* USER CODE END USB_MspInit 0 */

  /* Peripheral clock enable */

  __HAL_RCC_USB_CLK_ENABLE();

  /* Peripheral interrupt init */

  HAL_NVIC_SetPriority(USB_IRQn, 3, 0);

  HAL_NVIC_EnableIRQ(USB_IRQn);

 /* USER CODE BEGIN USB_MspInit 1 */

 /* USER CODE END USB_MspInit 1 */

 }

}

0 REPLIES 0