cancel
Showing results for 
Search instead for 
Did you mean: 

stm32F446re usb cdc virtual com port not showing up as the usbd_desc.c

ACand.3
Associate II

Hey everyone,

 

I'm learning about USB CDC and soon USB HID. 

I think I successfully program the stm32 as a cdc device because I can connect to it, and I can read and write serial commands through a terminal. I can even catch the serial buffer through the CDC Receive function. I used cubemx and middleware for generating the usb cdc 

But my question is, on device manager, the stm32 cdc does not show up as "stm32 virtual comport" but as a regular Usb serial device. This happens to in windows 10 and 11. Also the PID and VID numbers are different from the usbd_desc.c. any help would be greatly appreciate it. 

im not sure if this is needed, but this is what I have for cdc control fs

static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)

{

/* USER CODE BEGIN 5 */

uint8_t tempbuf[7] = {0,0,0,0,0,0,0};

 

switch(cmd)

{

case CDC_SEND_ENCAPSULATED_COMMAND:

 

break;

 

case CDC_GET_ENCAPSULATED_RESPONSE:

 

break;

 

case CDC_SET_COMM_FEATURE:

 

break;

 

case CDC_GET_COMM_FEATURE:

 

break;

 

case CDC_CLEAR_COMM_FEATURE:

 

break;

 

/*******************************************************************************/

/* Line Coding Structure */

/*-----------------------------------------------------------------------------*/

/* Offset | Field | Size | Value | Description */

/* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/

/* 4 | bCharFormat | 1 | Number | Stop bits */

/* 0 - 1 Stop bit */

/* 1 - 1.5 Stop bits */

/* 2 - 2 Stop bits */

/* 5 | bParityType | 1 | Number | Parity */

/* 0 - None */

/* 1 - Odd */

/* 2 - Even */

/* 3 - Mark */

/* 4 - Space */

/* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */

/*******************************************************************************/

case CDC_SET_LINE_CODING:

temp[0] = pbuf[0];

temp[1] = pbuf[1];

temp[2] = pbuf[2];

temp[3] = pbuf[3];

temp[4] = pbuf[4];

temp[5] = pbuf[5];

temp[6] = pbuf[6];

 

break;

 

case CDC_GET_LINE_CODING:

pbuf[0] = temp[0];

pbuf[1] = temp[1];

pbuf[2] = temp[2];

pbuf[3] = temp[3];

pbuf[4] = temp[4];

pbuf[5] = temp[5];

pbuf[6] = temp[6];

 

 

break;

 

case CDC_SET_CONTROL_LINE_STATE:

 

break;

 

case CDC_SEND_BREAK:

 

break;

 

default:

break;

}

 

return (USBD_OK);

/* USER CODE END 5 */

}

 

 

Also, would it be possible to run this as a HID as well? I was thinking maybe I can press a button that can switch between cdc and HID. 

 

4 REPLIES 4
TDK
Guru

> But my question is, on device manager, the stm32 cdc does not show up as "stm32 virtual comport" but as a regular Usb serial device.

You cannot control how the device shows up in the device manager. Windows populates this based on, in part, PID and VID values.

> Also the PID and VID numbers are different from the usbd_desc.c. any help would be greatly appreciate it. 

The VID and PID should be able to be modified. Perhaps you are changing the wrong file, or not compiling or something. You can use a USB bus sniffer to see the packets on the USB bus to remove all doubt over what is being sent across.

> Also, would it be possible to run this as a HID as well?

You can theoretically switch between CDC and HID by deinitializing the USB, the reinitializing with the other device. This will make your code complicated, but it can be done.

You can also do a composite USB device. There are some examples floating around online.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

In regards to the PID/VID numbers being different, I see different values on windows/device manager when i select the hardware id option. 

But I will try the usb sniffer for more troubleshooting..

 

"You can theoretically switch between CDC and HID by deinitializing the USB, the reinitializing with the other device. This will make your code complicated, but it can be done.

You can also do a composite USB device. There are some examples floating around online."

So the goal is to have a device that communicates serially with our GUI. Our second goal is to also have this device act as a mouse using an IMU. This way the user can use our device as mouse to navigate the GUI, click on a command in the GUI and the GUI sends that command back serially to the stm32. But if we go this route, then yes, the we would need to create a custom composite USB Device. Especially if we want to integrate firmware updates using DFU. 



Would it be easier to add a serial to usb chip on the stm32 for serial communication and have the stm32 setup as a hid mouse device to accomplish our goals? 

 

 

> Would it be easier to add a serial to usb chip on the stm32 for serial communication and have the stm32 setup as a hid mouse device to accomplish our goals? 

Yes, that seems much easier to accomplish. UART examples and USB HID examples should get you to where you want to be.

If you feel a post has answered your question, please click "Accept as Solution".

So the goal is to have a device that communicates serially with our GUI. Our second goal is to also have this device act as a mouse using an IMU.

Then it it much easier just to use a "serial to usb chip" for a single serial connection to the computer.

On the computer you read the serial input and write back to STM32 directly from your custom application. Both the IMU data and anything else (make some kind of protocol to multiplex different streams). Your application can use SendInput API if you want the "virtual mouse" to control other applications or whole desktop. Linux and Mac OS have similar API.