Repository navigation
Conversation
0872ad3 to
3b373df
Compare
|
I'm satisfied with current implemention. It's get a little tricky but reasonable. From my perspective it would be nice to get some feedback from someone with better understanding of libusb internals. I've done some testing with composite and non-composite devices but my plan is to repeat them in more formalized manner before dropping WIP status. However I will be able to do that in ~2 weeks and I wanted to share current status. There is dependency on PR #965 which waiting for some formatting fixes. If necessary I'm willing to apply them in this PR |
|
I finally managed to properly test these changes - things are working correctly, see test report linked in PR description. |
|
It is great that you have included a test report. I would be reassured if we had some more review comments and testing from others as well though. @RyanMetcalfeNovanta what do you think about this PR? |
3b373df to
ccac965
Compare
|
@tormodvolden @mcuee I've rebased this branch on top of changes in #965 and performed testing again - works as expected, also in real use case where I found this issue in first place |
ccac965 to
aa60876
Compare
tormodvolden
left a comment
There was a problem hiding this comment.
I did just a first quick look at the code. It is a significant behavior change so someone into Windows will need to check it.
177bebf to
fe8cae8
Compare
|
This is not a test for the purpose of this PR (using two applications to access different interfaces of the same device), but rather to show some behavior differences of this PR with git master. Test device: Raspberry Pi Pico W with CicrcuitPython FW. I have used WinUSB driver to replace the Mass Storage driver (Interface 2), the CDC-ACM driver (Interface 0/1, with IAD) and the USB Audion Driver (Interface 4/5, no IAD). Interface 3 is using USB HID driver (USB HID Keyboard). Take note Claiming Interface 5 will fail as it is not using IAD -- therefore PR #965 will not help. |
|
Please take a look at my test result and see if the differences are expected. Thanks. |
fe8cae8 to
26b5740
Compare
|
@mcuee Branch rebased with changes as requested by @tormodvolden applied. I still need to do some testing but I would like to at least let you proceed with code review. I don't see any dangerous differences in outputs you provided. Probably verbosity of logs is a bit to high (will reduce them to debug). Could you re-run xusb with rebased branch? I assume that lack of "Reading OS string descriptor" is caused by not-including something that was added recently. I don't quite understand what Max LUN is and why it is different (it should be the same?) |
26b5740 to
d67cf68
Compare
|
Great. Now I do not see differences between git master and this PR. Ignore the MAX LUN number as it seems to be random -- it seems to me the USB Mass Storage in this Circuit Python FW is not compliant and the number is random. |
|
Please take a look at this PR when you got the time. Thanks. |
…nUSB interfaces, also requires: libusb/libusb#1181
|
I have set this for milestone 1.0.31. But we need to wait for the review of the other maintainers like @sonatique. |
|
Hi, I'm trying to debug a Windows app regression I found after using this PR and was hoping that someone smarter than me would help me understand something. What happens here if I try to claim an interface while already claimed? If I understand correctly |
|
Please help to rebase to the latest git when you got the time. Thanks. |
|
Using the tip from @tormodvolden here. |
|
This does not seem to work cannot with ST-Link under ARM64 with manually install WInUSB driver (ST does not provide the driver for ARM64). Same as libusb git. Not so sure if it is linked to the following or not. USBView ARM64 output. Details |
Windows manages each sub-device of composite device as separate device - each one requires separate call to CreateFile to obtain dev_handle. Opening all sub-devices eagerly prevents other applications for accessing any sub-device even if application that opened the device is not using them. This commit modifies WinUSB backend to call CreateFile lazily, so device handle is opened when necessary (by claiming the interface) and release as soon as possible (by releasing the interface). Implementation details: * winusbx_open becomes essentially no-operation * winusbx_claim_interface ensures that device handle is opened * interface used to initialize WinUSB handle has associated counter of claimed interfaces * claiming and releasing interfaces modifies ref-counter accordingly * when counter reaches zero on releasing interface, device handle is closed Signed-off-by: Maciej Nowak <maciejt.nowak@gmail.com>
43d16cd to
6abbc4f
Compare
I've rebased branch on top of master but did not run any tests. As this PR is nearing four years I would like to recommend anyone who is affected by this bug to use Rust's crate nusb (https://github.com/kevinmehall/nusb) - it does not use libusb underneath and do not have problem with concurrent access to composite devices. |
Thanks for the update. Unfortunately libusb project was without a real Windows backend maintainer from March 2021 to Aug 2025, until @sonatique came on board in Aug 2025. Main Windows developers for libusb project: |
| initialized_iface = 0; | ||
| } | ||
|
|
||
| usbi_dbg(ctx, "libusb: release_interface(%p, %d) initialized_iface=%d claimed_count = %d", dev_handle, iface, initialized_iface, handle_priv->interface_handle[initialized_iface].claimed_interfaces_count); |
There was a problem hiding this comment.
"libusb: " prefix makes me think that this is maybe a leftover instrumentation debug rather than a debug we need to merge. Should be trimed or droped
|
Tested together with #1830, works great! |
|
Correction: This change causes a crash on |
|
@maxtruxa : any news from your further tests ? |
|
Seem to work for the following device. Microsoft USBview output. Details |
|
On the other hand, libusb git also works. |
|
Sorry for the late response. I got a working patch with various fixes that I will rebase on master and submit within the next few days. |
@maxtruxa, we're developing software for a device with multiple winusb interfaces and have run into #1177. We're creating a libusb hotfix by cherry picking the following commits on top of libusb@v1.0.30:
If you're willing to share your patch, we'd be happy to include it in our fix and run in through our test pipeline. For reference: UsbDotNet: Patch libusb issue #1177 |
This is work-in-progress, I'm opening PR to get initial feedback/review and possibly be tested by others.
Fixes #1177 and includes changes from #965.
Summary of changes:
winusbx_openessentially no-opwinusbx_claim_interfaceis called it ensures that device handle is valid, if not -CreateFileis called.winusbx_release_interfaceuses refcounting to release WinUSB device and device handle.I did not test how it behaves with libusb-filter (never used that, so some catching up to do first).With composite device containing several WinUSB devices (some of them grouped in IAD) libusb behaves correctly -CreateFileis delayed until claiming interfaces and handle is closed as soon as last associated interface is released.Test report https://gist.github.com/Novakov/4b2d4094825b83ef58b23060224660f8
printfs are left on purpose and will be removed before finalizing - I'm dropping recompiledlibusb.dllwhere I can (OpenOCD and Orbuculum mostly) to check if devices are opened/closed as supposed to, having debug printfs available makes it easier.