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
conor
Associate II
Posted on March 25, 2015 at 00:08 It's probably the call to malloc failing. Replace your malloc call with a statically allocated instancce

static USBD_WHATEVER_HandleTypeDef hWhatever;
< 
snip
>
pdev->pClassData = hWhatever;//USBD_malloc(sizeof (USBD_WHATEVER_HandleTypeDef));

B Zikhali
Associate III
Posted on March 25, 2015 at 11:29

Thank you for your reply Conor, I am actually using a static allocate, I've checked and it returns the desired memory:

/**
* @brief static single allocation 
* @param size: size of allocated memory 
* @retval None
*/
void
* USBD_static_malloc(uint32_t size)
{
static
uint32_t mem[
sizeof
(USBD_CDC_HandleTypeDef)];
return
mem; 
}

petr239955
Associate III
Posted on March 25, 2015 at 21:51

I had similar problem

when I

started

to try

USB

CDC

and

STM32

CubeMX. Don't call USBD_CDC_Init(), this function is called automatically during enumeration or virtual COM

port opening.

I have problem if I start of sending of data before enumeration and port opening. I found solution on other forum, it is

necessary to have

any status information.

I

did not find

anything like this in

HAL

library

. I added variable u8_cdc_initialized to CDC_Init_FS(void) and CDC_DeInit_FS(void).

static int8_t CDC_Init_FS(void)
{
hUsbDevice_0 = &hUsbDeviceFS;
/* USER CODE BEGIN 3 */ 
/* Set Application Buffers */
USBD_CDC_SetTxBuffer(hUsbDevice_0, UserTxBufferFS, 0);
USBD_CDC_SetRxBuffer(hUsbDevice_0, UserRxBufferFS);
u8_cdc_initialized = 1;
return (USBD_OK);
/* USER CODE END 3 */ 
}
static int8_t CDC_DeInit_FS(void)
{
/* USER CODE BEGIN 4 */
u8_cdc_initialized = 0;
return (USBD_OK);
/* USER CODE END 4 */ 
}

All

function calls

of CDC_Transmit_FS()

must

be conditional

:

if (u8_cdc_initialized)
{ 
u8_buff[0] = 'c';
CDC_Transmit_FS(u8_buff, 1);
} 

B Zikhali
Associate III
Posted on March 26, 2015 at 11:13

I thought that's what was supposed to happen ie. USBD_CDC_Init() being called automatically but if I don't call it explicitly, it never is which as I detailed above causes the device handlers pClassData field to never be initialized (see screenshot) and all calls to USBD_CDC_SetTxBuffer to fail.

I tried your method but again if I don't explicitly call USBD_CDC_Init(), CDC_Init_FS() will also never be called, leaving

u8_cdc_initialized

= 0. I am at a wits end, please help me.

________________

Attachments :

PClassData_NULL.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzFJ&d=%2Fa%2F0X0000000bM9%2FF6.fOeR1tZAJsORVlF6SpLT2_5eoCQ_f7Bv_5i_gd8w&asPdf=false
B Zikhali
Associate III
Posted on March 30, 2015 at 16:37

Thank you Petr!!! You were right, my code was trying to send data before the port had been opened.

I realised during the weekend that I would never be able to see the initialization of u8_cdc_initialized whilst the MCU was connected to the debugger, which is why I had initially said your solution was not working for me. The solution I found was to disconnect and reconnect the MCU and read the output from the terminal, and I can see my data being sent from the MCU after a slight pause where the port is being opened. 

Do you have the link to the forum you read this on? It sounds more informative than ST's own documentation which actually told me to call USBD_CDC_Init() [Page 52 Part 7.5.6 of User manual UM1734] which cost me three days of debugging! Thank you so much for your help. Let me now try and create a protocol for my application. 

stm32cube-t
Senior III
Posted on April 15, 2015 at 20:44

Please see project file attached for reference.

________________

Attachments :

UsbDeviceCDC.7z : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzSa&d=%2Fa%2F0X0000000bM8%2FG_hFr7D.qepzLOZUBKzrXwOz9zLmk5lhAsq_3z6FtZo&asPdf=false
malik
Associate II
Posted on September 09, 2016 at 15:55

I'm trying to set up a VCP on my stm32f4 discovery board and I'm also using CubeMX. I have implemented a status check variable like you suggested but I still get the same error even when I don't try to send anything, debug or regular execution. I read on device manager:

''Unknown USB Device (Device Descriptor Request Failed)

Windows has stopped this device because it has reported problems. (Code 43)

A request for the USB device descriptor failed.''

slimen
Senior
Posted on September 09, 2016 at 18:31

Hi, 

Are you using ST-Link with Windows 10? In this case, try with compatibility mode for windows 8 option.

Regards

malik
Associate II
Posted on September 12, 2016 at 15:43

Yes I'm using windows 10 and already changed compatibility mode and updated corresponding VCP drivers from ST but it didn't help. I also switched between IDEs (MDK4 and TrueStudio) but didn't change anything either. Help!!