FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: VNC2 re-enumeration after first remove the HID device  (Read 20577 times)

Yvonne

  • Newbie
  • *
  • Posts: 12
    • View Profile
VNC2 re-enumeration after first remove the HID device
« on: July 03, 2023, 04:53:43 AM »

Hello,

I am using the VNC2 chip as the USB host to handle HID devices (USB reader, barcode scanner and keyboard) scanning and transmitting data. Based on the example code "USBHostHIDKbd", I use the USBHost Driver and HID Driver in my code. In my code,  I use the "usbhost_connect_state" function to check whether the plugin HID device has completed the enumertaion process and got the status of enumeration become PORT_STATE_ENUMERATED.

The following is my code which is almost the same as the sample function provided in example code:
Code: [Select]
unsigned char usbhost_connect_state(VOS_HANDLE hUSB) {
    unsigned char connectstate = PORT_STATE_DISCONNECTED;
    usbhost_ioctl_cb_t hc_iocb;

    if (hUSB) {
    hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_CONNECT_STATE;
    hc_iocb.get = &connectstate;
    vos_dev_ioctl(hUSB, &hc_iocb);

    // repeat if connected to see if we move to enumerated
    if (connectstate == PORT_STATE_CONNECTED) {
vos_dev_ioctl(hUSB, &hc_iocb);
    }
    }
    return connectstate;
}

I can successfully transmit data on the very first plugin after flashing the .rom file on the VNC2 chip. However, when I remove the first plugined HID device and re-plugin another HID device, the status of enumeration result can not get into PORT_STATE_ENUMERATED. This made the another HID device cannot scan and transmit data.

I look up the Vinculum II User Guide documentation and found another code as follows:
Code: [Select]
unsigned char changeInEnumeration(VOS_HANDLE hUsbHost)
{
    usbhost_ioctl_cb_t usbhost_iocb;
    static unsigned short prev;
    unsigned short i;
    // wait until enumeration change
   
func_count++;

do
    {
        vos_delay_msecs(1);
        usbhost_iocb.ioctl_code = VOS_IOCTL_USBHOST_GET_ENUMERATION_HANDLE;
        usbhost_iocb.get = &i;
        vos_dev_ioctl(hUsbHost, &usbhost_iocb);
    } while (i == prev);

    // keep handle for next call
    prev = i;
    return i;
}

When I declare the changeInEnumeration function in my code but not call it in main.c or any other functions, the enumeration works for all the HID devices no matter how many times for plugin, remove and re-plugin. I wonder is the changeInEnumeration function would be called in the background for VNC2 when plugin and remove the HID device? Or any suggestion to solve the enumeration between switches for different HID devices doing plugin and remove process of the HID devices are appreciated.

Thank you so much again!

Yvonne
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 897
    • View Profile
Re: VNC2 re-enumeration after first remove the HID device
« Reply #1 on: July 04, 2023, 10:05:42 AM »

Hi Yvonne,

I did the same experiment, but I could detect the second HID device successfully.
I've checked our source code and there is nowhere that is actively calling the changeInEnumeration function.
At present, I can only suspect that the possible reason is that there is something wrong with the program you are running, which leads to such strange things happening.

Could you provide us more details, so we can clarify the problem?

Best regards

FTDI Community

Logged

Yvonne

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: VNC2 re-enumeration after first remove the HID device
« Reply #2 on: July 06, 2023, 10:46:13 AM »

Hello,

I kept tried to modified my code and now I can use the modified example code "USBHostHIDKbd" to scan data for the three HID devices (USB reader, barcode scanner and keyboard) mentioned previously. And data can be successfully scanned after plugin, remove and re-plugin. This example code is used based on opening the USBHost driver and attaching the HID driver.

However, I used the example code "USBHostHID2" to try to get the same function previously. In this code, I used the same enumeration function "usbhost_connect_state" as mentioned before. However, I can only scan data at the very first plugin for the HID device. When I remove the HID device and re-plugin another HID device, the enumeration can fail all the time. I wonther that in this usbhost_connect_state function, is it can always get the PORT_STATE_ENUMERATED state during several connection try? or could the state after doing the usbhost_connect_state function always stay in PORT_STATE_CONNECTED or PORT_STATE_DISCONNECTED? (which means I will alway not get ready for enumeration.)

I sometimes see the value of status show in PORT_STATE_CONNECTED and then becomes to PORT_STATE_ENUMERATED after a while in checking this function in both "USBHostHIDKbd" and "USBHostHID2" example codes. May I ask what's the difference between the PORT_STATE_CONNECTED and PORT_STATE_ENUMERATED? In the example code, the if condition only allow the state of PORT_STATE_ENUMERATED to go into reading data process.

I also write another function to get the status of "usbhost_connect_state" until the status become PORT_STATE_ENUMERATED which is shown as follows.
Code: [Select]
status = usbhost_connect_state(hUSBHOST_1);
while (status != PORT_STATE_ENUMERATED) {
                  close_drivers();
          vos_delay_msecs(100);
  open_drivers();

  status = usbhost_connect_state(hUSBHOST_1);
}

If I found my code encounter the situation that the first enumeration could success but the second, third and other enumeration afterwards could fail,  what could be the problem or any debug suggestions are appreciated in advanced!

Thank you so much!

Yvonne
Logged

FTDI Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 897
    • View Profile
Re: VNC2 re-enumeration after first remove the HID device
« Reply #3 on: July 11, 2023, 09:57:49 AM »

Hi Yvonne,

-------------------------------------------------------------------------------------------------------------------------------------------------
Q: May I ask what's the difference between the PORT_STATE_CONNECTED and PORT_STATE_ENUMERATED?

PORT_STATE_CONNECTED:
Before the USB starts to enter the enumeration process.

PORT_STATE_ENUMERATED:
USB successfully completed the enumeration process.

If the USB enumeration fails, it means that the USB driver cannot operate successfully.

----------------------------------------------------------------------------------------------------------------------------------------------------
Q:  However, I used the example code "USBHostHID2" to try to get the same function previously.
In this code, I used the same enumeration function "usbhost_connect_state" as mentioned before.
However, I can only scan data at the very first plugin for the HID device. When I remove the HID device and re-plugin another HID device, the enumeration can fail all the time.

 Sorry, this is the restriction of this sample code.

Q: could the state after doing the usbhost_connect_state function always stay in PORT_STATE_CONNECTED or PORT_STATE_DISCONNECTED?
       
No, it will change according to the actual state of the USB device.

Best Regards

FTDI Community

Logged