Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last version (1.0.21/1.022) does not list all connected devices on macOS Sierra #290

Closed
amok opened this issue Apr 10, 2017 · 18 comments
Closed
Labels

Comments

@amok
Copy link

amok commented Apr 10, 2017

On master branch (seems version 1.0.21) device (STM32VLDiscovery board in my case) doesn't show up in list of connected devices, but on tag v1.0.9 it does.

Related to stlink-org/stlink/issues/574 (and comment)

➜  ~ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.3

libusb@master devices list

➜  libusb git:(master) ./examples/testlibusb
Dev (bus 20, device 5): Broadcom Corp. - Bluetooth USB Host Controller

libusb@v1.0.9 devices list

➜  libusb git:(f98eaca) ✗ ./examples/testlibusb
Dev (bus 20, device 0): 05AC - 8007
Dev (bus 20, device 5): Broadcom Corp. - Bluetooth USB Host Controller
Dev (bus 20, device 10): STMicroelectronics - STM32 STLink

➜  libusb git:(f98eaca) ✗ ./examples/listdevs
05ac:8007 (bus 20, device 0)
05ac:8290 (bus 20, device 5)
0483:3744 (bus 20, device 10)

Please let me know if you need some more debugging info.

@amok amok changed the title Last version does not list all connected devices on macOS Sierra Last version (1.0.21) does not list all connected devices on macOS Sierra Apr 10, 2017
@xor-gate
Copy link

xor-gate commented Apr 10, 2017

I think the device is bound to a kernel driver as mentioned here:

https://github.com/libusb/libusb/wiki#supported-environments

Note: the device should not be bound to a kernel driver. You can use a codeless kext to achieve that if there is a kernel driver (eg: HID or USB Mass Storage) which already binds to the device.

As the Stlink v1 programmer uses the SCSI transport (compared to Stlink v2 which uses RAW transport).

@mcuee mcuee added the macOS label Apr 26, 2017
@Marc-Aldorasi-Imprivata

This also worked in 1.0.20. It appears to be caused by 871eb29 and b7526c1, and can be worked around by applying the following patch:

diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 9946222..42fcc6e 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -516,7 +516,7 @@ static void darwin_check_version (void) {
   errno = 0;
   version = strtol (version_string, NULL, 10);
   if (0 == errno && version >= 15) {
-    darwin_device_class = "IOUSBHostDevice";
   }
 }

