Skip to main content
Visitor II
March 26, 2024
Question

USB VCP Get_SerialNum

  • March 26, 2024
  • 2 replies
  • 1725 views

Hello Everybody,

 

I use STM32CubeIDE1.15.0 Build: 20695_20240315_1429 and a custom board with a STM32303RE inside.

I use the IOC interface to set the virtual port com. Everything work fine, just a detail: when i connect, then disconnect and reconnect the USB port, the port com number on Windows change, It increase (search the next available number)! The VID and PID are always the same, so I focus on the serial number, and i found that (code generate by STM32CubeIde):

 
usbd_desc.c:
 
legalguillaume_0-1711471641088.png
3 undefined local variables, which are used to generate the serial number. Each time I connect the USB cable, the values change=>so the serial number change.
 
Is it normal? Is it a (strange) way to generate a randomize serial number?
Just a bug?
 
 
(VCP number seems better with this fix:
legalguillaume_0-1711473139330.png

 

;)

)

 
 
 
BR,
Guillaume Le Gal
 
 
    This topic has been closed for replies.

    2 replies

    Super User
    March 26, 2024

    Just a bug. Consistent serial numbers can be created from anything else, for example programmed in OTP flash or eeprom.

    See also: https://community.st.com/t5/stm32-mcus-products/stm32f103ze-usb-login-to-windows-with-the-same-comport/td-p/654424

     

    Visitor II
    August 25, 2025

    Hi, I am also having this problem with CubeMX 6.11.0 and STM32Cube FW_F4 V1.28.2. Was this bug fixed? I think this is the reason that my device is always detected as a new COM port.

    Super User
    August 25, 2025

    Just check in the sources (generated by Cube?) if there still are un-initialized variables. Fix as needed.

    Also note that in Windows it is possible to ignore the "serial numbers" for specific VEN/DEV combination. If you don't see any "serial number" on the host side, it could be that.

     

    Visitor II
    August 26, 2025

    Thank you for your response! 

    I know how to fix it (and indeed initializing these variables fixed the USB problem for me). The question was whether this bug was fixed by ST in later versions of Cube template. This use of uninitialized variables is clearly Undefined Behavior and can as well reboot your MCU or wipe your flash if another version of compiler feels like it.