This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB CDC device problem

Hi,

I am working on a USB CDC device using the LM3s5C51 controller. I am continuously transmitting a string from the device. Now I check This string on the hyperterminal on the virtual comport.

Now if I disconnect the device and then again I connect the device it does not transmit any string. Also when I disconnect the device there is no event disconnected reported. The device goes into suspend state and after again connecting the device it does not show any event connected message. Is this a problem beacuse my device self powered ? 

Regards

Dhanush

  • Your problem is a common one on Windows USB application.
    - If a USB device disconnects (by plug off or reset) while an application opens the device, the application can’t open the device again after the device reconnects.

    As the requirement of PC application, which opens a USB device,
    the application has to close the device handle immediately, when the device disconnects. After the device reconnects, the application re-opens the device.

    This is common requirement of USB applications, not just for CDC (VCP: virtual COM Port), also for HID, WinUSB, etc.

    To satisfy this requirement, WM_DEVICECHANGE message is available to detect device connection change.
    - Application registers the device interface to the system, using RegisterDeviceNotification(), when it firstly opens the device. And then, WM_DEVICECHANGE message is sent to the application when the device disconnects/ re-connects (DBT_DEVICEREMOVECOMPLETE / DBT_DEVICEARRIVAL).

    As of the "Port" setup-class devices like COM ports, MSDN describes as follows.

    RegisterDeviceNotification function
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa363431(v=vs.85).aspx
    The DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events are automatically broadcast to all top-level windows for port devices. Therefore, it is not necessary to call RegisterDeviceNotification for ports, and the function fails if the dbch_devicetype member is DBT_DEVTYP_PORT.

    Fine. Virtual COM port doesn’t need to register its device interface. This scenario works for USB-UART drivers of FTDI, SiLabs, Prolific, etc. However, it doesn’t work for usbser.sys (Windows built-in CDC driver), because of defect of this driver. As the requirement of COM port driver, usbser.sys should register a device interface of GUID_DEVINTERFACE_COMPORT. And this registration would bring above COM port option.

    GUID_DEVINTERFACE_COMPORT
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff545821(v=vs.85).aspx
    The system-supplied function driver for serial ports registers an instance of this device interface class for a serial port.

    usbser.sys doesn’t register this device interface, violating above MS rule. This defect has been known for at least these 10 years, but MS have left it unfixed so long.
    This is one of many defects of usbser.sys, I don’t recommend usbser.sys for decent application, just for toys.


    The workarounds of this usbser.sys defect are,
    A) Application regularly polls the connection of target COM port.
    - Using WMI
    http://www.microchip.com/forums/FindPost/560699
    or
    - Using SetupDi-API
    http://www.microchip.com/forums/FindPost/365029

    OR
    B) Assign serenum.sys as a filter driver of usbser.sys.

    Register GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR of serenum.sys for device notification.

    Tsuneo

  • Hi Tsuneo,

    Thank you for the response. 

    In Stellaries USB library guide I read this line.

    In device mode, the USB_EVENT_DISCONNECTED event will not be reported to the application
    if the MCU’s PB1/USB0VBUS pin is connected to a fixed +5 Volts rather than directly to the
    VBUS pin on the USB connector.

    My controller has an external voltage  of 3.3 volt. In my circuit I had previously connected PB1 to fixed 5V and in the config descriptor I stated this as a self powered device. But then after reading the above lines I changed PB1 and connected directly to VBUS pin on the connector and then in the config descriptor I stated it as a bus powered device. Am I doing anything wrong here. I dont get the disconnect Event in both the cases.

    Also I am trying that my device after it gets disconnected from the host should give a disconnect event and when it connect it gives a event connect msg.

    I am using a serial to USB converter  (cable) which is a fully bus powered device. I transmit my data on UART and in between my pc and device I use a serial to usb cable. I check this on hyperterminal using virtual comport. Even after I disconnect and then reconnect it and on the hyperterminal I click the disconnect and connect icon , it does work fine but my device does not work as above Is this still a problem with usbser.sys .

    Regards

    Sanket

     

  • Dhanush Nair said:
    I check this on hyperterminal using virtual comport. Even after I disconnect and then reconnect it and on the hyperterminal I click the disconnect and connect icon , it does work fine but my device does not work as above Is this still a problem with usbser.sys .


    It’s so-called connection recovery feature of PC driver.
    I tested this feature on the latest drivers of FTDI, SiLabs and Prolific. All of drivers work as you described.

    When I had tested this feature 5 years ago, FTDI worked, but SiLabs failed. I didn’t test it on Prolific. In those days, FTDI had proudly announced this feature. SiLabs should have recently refined their driver.

    usbser.sys still fails this feature on Windows7 and even on 8.1
    And it is natural for MS driver, because its behavior faithfully follows MS guideline.

    If you would like this feature, you should change the PC driver.

    Tsuneo

  • its a bug in USB library. i am using tiva-c 2.1.1 where this problem completely solved . recently i realized this on tiva-c 2.0.1 : when we disconnect device during enumeration phase , device fall into an infinite loop waiting for device status change. use USB library presented on 2015 by ti
  • Hello Ali

    Another note though. There was another issue we thought in the Fat FS implementation for a USB Stick, where USB behaved the same. Closer inspection did reveal that the Fat FS initialization was not handled by the application code (all good on TivaWare)

    Regards
    Amit
  • Dear Tsuneo,

    in your message,

    B) Assign serenum.sys as a filter driver of usbser.sys.

    Register GUID_DEVINTERFACE_SERENUM_BUS_ENUMERATOR of serenum.sys for device notification.

    how to do this in the inf file setting?

    any extra file needed for this operation?

    Thanks,

    Shaowei