none
Assign virtual USB COM port number RRS feed

  • Question

  • Hi,

    We are currently developing using WINCE 7 and VS2008. We are having some issues with the USB virtual serial COM port when our device is connected to a PC. The COM port number changes each time we power cycle our device and connect it to the same PC. We would like to assign a COM port for our device to connect to a PC. We modified the platform.reg file with the following settings:

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\USBSER_Class]
       "Dll"="serialusbfn.dll"
       "DeviceName"="USBFNS2:"
       "Prefix"="COM"
       "Index"=dword:9
       "DeviceArrayIndex"=dword:1 
       "IClass"=multi_sz:"{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}","{C375C787-B721-4b8e-B67F-A112D5C0A404}"
       "idVendor"=dword:Company Info
       "Manufacturer"="Our Device"
       "idProduct"=dword:product info
       "Product"="Product Name"
       "bcdDevice"=dword:90

    By setting "Index"=dword:9 on the register, should the device connect to COM9? If COM9 is in used, it should connect to the following free COM port?

    Are we missing any settings?

    Thanks,

    David L.

    Tuesday, November 3, 2015 8:43 PM

Answers

  • Hi David

    Here are some comments related to the question being asked:

    • It should be possible to control the serial port number using the "Index" key for the registry settings.
    • If it's not working, check the registry settings to make sure that "DefaultClientDriver"="USBSER_Class" is set.
    • If that default client driver is in place, then try to add a new [HKEY_CURRENT_USER\Comm\RasBook\USB] entry for it. This entry usually has a key named "Entry" containing information about the serial port number value. That's why it could be necessary to add an entry after setting "USBSER_Class" as the default client driver, specifying in the "Entry" part the value of the index being used, because it could contain a different value then the one being set.

    Adeneo Support Team


    Thursday, January 7, 2016 6:57 PM

All replies

  • Hi David,

    Can you clarify the issue? Are you hitting this issue? http://stackoverflow.com/questions/9835881/releasing-a-unplugged-virtual-serial-port.  Can you discuss the connect disconnect and what is happening on each side of the connection? Are you sure your USB device is function and not host?

    When you power cycle is it a cold or warm boot?  My suspicion is the port is not actually being released during the suspend cycle. Can you confirm that the driver unloads fully?

    Sincerely,

    IoTGirl

    Tuesday, November 3, 2015 10:23 PM
    Moderator
  • I don't know if you can do this from device's registry, as it's not provided in documentation.

    But if you need this just for testing, you can check this link, and change the device settings on PC to assign a COM port number to your device.

    Wednesday, November 4, 2015 5:23 AM
  • Hi IoTGirl,

    The issue that we are having is that when we connect our device to a desktop, we switch the virtual COM port from USB host to USB device. When we connect our device to the desktop PC, it installs the driver for the device and assign a COM port but if we disconnect our device, power cycle it and reconnect it to the desktop PC, sometimes it reinstall the drivers and assign a different COM port. If we set the COM port from the Device Manager to COM100, it will assign COM100 when we disconnect/connect the device to the PC. But, if we power cycle the device, a different COM port is assigned.

    We are using the BSP from Adeneo for the iMX537 and modified the fsl_usbotg.cpp to set different events on connect/disconnect to an USB port. Here is our code:

                    

     m_OldStates = usbOtgState;

        // When otg state goes to "USBOTG_b_peripheral", we unload HCD driver & load UFN driver
        // when otg state goes to "USBOTG_a_host" we unload UFN driver & load HCD driver
        if (usbOtgState == USBOTG_b_idle)
        {
            if (m_bHostDriverRunning)
            {
                RETAILMSG(1, (L"\tOTG : Unload HCD\r\n"));
                m_bHostDriverRunning = FALSE;
                LoadUnloadHCD(FALSE);
                OUTREG32(&(m_pUsbReg->OTG.USBINTR), 0); //disable all interrupt
            }

            Sleep(2000);

            if (!m_bDevDriverRunning)
            {
                RETAILMSG(1, (L"\tOTG : Load UFN\r\n"));
                m_bDevDriverRunning = TRUE;
                LoadUnloadUSBFN(TRUE);
    SetEvent(g_hUsbDevDetect);
            }
        }
        if (usbOtgState == USBOTG_a_idle)
        {
            //RETAILMSG(1,(TEXT("NewStateAction 6 m_bDevDriverRunning %d m_bHostDriverRunning %d\r\n"),m_bDevDriverRunning,m_bHostDriverRunning));
            if (m_bDevDriverRunning)
            {
                RETAILMSG(1, (L"\tOTG : Unload UFN\r\n"));
                m_bDevDriverRunning = FALSE;
                LoadUnloadUSBFN(FALSE);
                OUTREG32(&(m_pUsbReg->OTG.USBINTR), 0); //disable all interrupt
    //SetEvent(g_hUsbDevUnDetect);
    }

            Sleep(2000);

            if (!m_bHostDriverRunning)
            {
                RETAILMSG(1, (L"\tOTG : Load HCD\r\n"));
                m_bHostDriverRunning = TRUE;
                LoadUnloadHCD(TRUE);
    SetEvent(g_hUsbDevUnDetect);
            }
        }

    Here are our settings in Platform.reg:    

    IF BSP_USBOTG
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\UsbOtg]
        "Dll" = "fsl_usbotg.dll"
        "Prefix" = "OTG"
        "Order" = dword:25
        "MemBase"=dword:53F80000    
        "MemLen"=dword:00001000        
        "Irq"=dword:12
        "IsrDll"="USB_giisr.dll"
        "IsrHandler"="ISRHandler"
        "DynamicClientLoad"=dword:3
    ;    "DynamicClientLoad"=dword:1
    ;    "DisableRoleSwitch"=dword:1
    ;    "InitialRoleMaster"=dword:1
        "HCDPortNumberOnOTG"=dword:0
        "BusIoctl"=dword:2a0048
        "InterfaceType"=dword:0
        "IClass"=multi_sz:"{6F40791D-300E-44E4-BC38-E0E63CA8375C}=%b"


    ; @CESYSGEN IF CE_MODULES_USBFN
    IF BSP_USB_HSOTG_CLIENT
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\UsbOtg\USBFN]
        "Prefix"="UFN"
        "Dll"="usbfn.dll"
        "Index"=dword:1
        "Order"=dword:22
        "MemBase"=dword:53F80000
        "MemLen"=dword:00001000
        "Irq"=dword:12
        "Priority256"=dword:64
        "OTGSupport" = dword:0
        "OTGGroup"="01"
        "BusIoctl"=dword:2a0048
        "IClass"= multi_sz:"{E2BDC372-598F-4619-BC50-54B3F7848D35}=%b","{6F40791D-300E-44E4-BC38-E0E63CA8375C}=%b"
    ENDIF BSP_USB_HSOTG_CLIENT
    ; @CESYSGEN ENDIF CE_MODULES_USBFN

    ; @CESYSGEN IF CE_MODULES_USBHOST
    IF BSP_USB_HSOTG_HOST
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\UsbOtg\Hcd]
       "Prefix"="HCD"
       "Dll"="hcd_hsotg.dll"
       "Order"=dword:15
       "Class"=dword:0c
       "SubClass"=dword:03
       "ProgIF"=dword:20
       "MemBase"=dword:53F80000
       "MemLen"=dword:00001000
       "irq"=dword:12
       "HcdCapability"=dword:4      ;HCD_SUSPEND_ON_REQUEST
       "OTGSupport"=dword:0
       "OTGGroup"="01"
       "UseExistingSettings"=dword:0
    ENDIF BSP_USB_HSOTG_HOST
    ; @CESYSGEN ENDIF CE_MODULES_USBHOST

    ENDIF ; BSP_USBOTG
    ; @CESYSGEN ENDIF CE_MODULES_USBHOST && CE_MODULES_USBFN

    IF BSP_USBOTG !

    ; @CESYSGEN IF CE_MODULES_USBFN
    IF BSP_USB_HSOTG_CLIENT
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\UFN]
        "Prefix"="UFN"
        "Dll"="usbfn.dll"
        "Index"=dword:1
        "Order"=dword:22
        "MemBase"=dword:53F80000
        "MemLen"=dword:00001000
        "Irq"=dword:12
        "Priority256"=dword:64
        "OTGSupport" = dword:0
        "OTGGroup"="01"
        "BusIoctl"=dword:2a0048
        "IClass"= multi_sz:"{E2BDC372-598F-4619-BC50-54B3F7848D35}=%b","{6F40791D-300E-44E4-BC38-E0E63CA8375C}=%b"
    ENDIF BSP_USB_HSOTG_CLIENT
    ; @CESYSGEN ENDIF CE_MODULES_USBFN

    ; @CESYSGEN IF CE_MODULES_USBHOST
    IF BSP_USB_HSOTG_HOST
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\HCD_HSOTG]
       "Prefix"="HCD"
       "Dll"="hcd_hsotg.dll"
       "Order"=dword:15
       "Class"=dword:0c
       "SubClass"=dword:03
       "ProgIF"=dword:20
       "MemBase"=dword:53F80000
       "MemLen"=dword:00001000
       "irq"=dword:12
       "IsrDll"="giisr.dll"
       "IsrHandler"="ISRHandler"
       "HcdCapability"=dword:4      ;HCD_SUSPEND_ON_REQUEST
       "OTGSupport"=dword:0
       "OTGGroup"="01"
    ENDIF BSP_USB_HSOTG_HOST
    ; @CESYSGEN ENDIF CE_MODULES_USBHOST

    ENDIF BSP_USBOTG !

    IF BSP_USB_HSH1
    [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\HCD_HSH1]
       "Prefix"="HCD"
       "Dll"="hcd_hsh1.dll"
       "Order"=dword:15
       "Class"=dword:0c
       "SubClass"=dword:03
       "ProgIF"=dword:20
       "MemBase"=dword:53F80000
       "MemLen"=dword:00001000
       "irq"=dword:0E
       "IsrDll"="giisr.dll"
       "IsrHandler"="ISRHandler"
       "HcdCapability"=dword:4      ;HCD_SUSPEND_ON_REQUEST
       "OTGSupport"=dword:0
       "OTGGroup"="02"
    ENDIF BSP_USB_HSH1

    IF SYSGEN_USBFN_SERIAL

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
       "DefaultClientDriver"=- ; erase previous default
       "DefaultClientDriver"="Serial_Class"

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Serial_Class]
          "idVendor"=dword:2A72
          "idProduct"=dword:0200
          "Manufacturer"="OUR COMPANY"
          "Product"="Device"    
          ;"DevConfig"=hex:10,00,00,00,78,00,00,00,00,01,00,00,00,4e,00,00,00,00,08,00,00,00,00,00,00
          "Index"=dword:5

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Serial_Class\Unimodem]
       "Tsp"="Unimodem.dll"
       "DeviceType"=dword:0
       "DevConfig"=hex:10,00,00,00,78,00,00,00,00,01,00,00,00,4e,00,00,00,00,08,00,00,00,00,00,00

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\Serial_Class\Config]
       "EnableFlowHard"=dword:0
       "EnableFlowSoft"=dword:0

          

    ;===============================================================================
    ; usb server

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
       "DefaultClientDriver"=- ; erase previous default
    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers]
       "DefaultClientDriver"="USBSER_Class"  

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\USBSER_Class]
       "Dll"="serialusbfn.dll"
       "DeviceName"="USBFNS2:"
       "Prefix"="COM"
       "Index"=dword:8
       "DeviceArrayIndex"=dword:1 
       "IClass"=multi_sz:"{CC5195AC-BA49-48a0-BE17-DF6D1B0173DD}","{C375C787-B721-4b8e-B67F-A112D5C0A404}"
       "idVendor"=dword:----
       "Manufacturer"="OUR COMPANY"
       "idProduct"=dword:----
       "Product"="Device"
       "bcdDevice"=dword:90
       ;"Tsp"="Unimodem.dll"
      ; "DeviceType"=dword:0

    [HKEY_LOCAL_MACHINE\Drivers\USB\FunctionDrivers\USBSER_Class\Unimodem]
       "Tsp"="Unimodem.dll"
       "DeviceType"=dword:0
       "DevConfig"=hex:10,00,00,00,78,00,00,00,00,01,00,00,00,4e,00,00,00,00,08,00,00,00,00,00,00
       ;"DevConfig"=hex: 10,00, 00,00, 05,00,00,00, 10,01,00,00, 00,4B,00,00, 00,00, 08, 00, 00, 00,00,00,00

    We can see that the USB device and USB host driver are being loaded or unloaded when we connect to an USB port:

    72374 PID:400002 TID:316001e 

    OTG : Unload HCD
    PB Debugger Unloaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\HCD_HSOTG.DLL'
      82729 PID:400002 TID:316001e  OTG : Load UFN
    PB Debugger Loaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\USBFN.DLL'
    PB Debugger Loaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\SERIALUSBFN.DLL'

    Or disconnect from a USB port:

     143039 PID:400002 TID:316001e  OTG : Unload UFN
    PB Debugger Unloaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\SERIALUSBFN.DLL'
    PB Debugger Unloaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\USBFN.DLL'
     145336 PID:400002 TID:316001e  OTG : Load HCD
    PB Debugger Loaded symbols for 'C:\WINCE700\OSDESIGNS\WORKSPACE\RELDIR\DEVICE_ARMV7_RELEASE\HCD_HSOTG.DLL'

    Also, we also get the following error when disconnecting and we are not sure of the cause: 

     145719 PID:400002 TID:33c001e USBOTG::EventNotification: VBUS ERROR entered.

    Please help,

    David L.


    • Edited by DavidL83 Wednesday, November 4, 2015 7:22 PM To clarify context
    Wednesday, November 4, 2015 7:16 PM
  • Hi David,

    Have you reached out to Adeneo as to how this is accomplished with their platform?

    Sincerely,

    IoTGirl

    Wednesday, November 4, 2015 7:36 PM
    Moderator
  • Hi IoTGirl,

    No yet because our support with them expired.

    Regards,

    Miguel Lopez

    Wednesday, November 4, 2015 7:42 PM
  • You might try the iMX Forum @ Freescale... https://community.freescale.com/community/imx

    Wednesday, November 4, 2015 9:24 PM
    Moderator
  • Hi David

    Here are some comments related to the question being asked:

    • It should be possible to control the serial port number using the "Index" key for the registry settings.
    • If it's not working, check the registry settings to make sure that "DefaultClientDriver"="USBSER_Class" is set.
    • If that default client driver is in place, then try to add a new [HKEY_CURRENT_USER\Comm\RasBook\USB] entry for it. This entry usually has a key named "Entry" containing information about the serial port number value. That's why it could be necessary to add an entry after setting "USBSER_Class" as the default client driver, specifying in the "Entry" part the value of the index being used, because it could contain a different value then the one being set.

    Adeneo Support Team


    Thursday, January 7, 2016 6:57 PM