@@ -882,7 +882,7 @@ static int get_device_parent_sessionID(io_service_t service, UInt64 *parent_sess

   /* Walk up the tree in the IOService plane until we find a parent that has a sessionID */
   parent = service;
-  while((result = IORegistryEntryGetParentEntry (parent, kIOServicePlane, &parent)) == kIOReturnSuccess) {
+  while((result = IORegistryEntryGetParentEntry (parent, kIOUSBPlane, &parent)) == kIOReturnSuccess) {
     if (get_ioregistry_value_number (parent, CFSTR("sessionID"), kCFNumberSInt64Type, parent_sessionID)) {
         /* Success */
         return 1;

@hjelmn
Copy link
Member

hjelmn commented Aug 30, 2017

This is an odd issue. For some reason on Sierra and High Sierra the matching dictionary is not matching all devices of class IOUSBHostDevice. I can confirm it does work when matching IOUSBDevice. Not sure this is the correct fix. Digging into it now.

Looks like AppleUSBDevice as the matching class also works.

@JeremyAgost
Copy link

Is there a reason you think it's "better" to use the IOServicePlane rather than the IOUSBPlane? Presumably we only care about parent relationships for devices that are visible in the IOUSBPlane. I'm also not sure that AppleUSBDevice is the right matching class because I believe that will only match a subset of USB device classes. Not every USB device is matched by the AppleUSBDevice class, since they can be claimed by non-Apple drivers.

@EricG-Personal
Copy link

Is there any progress on this issue? I am experiencing the same problem.

If it helps, there are two terminal commands I can issue to show all of the devices or at least the devices I care about:

  1. ioreg -p IOUSB -w0 -l

  2. system_profiler SPUSBDataType

I am using macOS 10.13.3

@EricG-Personal
Copy link

EricG-Personal commented Mar 6, 2018

I did build and try the latest 1.0.22-rc3 release which mentioned improved support for Sierra and High Sierra in the release notes, but it exhibits the same problem.

@JeremyAgost
Copy link

You should try my company's fork, https://github.com/GroundControl-Solutions/libusb. We had to fix some hotplug detection issues as I recall to ensure all devices are found on Sierra and High Sierra.

@mcuee
Copy link
Member

mcuee commented Mar 9, 2018

In my case, I only see the Apple root hub (05ac:8086) is not listed in the latest version compared to libusb-1.0.20.

MyMacMini:libusb-1.0.20 xiaofanc$ ./examples/listdevs 
05ac:8281 (bus 250, device 7) path: 1.1.3
046d:c52b (bus 253, device 4) path: 1.2
1a40:0101 (bus 250, device 4) path: 1.3
0403:6001 (bus 250, device 3) path: 1.2
0fcf:1009 (bus 253, device 3) path: 1.3
05ac:8242 (bus 253, device 2) path: 1.1
0a5c:4500 (bus 250, device 2) path: 1.1
0424:2513 (bus 253, device 1) path: 1
0424:2513 (bus 250, device 1) path: 1
05ac:8006 (bus 250, device 0)
05ac:8006 (bus 250, device 0)
        
MyMacMini:libusb xiaofanc$ ./examples/testlibusb
Dev (bus 250, device 7): Apple Inc. - Bluetooth USB Host Controller
Dev (bus 253, device 4): Logitech - USB Receiver
Dev (bus 250, device 4): 1A40 - USB 2.0 Hub
Dev (bus 250, device 3): FTDI - FT232R USB UART
Dev (bus 253, device 3): Dynastream Innovations - ANT USB-m Stick
Dev (bus 253, device 2): Apple Computer, Inc. - IR Receiver
Dev (bus 250, device 2): Apple Inc. - BRCM20702 Hub
Dev (bus 253, device 1): 0424 - 2513
Dev (bus 250, device 1): 0424 - 2513

MyMacMini:libusb xiaofanc$ pwd
/Users/xiaofanc/work/libusb/libusb
MyMacMini:libusb xiaofanc$ ./examples/listdevs 
05ac:8281 (bus 250, device 7) path: 1.1.3
046d:c52b (bus 253, device 4) path: 1.2
1a40:0101 (bus 250, device 4) path: 1.3
0403:6001 (bus 250, device 3) path: 1.2
0fcf:1009 (bus 253, device 3) path: 1.3
05ac:8242 (bus 253, device 2) path: 1.1
0a5c:4500 (bus 250, device 2) path: 1.1
0424:2513 (bus 253, device 1) path: 1
0424:2513 (bus 250, device 1) path: 1

@mcuee
Copy link
Member

mcuee commented Mar 9, 2018

Okay, I inserted an iPhone (05ac:12a8) and I can reproduce this issue. 1.020 can see the device. Latest git can not.

MyMacMini:libusb-1.0.20 xiaofanc$ ./examples/listdevs 
05ac:12a8 (bus 250, device 6) path: 1.3.2
0bda:0109 (bus 250, device 5) path: 1.3.4
05ac:8281 (bus 250, device 7) path: 1.1.3
046d:c52b (bus 253, device 4) path: 1.2
1a40:0101 (bus 250, device 4) path: 1.3
0403:6001 (bus 250, device 3) path: 1.2
0fcf:1009 (bus 253, device 3) path: 1.3
05ac:8242 (bus 253, device 2) path: 1.1
0a5c:4500 (bus 250, device 2) path: 1.1
0424:2513 (bus 253, device 1) path: 1
0424:2513 (bus 250, device 1) path: 1
05ac:8006 (bus 250, device 0)
05ac:8006 (bus 250, device 0)

MyMacMini:libusb xiaofanc$ ./examples/listdevs 
0bda:0109 (bus 250, device 5) path: 1.3.4
05ac:8281 (bus 250, device 7) path: 1.1.3
046d:c52b (bus 253, device 4) path: 1.2
1a40:0101 (bus 250, device 4) path: 1.3
0403:6001 (bus 250, device 3) path: 1.2
0fcf:1009 (bus 253, device 3) path: 1.3
05ac:8242 (bus 253, device 2) path: 1.1
0a5c:4500 (bus 250, device 2) path: 1.1
0424:2513 (bus 253, device 1) path: 1
0424:2513 (bus 250, device 1) path: 1

@JeremyAgost
Copy link

Later today I should have time to pull-request from our branch to resolve that issue.

@mcuee
Copy link
Member

mcuee commented Mar 25, 2018

@JeremyAgost Now 1.022 has been released, can you get the pull-request against latest git? Thanks.

@mcuee mcuee changed the title Last version (1.0.21) does not list all connected devices on macOS Sierra Last version (1.0.21/1.022) does not list all connected devices on macOS Sierra Mar 25, 2018
@mcuee
Copy link
Member

mcuee commented Jul 29, 2020

My Mac Mini died. Is this issue still there in the master git?

@JeremyAgost
Copy link

JeremyAgost commented Jul 31, 2020

In the product that we integrate libusb, we've simply dropped support for macOS Sierra partly because of this issue. We're not set up to test with those earlier OS versions anymore. Sorry I can't help more.

@mcuee
Copy link
Member

mcuee commented Aug 3, 2020

@JeremyAgost Thanks for the update. Can you confirm that High Seirra macOS 10.13 (successor to Sierra macOS 10.12) has no issue? Thanks. And hopefully 10.14 Mojave and 10.15 Catalina are okay as well.

@mcuee
Copy link
Member

mcuee commented Aug 3, 2020

stlink-org/stlink#574

The above stlink issue says that 1.0.23 sorted out the issue.


Here we actually had two separate problems in one issue:

libusb problems with device detection in macOS:
Bug in external libusb library, solved in v1.0.23, which is also distributed via the package repositories homebrew and MacPorts per default. Thus this is no longer an issue.

ST-Link-v1 driver issue relates to Kernel Extensions (kext):
Closed by commit 59c5cfd.

@mcuee
Copy link
Member

mcuee commented Aug 3, 2020

#428

It seems this has been fixed in Pull Request 428 and release 1.0.23.

@amok
Copy link
Author

amok commented Aug 3, 2020

Then I'm closing this. Ping me here to reopen in case the issue persists

@amok amok closed this as completed Aug 3, 2020
@hjelmn
Copy link
Member

hjelmn commented Jul 21, 2021

Coming back around to this. From what I can tell this is a bug in 11.12.x and other macOS releases. Even though the iPhone shows up as class IOUSBHostDevice it doesn't show up in the device iterator for that class. Apple fixed this by macOS 11.

There are benefits to going back to using IOUSBHostDevice so I will look for a workaround that works with all versions until we no longer support the last broken version (I will check 10.13 and 10.14).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants