cancel
Showing results for 
Search instead for 
Did you mean: 

STM32Cube USB CDC Unknown USB Device Descriptor Request Failed

B Zikhali
Associate III
Posted on March 24, 2015 at 18:38

I have been working on setting up my MCU as a VCP CDC Device using STM32Cube for the past few days. I have studied the STM32Cube USB device library User Manual (UM1734) and have followed the steps outlined in part 7.5.6 which calls on my application to call the function USBD_CDC_Init().

void

MX_USB_DEVICE_Init(

void

)

{

/* 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); // USBD_CDC_Init called here

hUsbDeviceFS.pClass->Init(&hUsbDeviceFS, DEVICE_FS);

}

I have changed the value of CDC_DATA_HS_MAX_PACKET_SIZE to 256 in usbd_cdc.h as detailed in this [DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Java/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Java/USB%20CDC%20Bug%20in%20CubeMX%20firmware&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000F9A0E3A95BA69146A17C2E80209ADC21&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx&currentviews=3282]post to ensure that my device data packet size is 64 bytes.

#define CDC_DATA_HS_MAX_PACKET_SIZE 256 /* Endpoint IN & OUT Packet size */

I have also ensured that my heap size is changed to the minimum recommended by ST support in another post on this forum, in my .ld file

_Min_Heap_Size = 0x0400;

/* required amount of heap */

_Min_Stack_Size = 0x0400;

/* required amount of stack */

The problem is if I call the function USBD_CDC_Init() the MCU controller is listed as an UnKnown Device by Windows and stopped. If I comment out the call, my MCU is correctly recognised and configured as a VCP device in both Windows and Linux but all subsequent calls to USBD_CDC_SetTxBuffer will fail (HardFaultHandler is called) because the pClassData field of the USB Device handler is never initialized. I am caught between the devil and the deep blue sea, how do I proceeed?

I am using a STM32f302k8 and STM32CubeMX version 4.6.0 with FW version 1.1.1 for STM32F3.

#usb #usb #usb #stm32 #stm32 #stm32f4 #usb #discovery #stm32f3

14 REPLIES 14
malik
Associate II
Posted on September 12, 2016 at 15:48

I have the EXACT same problem: CDC_Init_FS never called.

christoph2399
Associate II
Posted on September 13, 2016 at 08:16

please check if you use the right interface aswell as the right pins

HAL_PCD_MspInit()

, but i would say: disable vbus sensing...

check in your usbd_conf.c:

USBD_StatusTypeDef  USBD_LL_Init (USBD_HandleTypeDef *pdev)

  /* Init USB_IP */

  if (pdev->id == DEVICE_FS) {

  /* Link The driver to the stack */

  hpcd_USB_OTG_FS.pData = pdev;

  pdev->pData = &hpcd_USB_OTG_FS; 

  

  hpcd_USB_OTG_FS.Instance = USB_OTG_FS;

  hpcd_USB_OTG_FS.Init.dev_endpoints = 4;

  hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;

  hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;

  hpcd_USB_OTG_FS.Init.ep0_mps = DEP0CTL_MPS_64;

  hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;

  hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;

  hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;

  hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;

  hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;

  if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)

  {

    while(1);//Error_Handler();

  }

  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);

  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);

  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);

  }

  return USBD_OK;

}

malik
Associate II
Posted on September 13, 2016 at 16:08

* I tried both with and without vbus sensing but it didn't change anything.

**I have checked the

HAL_PCD_MspInit()

function and it's the right pins that are being configured (PA11 and PA12)  in the right mode I think. Here is the function in usbd_conf.c file:

/* MSP Init */

void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(pcdHandle->Instance==USB_OTG_FS)

  {

  /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */

  /* USER CODE END USB_OTG_FS_MspInit 0 */

  

    /**USB_OTG_FS GPIO Configuration    

    PA11     ------> USB_OTG_FS_DM

    PA12     ------> USB_OTG_FS_DP 

    */

   

GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

    GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    /* Peripheral clock enable */

    __HAL_RCC_USB_OTG_FS_CLK_ENABLE();

    /* Peripheral interrupt init */

    HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(OTG_FS_IRQn);

  /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */

  /* USER CODE END USB_OTG_FS_MspInit 1 */

  }

}

Posted on January 07, 2017 at 19:30

I see your 

HAL_PCD_MspInit() has the GPIO initialization for the USB pins. Mine has not. CubeMX generated. I cannot find this GPIO initialization happening anywhere else either.

STM32F042G6

Posted on January 07, 2017 at 23:40

Let me answer that myself. I found from STM32F072 example code for som eval board that GPIO initializing is optional.