Custom device name for nrf52840 USB dongle in pyserial

I am making an application using nrf52840 USB dongle. 

I am using a python program with pyserial. This works great. 
My only problem is that I want to have a very reliable way to identify the correct USB device.

I am using this code in python to identify the USB device.

def find_nrf_com_port():
    ports = serial.tools.list_ports.comports()
    print("dY"? Available COM ports:")
    for port in ports:
        print(port)

    for port in ports:
        if "Nestlab" in port.description or "USB Serial Device" in port.description:
            return port.device
    return None


this is returning

PS C:\Users\BjornOlsen\Documents\GitHub\nestlab_usb_stick\usb_comm> python3 .\read_serial.py
🔍 Available COM ports:
COM17 - USB Serial Device (COM17)
✅ Auto-detected COM port: COM17
Connected to COM17...

The problem here is that the device is called "USB Serial Device". Not a very descriptive name! 

In my nrf52840 I am using this prj.conf.

CONFIG_GPIO=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Nestlab USB Stick"
CONFIG_USB_DEVICE_MANUFACTURER="Malsen Medical"
CONFIG_USB_DEVICE_SN="0001"
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_CJSON_LIB=y

I was expecting that this would change the name to "Nestlab USB Stick" - but alas this does not work.
Note! I do not need it to show up in windows. I only really need the name to be unique when I list USB devices using pyserial.


Parents
  • Hello bjornolsen,

    I believe this is more a pyserial issue than a nRF device issue, so perhaps a more general software engineering or Python forum might be able to help you better.

    On the nRF Device, you only need to set CONFIG_USB_DEVICE_PRODUCT like you already did. If you use some library to interact with USB device rather than serial port, you should be able to see the configured name.

    I found this thread on Stack Overflow which seems to address a similar issue: python - Pyserial get the name of the device behind a COM Port - Stack Overflow.

    Hieu

  • Hello.


    Well I don't know what I am expected to see really.

    on windows the device shows up like this

    Get-WmiObject Win32_SerialPort | Where-Object { $_.PNPDeviceID -like 'USB*' } | Format-Table Name, DeviceID, PNPDeviceID, Description
    
    Name                      DeviceID PNPDeviceID                                   Description
    ----                      -------- -----------                                   -----------
    USB Serial Device (COM22) COM22    USB\VID_2FE3&PID_0100&MI_00\7&227FB56F&0&0000 USB Serial Device


    I don't want to mount the USB device to windows (I am not using it as a USB storage device). 
    I would expect that I would see the correct name in device manager. The name in the device manager is the same as what I see over python

    Device: COM22
     Name: COM22
     Description: USB Serial Device (COM22)
     HWID: USB VID:PID=2FE3:0100 SER=3702 LOCATION=1-2.2:x.0
     VID: 12259
     PID: 256
     Serial number: 3702
     Manufacturer: Microsoft
     Product: None

  • Hello,

    What would be shown if you flash this sample onto the dongle? I don't have a dongle with me right now to test.
    https://github.com/nrfconnect/sdk-zephyr/tree/v3.7.99-ncs2-rc1/samples/subsys/usb/console

    I wonder if the bootloader on the dongle gets registered with the PC first and causes issue. Do you also have a nRF52840 DK to cross check application behavior?

  • Hello,

    I cloned the library and built the application with no problems using SDK 2.9.

    I still see

    "COM20 USB Serial Device (COM20)".

    in windows device manager I see exactly the same.
    Manufacturer: "Microsoft".

    I think Microsoft simply do not reconize this USB stick.
    "Device USB\VID_2FE3&PID_0004&MI_02\6&b296da&0&0002 requires further installation."

    It almost seems that it needs some kind of driver in order to reconize it.

    I have not tried the nrf52840dongle on linux. All I really want it to reliably detect it there are many USB devices connected (and that is often the case). But it shows up in windows as a "generic USB" device. that is the isssue.

    Maybe I am simply missing a driver.

    Note! I tried this in SDK 2.9 and 2.7, same result.

  • I am having some small success here.

    In order for it to show up as a SDFU device AFTER flashing I need to add

    CONFIG_USB_DEVICE_VID=0x1915  
    CONFIG_USB_DEVICE_PID=0x521F  

    If I use any other VID/PID it seems to show up as a generic device (unless I register my company with windows I would guess).

    It seems that my best bet is to go with this. At least then it shows up a a nordic USB rather than windows generic usb. 

    It seems I am unable to set the custom name, but that is not so important as long as I have a clearly distinguishable name.

  • Hi bjornolsen,

    What you found gave me a great clue to recall something. The root cause is that Windows cache the device name since the first time you connected to it. When you change VID and PID, it recognizes the device as something new, so the configured name goes through.

    Thus, this is a limitation on the host OS, Windows. There is not much that can be done from the device application, unfortunately.

Reply
  • Hi bjornolsen,

    What you found gave me a great clue to recall something. The root cause is that Windows cache the device name since the first time you connected to it. When you change VID and PID, it recognizes the device as something new, so the configured name goes through.

    Thus, this is a limitation on the host OS, Windows. There is not much that can be done from the device application, unfortunately.

Children
No Data
Related