Skip to main content
Olek1
Associate II
August 1, 2019
Question

STM32G431RB cannot start USB CDC, PC cannot detect the device(unknown device error)

  • August 1, 2019
  • 5 replies
  • 2455 views

Hi,

I got a problem with running USB CDC on STM32G431RB. I configured USB as device and added USB CDC driver.

I have changed 'CDC_Control_FS' function in 'usbd_cdc_if.c' file.

case CDC_SET_LINE_CODING:
 	LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8)| 							(pbuf[2] << 16) | (pbuf[3] << 24));
		LineCoding.format = pbuf[4];
		LineCoding.paritytype = pbuf[5];
		LineCoding.datatype = pbuf[6];
 break;
 case CDC_GET_LINE_CODING:
 	pbuf[0] = (uint8_t)(LineCoding.bitrate);
		pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
		pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
		pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
		pbuf[4] = LineCoding.format;
		pbuf[5] = LineCoding.paritytype;
		pbuf[6] = LineCoding.datatype;
 break;
 break;

I tried on both Windows 10 and Windows 7 PC but I get all the time error: 'Unknown device'(looks like vendor id is never delivered to PC, but I checked and stm32 tries to send it).

I also tried both crystalless version and using HSE.

Does anyone got it working on STM32G4?

EDIT: One more thing I checked USB bootloader and it works, so the problem is software I believe.

Thanks.

This topic has been closed for replies.

5 replies

DGuly
Visitor II
August 23, 2019

Have you gotten this to work? I have an STM32G431CBU on a custom board that also refuse to show up on USB, even though it gets power just fine. Could well be bugginess of the board, though it seems like things are connected up right as far as the wiring goes.

Olek1
Olek1Author
Associate II
August 23, 2019

I figure it out. First of all check if cabling is correct(easiest way is to run USB bootloader mode).

To fix the software you need to change usbd_desc.c by changing USBD_CDC_DeviceDesc struct to:

__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
{
 0x13, /*bLength */
 USB_DESC_TYPE_DEVICE, /*bDescriptorType*/
 0x0,
 0x02,
 0x02, /*bDeviceClass*/
 0x02, /*bDeviceSubClass*/
 0x00, /*bDeviceProtocol*/
 USB_MAX_EP0_SIZE, /*bMaxPacketSize*/
 LOBYTE(USBD_VID), /*idVendor*/
 HIBYTE(USBD_VID), /*idVendor*/
 LOBYTE(USBD_PID), /*idProduct*/
 HIBYTE(USBD_PID), /*idProduct*/
 0x00, /*bcdDevice rel. 2.00*/
 0x02,
 USBD_IDX_MFC_STR, /*Index of manufacturer string*/
 USBD_IDX_PRODUCT_STR, /*Index of product string*/
 USBD_IDX_SERIAL_STR, /*Index of serial number string*/
 USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/
};

Notice the 0x0 on line 5 which is required. After that Windows 10 should discover your stm32 as USB VCP.

Good luck!

Dmitry
Visitor II
September 10, 2019

Thank you very much! Everything is working! Only: bLength = 0x12

waclawek.jan
Super User
August 23, 2019

Where do you have this descriptor from?

The bLength field is incorrect; count the bytes, there should be 18 = 0x12 there.

JW

Dmitry
Visitor II
September 10, 2019

After the hint above, I also found this descriptor in STM32CubeG4. And after the correction everything worked. (STM32G431KBT). bLength = 0x12 - It is right.

__ALIGN_BEGIN uint8_t USBD_CDC_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =

{

 0x12,                      /*bLength */

 USB_DESC_TYPE_DEVICE,      /*bDescriptorType*/

 0x00,                      /*bcdUSB */

 0x02,

 0x02,                      /*bDeviceClass*/

 0x02,                      /*bDeviceSubClass*/

 0x00,                      /*bDeviceProtocol*/

 USB_MAX_EP0_SIZE,          /*bMaxPacketSize*/

 LOBYTE(USBD_VID),          /*idVendor*/

 HIBYTE(USBD_VID),          /*idVendor*/

 LOBYTE(USBD_PID),          /*idProduct*/

 HIBYTE(USBD_PID),          /*idProduct*/

 0x00,                      /*bcdDevice rel. 2.00*/

 0x02,

 USBD_IDX_MFC_STR,          /*Index of manufacturer string*/

 USBD_IDX_PRODUCT_STR,      /*Index of product string*/

 USBD_IDX_SERIAL_STR,       /*Index of serial number string*/

 USBD_MAX_NUM_CONFIGURATION /*bNumConfigurations*/

};

Olek1
Olek1Author
Associate II
October 11, 2019

You are right, my mistake.

What is funny it works for both 0x12 and 0x13.

Dmitry
Visitor II
October 11, 2019

The CubeMx generates an invalid descriptor!

...Waiting for the update for the G4 family.