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 Reply Children
  • 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.

Related