Skip to main content
DJung.3
Associate
Solved

stm32 usb device dual

Hello. I'm using EVM board with STM32F407ZGT.

I set up the USB as below to use it as a USB Device. (CDC)

2024-05-29_134310.jpg2024-05-29_134325.jpg

But only one COM port can be found in the device manager on the PC.

2024-05-29_134405.jpg

I want to know if I can't set 2 usb device or if it's a problem with setting.

Please help me!!

2024-05-29_135118.jpg

 

This topic has been closed for replies.
FBLBest answer
ST Technical Moderator

Hello @DJung.3 

 

You need to register two instances with USBD_RegisterClassComposite.

 /* Init Device Library */
 USBD_Init(&USBD_Device, &COMPOSITE_Desc, 0);

 /* Register CDC class first instance */
 USBD_RegisterClassComposite(&USBD_Device, USBD_CDC_CLASS, CLASS_TYPE_CDC, CDC_EpAdd_Inst1);

 /* Register CDC class second instance */
 USBD_RegisterClassComposite(&USBD_Device, USBD_CDC_CLASS, CLASS_TYPE_CDC, CDC_EpAdd_Inst2);

 /* Add CDC Interface Class */
 if (USBD_CMPSIT_SetClassID(&USBD_Device, CLASS_TYPE_CDC, 0) != 0xFF)
 {
 USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
 }

 /* Add CDC Interface Class */
 if (USBD_CMPSIT_SetClassID(&USBD_Device, CLASS_TYPE_CDC, 1) != 0xFF)
 {
 USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
 }
 /* Start Device Process */
 USBD_Start(&USBD_Device);

  

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL

3 replies

FBLBest answer
ST Technical Moderator

Hello @DJung.3 

 

You need to register two instances with USBD_RegisterClassComposite.

 /* Init Device Library */
 USBD_Init(&USBD_Device, &COMPOSITE_Desc, 0);

 /* Register CDC class first instance */
 USBD_RegisterClassComposite(&USBD_Device, USBD_CDC_CLASS, CLASS_TYPE_CDC, CDC_EpAdd_Inst1);

 /* Register CDC class second instance */
 USBD_RegisterClassComposite(&USBD_Device, USBD_CDC_CLASS, CLASS_TYPE_CDC, CDC_EpAdd_Inst2);

 /* Add CDC Interface Class */
 if (USBD_CMPSIT_SetClassID(&USBD_Device, CLASS_TYPE_CDC, 0) != 0xFF)
 {
 USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
 }

 /* Add CDC Interface Class */
 if (USBD_CMPSIT_SetClassID(&USBD_Device, CLASS_TYPE_CDC, 1) != 0xFF)
 {
 USBD_CDC_RegisterInterface(&USBD_Device, &USBD_CDC_fops);
 }
 /* Start Device Process */
 USBD_Start(&USBD_Device);

  

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
Visitor II

Hello, for a USB composite device with two CDC, both CDC eventually call the same CDC_Init_FS function and thus share a single buffer. When both CDCs are transmitting data simultaneously, is there a risk of data loss due to sharing the same buffer?

Mrli110_1-1731500726673.png

 

ST Technical Moderator

Hi @Mrli110 

Have you checked this article How to implement a dual CDC ACM USB device using t... - STMicroelectronics Community  If still having issues, I suggest you starting a new thread.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL