cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103ZE - USB - Login to Windows with the same ComPort

Rassi
Associate II

Hello.
I have developed a module that has an STM32F103ZE controller. This controller has a USB interface.
In order to test the modules, this USB interface is to be connected to a Windows PC via a needle bed. Then various test commands are to be sent via the USB interface for testing.
However, Windows assigns a new Virtual-ComPort number each time a new module is connected.
Is there a way to suppress this so that the same Virtual ComPort number is always assigned?
This must only be the case for the test system. Could this be done by adapting the Windows driver?

 

Greetings
Rasmus

1 ACCEPTED SOLUTION

Accepted Solutions

Hello.
Thanks for the feedback. That was exactly the tip I needed.
I have now set the serial number string in the "usbd_desc.c" file.

 

uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
  UNUSED(speed);
  *length = USB_SIZ_STRING_SERIAL;

  /* Update the serial number string descriptor with the data from the unique
   * ID */
  Get_SerialNum();
  /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */

  USBD_StringSerial[0] = 26;
  USBD_StringSerial[1] = 3;
  USBD_StringSerial[2] = 52;
  USBD_StringSerial[3] = 0;
  USBD_StringSerial[4] = 56;
  USBD_StringSerial[5] = 0;
  USBD_StringSerial[6] = 68;
  USBD_StringSerial[7] = 0;
  USBD_StringSerial[8] = 66;
  USBD_StringSerial[9] = 0;
  USBD_StringSerial[10] = 53;
  USBD_StringSerial[11] = 0;
  USBD_StringSerial[12] = 52;
  USBD_StringSerial[13] = 0;
  USBD_StringSerial[14] = 54;
  USBD_StringSerial[15] = 0;
  USBD_StringSerial[16] = 68;
  USBD_StringSerial[17] = 0;
  USBD_StringSerial[18] = 51;
  USBD_StringSerial[19] = 0;
  USBD_StringSerial[20] = 53;
  USBD_StringSerial[21] = 0;
  USBD_StringSerial[22] = 52;
  USBD_StringSerial[23] = 0;
  USBD_StringSerial[24] = 53;
  USBD_StringSerial[25] = 0;

  /* USER CODE END USBD_FS_SerialStrDescriptor */
  return (uint8_t *) USBD_StringSerial;
}

 

 

Now the devices are always assigned the same ComPort number by Windows.
Only when two devices are connected to a Windows PC at the same time are different ComPort numbers assigned.

Is there a more elegant way to set the serial number?

Thank you for your help.

Regards
Rasmus

 

 

 

 

 

 

View solution in original post

5 REPLIES 5
Pavel A.
Evangelist III

Do you assign unique "USB serial number" strings to the modules?

 

Hello.
Thanks for the feedback. That was exactly the tip I needed.
I have now set the serial number string in the "usbd_desc.c" file.

 

uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
  UNUSED(speed);
  *length = USB_SIZ_STRING_SERIAL;

  /* Update the serial number string descriptor with the data from the unique
   * ID */
  Get_SerialNum();
  /* USER CODE BEGIN USBD_FS_SerialStrDescriptor */

  USBD_StringSerial[0] = 26;
  USBD_StringSerial[1] = 3;
  USBD_StringSerial[2] = 52;
  USBD_StringSerial[3] = 0;
  USBD_StringSerial[4] = 56;
  USBD_StringSerial[5] = 0;
  USBD_StringSerial[6] = 68;
  USBD_StringSerial[7] = 0;
  USBD_StringSerial[8] = 66;
  USBD_StringSerial[9] = 0;
  USBD_StringSerial[10] = 53;
  USBD_StringSerial[11] = 0;
  USBD_StringSerial[12] = 52;
  USBD_StringSerial[13] = 0;
  USBD_StringSerial[14] = 54;
  USBD_StringSerial[15] = 0;
  USBD_StringSerial[16] = 68;
  USBD_StringSerial[17] = 0;
  USBD_StringSerial[18] = 51;
  USBD_StringSerial[19] = 0;
  USBD_StringSerial[20] = 53;
  USBD_StringSerial[21] = 0;
  USBD_StringSerial[22] = 52;
  USBD_StringSerial[23] = 0;
  USBD_StringSerial[24] = 53;
  USBD_StringSerial[25] = 0;

  /* USER CODE END USBD_FS_SerialStrDescriptor */
  return (uint8_t *) USBD_StringSerial;
}

 

 

Now the devices are always assigned the same ComPort number by Windows.
Only when two devices are connected to a Windows PC at the same time are different ComPort numbers assigned.

Is there a more elegant way to set the serial number?

Thank you for your help.

Regards
Rasmus

 

 

 

 

 

 

Is there a more elegant way to set the serial number?

Specially for testing multiple instances of USB devices with proper, unique "serial numbers" Windows has a registry parameter IgnoreHWSerNum. It is documented here.  It tells Windows to disregard the serial number and behave as it were missing. So the new COM port instances won't be generated. Again, this is not intended for normal use.

 

Bob S
Principal

@Pavel A.'s answer is the right one.  We've got lots and lots of FTDI USB-to-serial cables and STLink boards, and that is the only way to keep from overflowing the available COM numbering scheme in Windows.

Rassi
Associate II

Hello.
Thank you for the further solution approach.

Regards
Rasmus