Author Topic: using libusb with multiple endpoints  (Read 20489 times)

ADB

  • Member
  • ***
  • Posts: 26
using libusb with multiple endpoints
« on: July 04, 2019, 11:21:34 am »
Hi Jan,

Up to now, I've been working with an embedded device that was ennumerating as a simple libusb device in Windows' device manager. I was then able to write a C++ application based on the libusb library to receive bulk packets from my device.

My project requirements have changed on me and my embedded device is now ennumerating as a composite device with a virtual COM port and 2 instances of a simple libusb device. As expected I can see a VCOM, a USB composite device and 2 libusb "USB serial bus devices" in Windows device manager.

I've been able to check that the VCOM interface works OK using tera term. I've tried to modify my libusb based PC application (by changing the interface number and endpoints) to communicate with my embedded device but I get the following errors:

Device Opened
libusb: error [parse_endpoint] invalid extra ep desc len (0)
libusb: error [raw_desc_to_config] parse_configuration failed with error -1
libusb: warning [windows_assign_endpoints] could not read config descriptor: error -1
Cannot Claim Interface
Cannot Release Interface

Is this a limitation of libusb? Is the libusb library unable to use multiple endpoints?

Once I modified the manufacturer and device ID in your Winusb c# program, it was able to pick up all the instances of my embedded device. Would a winusb driver be more suitable to my needs?

Thanks in advance for your advice,

Regards,

Alan





Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: using libusb with multiple endpoints
« Reply #1 on: July 04, 2019, 05:09:54 pm »
First thing to try if you haven't:


After changing a descriptor, to force Windows to forget the previous descriptors, with the device attached, open Windows Device Manager and uninstall the device (under Driver). Then reattach.

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #2 on: July 05, 2019, 03:31:44 am »
Hi Jan,

Thank you for your message. I've done that. Now when I call libusb_get_device_descriptor in my code, my device appears twice.

Regards,

Alan

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #3 on: July 05, 2019, 07:30:54 am »
Hi Jan,

The WINUSB C# program picks up my 4 device interfaces using WMI. For the program to be able to write/read to it, I take it that it needs to find each interface using its GUID? Should this be set on my embedded device using "Microsoft Extended Properties Feature Descriptor".

Would I be better going down the WINUSB C# route rather than libusb?

Thanks in advance for your advice on this.

Regards,

Alan

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: using libusb with multiple endpoints
« Reply #4 on: July 05, 2019, 09:07:54 pm »
Either WinUSB or libusb should work.

Maybe you overlooked something in modifying the libusb program. That's where I would look first.

I have WinUSB example code here:

http://janaxelson.com/winusb.htm

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #5 on: July 08, 2019, 11:55:15 am »
Hi Jan,

Thank you for getting back to me. I've made some progress today: I've modified the order of the device descriptors on my embedded device. Now when I call libusb_get_device_descriptor, followed by libusb_get_config_descriptor my embedded device is picked up twice.

In both cases the ConfigurationDescriptors are the same but on closer inspection, libusb has only picked up my first interface. In my device descriptor array, I've set the following to use IAD descriptors (used to setup my VCOM port):

 0xEF, // bDeviceClass
 0x02, // bDeviceSubClass
 0x01, // bDeviceProtocol

Could this be preventing independent classes from ennumerating? Could something similar be achieved with the use of bInterfaceClass, bInterfaceSubClass and bInterfaceProtocol? Is an example of this available anywhere?

Thanks again,

Alan

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: using libusb with multiple endpoints
« Reply #6 on: July 08, 2019, 05:28:00 pm »
This is correct:

0xEF, // bDeviceClass
0x02, // bDeviceSubClass
0x01, // bDeviceProtocol

The IAD should then identify the interfaces that belong to the communications function.

The other two interfaces should each specify the libusb function.

If you post your descriptors, we might see something.

Here is one example:

https://www.microchip.com/forums/m735655.aspx

https://bitbucket.org/sparkbuzz/pic32_usb.x/src/default/usb_descriptors.c

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #7 on: July 09, 2019, 03:42:06 pm »
Hi Jan,

Thank you for the links, I will take a closer look when I'm in the office tomorrow.

I've attached the C file that contains my descriptors.

Thanks again,

Alan

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #8 on: July 10, 2019, 11:48:52 am »
Hi Jan,

I think I've made some progress today. I came across the following website: https://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/

If I run the printdev function I'm able to get the following response:

Number of possible configurations: 1  Device Class: ef  VendorID: 1fc9  ProductID: 8a
Interfaces: 4 | Number of alternate settings: 1
Interface Number: 2 | Number of endpoints: 2 | Descriptor Type: 5 | EP Address: 2 | Descriptor Type: 5 | EP Address: 82 | Number of alternate settings: 1
Interface Number: 3 | Number of endpoints: 2 | Descriptor Type: 5 | EP Address: 4 | Descriptor Type: 5 | EP Address: 84 | Number of alternate settings: 1
Interface Number: 0 | Number of endpoints: 1 | Descriptor Type: 5 | EP Address: 83 | Number of alternate settings: 1
Interface Number: 1 | Number of endpoints: 2 | Descriptor Type: 5 | EP Address: 1 | Descriptor Type: 5 | EP Address: 81 |

It would appear that libusb is picking up my device correctly.

Regards,

Alan

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: using libusb with multiple endpoints
« Reply #9 on: July 10, 2019, 03:08:34 pm »
Good to hear, thanks for reporting back.

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #10 on: July 11, 2019, 11:31:13 am »
Hi Jan,

I've been able to modify your winusb c# program to communicate with either of my winusb interfaces.

So far, only 1 of my interfaces is coming up as WCID comptatible. Do you have any examples of "Microsoft Compatible ID Feature Descriptor" with 2 sections and of "Microsoft Extended Properties Feature Descriptor " with 2 GUIDs?

Thanks in advance for your help with this.

Regards,

Alan

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research

ADB

  • Member
  • ***
  • Posts: 26
Re: using libusb with multiple endpoints
« Reply #12 on: July 16, 2019, 02:59:04 am »
Thanks.

Alan