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

[macOS] ST-Link-v1 driver issues / libusb problems #574

Closed
karpenet opened this issue Mar 18, 2017 · 23 comments
Closed

[macOS] ST-Link-v1 driver issues / libusb problems #574

karpenet opened this issue Mar 18, 2017 · 23 comments

Comments

@karpenet
Copy link

Unable to build driver on macOS Sierra 10.12.3

Output:

OS X version not supported.
make: *** [osx_stlink_shield] Error 1

Expected/description:
Tried building with Yosemite and El Capitan configurations as in driver readme, none seem to work.

@xor-gate
Copy link
Member

I'm not sure you need the driver for stlinkv1 on newer OS X. If you get your hands on a stlinkv2 this is recommended as they also can measure target voltage. The stlinkv1 is deprecated some time ago by ST Microelectronics.

@xor-gate xor-gate added this to the Unplanned (Contributions Welcome) milestone Mar 18, 2017
@karpenet
Copy link
Author

A lot of Discovery boards still ship with the stink-v1. I'm using the STM32VLDiscovery board which has this version too.

@xor-gate
Copy link
Member

Have you tried texane/stlink tools without driver?

@amok
Copy link

amok commented Apr 2, 2017

@xor-gate it does't work.
ST-LINK V2 works, but STM32VLDiscovery with its v1 - doesn't
it's even unable to find a device

➜  system_profiler SPSoftwareDataType
Software:

    System Software Overview:

      System Version: macOS 10.12.3 (16D32)
      Kernel Version: Darwin 16.4.0
      Boot Volume: Macintosh HD
      Boot Mode: Normal
      Computer Name: xxx
      User Name: xxx
      Secure Virtual Memory: Enabled
      System Integrity Protection: Disabled
      Time since boot: 14:52

➜  system_profiler SPUSBDataType
USB:

    USB 3.0 Bus:

      Host Controller Driver: AppleUSBXHCIWPT
      PCI Device ID: 0x9cb1
      PCI Revision ID: 0x0003
      PCI Vendor ID: 0x8086

         ...

        STM32 STLink:

          Product ID: 0x3744
          Vendor ID: 0x0483  (STMicroelectronics)
          Version: 1.00
          Serial Number: Vÿk?RpQPV"?g
          Speed: Up to 12 Mb/sec
          Manufacturer: STMicroelectronics
          Location ID: 0x14100000 / 9
          Current Available (mA): 500
          Extra Operating Current (mA): 0

➜  st-util
st-util 1.3.1
2017-04-02T18:36:39 WARN src/usb.c: Couldn't find any ST-Link/V2 devices

➜  lsusb
...
Bus 020 Device 009: ID 0483:3744 STMicroelectronics STM32 STLink  Serial: Vÿk?RpQPV"?g

➜  STLINK_DEVICE=020:009 st-util
st-util 1.3.1
2017-04-02T18:38:33 INFO src/usb.c: bus 020 dev 009
2017-04-02T18:38:33 WARN src/usb.c: Couldn't find matched ST-Link/V2 devices

➜  st-util -1
st-util 1.3.1
2017-04-02T18:40:55 WARN src/sg.c: Failed to find an stlink v1 by VID:PID
2017-04-02T18:40:55 ERROR src/sg.c: Could not open stlink device

@xor-gate
Copy link
Member

xor-gate commented Apr 3, 2017

Probably the kernel attaches to SCSI driver, so you are unable to see it.

@amok
Copy link

amok commented Apr 3, 2017

ioreg says

+-o STM32 STLink@14100000  <class AppleUSBDevice, id 0x100007d84, registered, matched, active, busy 0 (28 ms), retain 16>

I am not sure, but shouldn't it be IOUSBAttachedSCSI or something?

@amok
Copy link

amok commented Apr 3, 2017

@xor-gate seems st-util is able to detect and connect to board using prior version of libusb, I tried v1.0.9

➜  stlink git:(master) ./build/Release/src/gdbserver/st-util
st-util 1.3.1-12-g6902f47
2017-04-04T02:04:39 INFO src/common.c: Loading device parameters....
2017-04-04T02:04:39 INFO src/common.c: Device connected is: F1 Medium/Low-density Value Line device, id 0x10016420
2017-04-04T02:04:39 INFO src/common.c: SRAM size: 0x2000 bytes (8 KiB), Flash: 0x20000 bytes (128 KiB) in pages of 1024 bytes
2017-04-04T02:04:39 INFO src/gdbserver/gdb-server.c: Chip ID is 00000420, Core ID is  1ba01477.
2017-04-04T02:04:39 INFO src/gdbserver/gdb-server.c: Listening at *:4242...

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)

it is might be related to libusb/libusb#282 somehow

@xor-gate
Copy link
Member

xor-gate commented Apr 4, 2017

@amok that was a detailed investigation. I'm glad we see this fixed in libusb. Good work!

@karpenet
Copy link
Author

karpenet commented Apr 10, 2017

Thanks @amok but I'm still getting an error.

No other programs using the port.

$ system_profiler SPUSBDataType
USB:

    USB 3.0 Bus:

      Host Controller Driver: AppleUSBXHCIWPT
      PCI Device ID: 0x9cb1 
      PCI Revision ID: 0x0003 
      PCI Vendor ID: 0x8086 

        Bluetooth USB Host Controller:

          Product ID: 0x8290
          Vendor ID: 0x05ac  (Apple Inc.)
          Version: 1.46
          Speed: Up to 12 Mb/sec
          Manufacturer: Broadcom Corp.
          Location ID: 0x14300000 / 4
          Current Available (mA): 500
          Current Required (mA): 0
          Extra Operating Current (mA): 0
          Built-In: Yes

        STM32 STLink:

          Product ID: 0x3744
          Vendor ID: 0x0483  (STMicroelectronics)
          Version: 1.00
          Serial Number: Vÿl?Q�RP"1?�
          Speed: Up to 12 Mb/sec
          Manufacturer: STMicroelectronics
          Location ID: 0x14200000 / 8
          Current Available (mA): 500
          Current Required (mA): 100
          Extra Operating Current (mA): 0
$ st-util

st-util 1.3.1-12-g6902f47
2017-04-10T14:42:11 WARN src/usb.c: Stlink usb device found, but unable to claim (probably already in use?)
[!] send_recv send request failed: LIBUSB_ERROR_NOT_FOUND
[!] send_recv STLINK_DEBUG_RESETSYS
2017-04-10T14:42:11 INFO src/gdbserver/gdb-server.c: Chip ID is 00000000, Core ID is  00000000.
2017-04-10T14:42:11 INFO src/gdbserver/gdb-server.c: Listening at *:4242...
$ st-util -1

st-util 1.3.1-12-g6902f47

libusb: 0.000000 info [process_new_device] allocating new device for location 0x14000000
libusb: 0.000057 info [darwin_check_configuration] active config: 0, first config: 1
libusb: 0.000061 warning [process_new_device] Got unknown device speed 3
libusb: 0.000075 info [process_new_device] found device with address 0 at 000-05ac-8007-09-ff
libusb: 0.000495 info [process_new_device] allocating new device for location 0x14300000
libusb: 0.034344 info [darwin_check_configuration] active config: 1, first config: 1
libusb: 0.034407 info [process_new_device] found device with address 4 at 004-05ac-8290-ef-02
libusb: 0.034756 info [process_new_device] allocating new device for location 0x14200000
libusb: 0.034836 info [darwin_check_configuration] active config: 1, first config: 1
libusb: 0.034843 info [process_new_device] found device with address 8 at 008-0483-3744-00-00
libusb: 0.035367 info [darwin_open] device open for access
libusb: 0.035728 error [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access
2017-04-10T15:07:37 WARN src/sg.c: libusb_claim_interface() failed
libusb: 0.036108 info [event_thread_main] thread exiting
2017-04-10T15:07:37 ERROR src/sg.c: Could not open stlink device

@DouglasPearless
Copy link

I am getting exactly the same error :-(

@amok
Copy link

amok commented Apr 10, 2017

@xor-gate sorry for confusion
in my case last version of libusb does not work, but v1.0.9 works
so seems this bug (or feature) with devices list was introduced in some of the last versions
created issue libusb/libusb#290

@karpenet I am not sure we have the same issues (if so - sorry for spamming your thread). have you tried to downgrade libusb?

@xor-gate
Copy link
Member

Hi @amok its not a problem to discus here which probably could cause the problem.

@C44Supra
Copy link

C44Supra commented Apr 18, 2017

I'm having a similar issue (as per issue #587). I have built stlink from the latest source and installed it with homebrew on separate occasions. Without the driver / kext I get:

$ st-util -1
st-util 1.3.1
libusb: error [darwin_claim_interface] USBInterfaceOpen: another process has device opened for exclusive access
2017-04-18T15:21:43 WARN src/sg.c: libusb_claim_interface() failed
2017-04-18T15:21:43 ERROR src/sg.c: Could not open stlink device

And with the driver I get:

$ st-util -1
st-util 1.3.1
2017-04-18T15:04:32 WARN src/sg.c: Failed to find an stlink v1 by VID:PID
2017-04-18T15:04:32 ERROR src/sg.c: Could not open stlink device

I've had to modify the install.sh file so that it installs the 10.10 kext on Sierra. I also have the kext-dev-mode flag set but I'm not quite sure that method even does anything anymore on Sierra. Sierra itself does detect the device (I can see it in the System Profiler, deviceID and productID seem to be correct too).

As an experiment I installed Ubuntu 17.04 in a VM on the same system, built stlink from the same source, reconnected the board to the system and when VMWare Fusion asked me to choose a "destination" for the STLink I chose "Ubuntu". Started st-util -1 and it worked flawlessly in Ubuntu.

I'm inclined to believe that this might be a kext issue. As long as there's no kext installed it is detected but can't be claimed, most likely due to the mass storage issue. Once the kext is installed however stlink can't find it.

As of this moment I'm running whatever version libusb was installed automagically (most likely 1.0.21?) and I honestly have no idea how to install an older version (like 1.0.9) to see if this resolves the problem on my end as well.

@amok
Copy link

amok commented Apr 19, 2017

... how to install an older version ...

the simplest way probably would be to git clone libusb repo and then compile it on v1.0.9 tag and then symlink binaries to /usr/local/lib/
@C44Supra could you please try the same - curious will it work for you

@C44Supra
Copy link

C44Supra commented Apr 19, 2017

@amok I've been trying to do that but I fear something is just not going quite right.

I've got one folder in my home dir where I keep all my STM32 related stuff which is where I execute all of these commands from. Here are the literal steps that I've taken so far:

$ git clone https://github.com/libusb/libusb.git
$ cd libusb
$ git reset --hard ab9cd5a7be637f7b793987971a706b1d11c27ded

So far, so good. I've checked the files and I see numerous references to v 1.0.9. Now it get's sketchy. The first command to run, according to the INSTALL file, is './configure'. However that won't fly:

-bash: ./configure: No such file or directory

The only executable file I can see in the folder is autogen.sh, which gives me this:

glibtoolize: putting auxiliary files in '.'.
glibtoolize: copying file './ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
glibtoolize: copying file 'm4/libtool.m4'
glibtoolize: copying file 'm4/ltoptions.m4'
glibtoolize: copying file 'm4/ltsugar.m4'
glibtoolize: copying file 'm4/ltversion.m4'
glibtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:38: installing './compile'
configure.ac:39: installing './config.guess'
configure.ac:39: installing './config.sub'
configure.ac:29: installing './install-sh'
configure.ac:29: installing './missing'
examples/Makefile.am:1: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
examples/Makefile.am: installing './depcomp'
libusb/Makefile.am:4: warning: source file 'os/darwin_usb.c' is in a subdirectory,
libusb/Makefile.am:4: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled.  For now, the corresponding output
automake: object file(s) will be placed in the top-level directory.  However,
automake: this behaviour will change in future Automake versions: they will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.
libusb/Makefile.am:3: warning: source file 'os/linux_usbfs.c' is in a subdirectory,
libusb/Makefile.am:3: but option 'subdir-objects' is disabled
libusb/Makefile.am:5: warning: source file 'os/openbsd_usb.c' is in a subdirectory,
libusb/Makefile.am:5: but option 'subdir-objects' is disabled
libusb/Makefile.am:6: warning: source file 'os/poll_windows.c' is in a subdirectory,
libusb/Makefile.am:6: but option 'subdir-objects' is disabled
libusb/Makefile.am:6: warning: source file 'os/windows_usb.c' is in a subdirectory,
libusb/Makefile.am:6: but option 'subdir-objects' is disabled
libusb/Makefile.am:37: warning: source file 'os/threads_windows.c' is in a subdirectory,
libusb/Makefile.am:37: but option 'subdir-objects' is disabled
libusb/Makefile.am:37: warning: source file 'os/threads_posix.c' is in a subdirectory,
libusb/Makefile.am:37: but option 'subdir-objects' is disabled
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... yes
checking whether make supports nested variables... (cached) yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... x86_64-apple-darwin16.1.0
checking host system type... x86_64-apple-darwin16.1.0
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert x86_64-apple-darwin16.1.0 file names to x86_64-apple-darwin16.1.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin16.1.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin16.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for windres... no
checking for inline... inline
checking operating system... Darwin/Mac OS X
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking for nfds_t... yes
checking sys/timerfd.h usability... no
checking sys/timerfd.h presence... no
checking for sys/timerfd.h... no
checking whether TFD_NONBLOCK is declared... no
checking whether to use timerfd for timing... no (header not available)
checking for struct timespec... yes
checking for sigaction... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for gettimeofday... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating libusb-1.0.pc
config.status: creating Makefile
config.status: creating libusb/Makefile
config.status: creating examples/Makefile
config.status: creating doc/Makefile
config.status: creating doc/doxygen.cfg
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

After that I can run "make"

/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in libusb
  CC       libusb_1_0_la-core.lo
  CC       libusb_1_0_la-descriptor.lo
  CC       libusb_1_0_la-io.lo
  CC       libusb_1_0_la-sync.lo
  CC       libusb_1_0_la-darwin_usb.lo
os/darwin_usb.c:291:51: warning: address of array 'handle->os_priv' will always evaluate to 'true'
      [-Wpointer-bool-conversion]
      if (dpriv->location == location  && handle->os_priv) {
                                       ~~ ~~~~~~~~^~~~~~~
os/darwin_usb.c:326:3: warning: 'objc_registerThreadWithCollector' is deprecated: it does nothing. Define
      OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily silence this diagnostic. [-Wdeprecated-declarations]
  objc_registerThreadWithCollector();
  ^
/usr/include/objc/objc-auto.h:245:25: note: 'objc_registerThreadWithCollector' has been explicitly marked deprecated here
static OBJC_INLINE void objc_registerThreadWithCollector() { }
                        ^
os/darwin_usb.c:386:7: warning: 'OSAtomicIncrement32Barrier' is deprecated: first deprecated in macOS 10.12 - Use
      atomic_fetch_add() from <stdatomic.h> instead [-Wdeprecated-declarations]
  if (OSAtomicIncrement32Barrier(&initCount) == 1) {
      ^
/usr/include/libkern/OSAtomicDeprecated.h:182:9: note: 'OSAtomicIncrement32Barrier' has been explicitly marked deprecated
      here
int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue );
        ^
os/darwin_usb.c:409:7: warning: 'OSAtomicDecrement32Barrier' is deprecated: first deprecated in macOS 10.12 - Use
      atomic_fetch_sub() from <stdatomic.h> instead [-Wdeprecated-declarations]
  if (OSAtomicDecrement32Barrier(&initCount) == 0) {
      ^
/usr/include/libkern/OSAtomicDeprecated.h:201:9: note: 'OSAtomicDecrement32Barrier' has been explicitly marked deprecated
      here
int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue );
        ^
os/darwin_usb.c:1151:27: warning: expression which evaluates to zero treated as a null pointer constant of type
      'IOUSBInterfaceInterface300 **' (aka 'struct IOUSBInterfaceStruct300 **') [-Wnon-literal-null-conversion]
  cInterface->interface = IO_OBJECT_NULL;
                          ^~~~~~~~~~~~~~
/System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h:164:24: note: expanded from macro 'IO_OBJECT_NULL'
#define IO_OBJECT_NULL  ((io_object_t) 0)
                        ^~~~~~~~~~~~~~~~~
5 warnings generated.
  CC       libusb_1_0_la-threads_posix.lo
  CCLD     libusb-1.0.la
Making all in doc
make[2]: Nothing to be done for `all'.
Making all in examples
  CC       listdevs.o
  CCLD     listdevs
  CC       dpfp.o
  CCLD     dpfp
  CC       dpfp_threaded-dpfp_threaded.o
  CCLD     dpfp_threaded
make[2]: Nothing to be done for `all-am'.

and "make install":

Making install in libusb
 .././install-sh -c -d '/usr/local/lib'
 /bin/sh ../libtool   --mode=install /usr/bin/install -c   libusb-1.0.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libusb-1.0.0.dylib /usr/local/lib/libusb-1.0.0.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libusb-1.0.0.dylib libusb-1.0.dylib || { rm -f libusb-1.0.dylib && ln -s libusb-1.0.0.dylib libusb-1.0.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libusb-1.0.lai /usr/local/lib/libusb-1.0.la
libtool: install: /usr/bin/install -c .libs/libusb-1.0.a /usr/local/lib/libusb-1.0.a
libtool: install: chmod 644 /usr/local/lib/libusb-1.0.a
libtool: install: ranlib /usr/local/lib/libusb-1.0.a
 .././install-sh -c -d '/usr/local/include/libusb-1.0'
 /usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0'
Making install in doc
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
Making install in examples
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Nothing to be done for `install-exec-am'.
 ./install-sh -c -d '/usr/local/lib/pkgconfig'
 /usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig'

I've checked /usr/local/lib and there are 4 new libusb related files there:

libusb-1.0.0.dylib
libusb-1.0.a
libusb-1.0.dylib (which is an alias to libusb-1.0.0.dylib)
libusb-1.0.la

Running st-util -1 again gives me the exact same outcome:

$ st-util -1
st-util 1.3.1-15-g3d24377
2017-04-20T01:36:58 WARN src/sg.c: Failed to find an stlink v1 by VID:PID
2017-04-20T01:36:58 ERROR src/sg.c: Could not open stlink device

To be sure I've removed the files again and downloaded the 1.0.9 libusb tarbal from sourceforge. This one does have the configure file and executing it gives me this:

$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... x86_64-apple-darwin16.1.0
checking host system type... x86_64-apple-darwin16.1.0
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin16.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for windres... no
checking for inline... inline
checking whether gcc and cc understand -c and -o together... yes
checking operating system... Darwin/Mac OS X
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking for nfds_t... yes
checking sys/timerfd.h usability... no
checking sys/timerfd.h presence... no
checking for sys/timerfd.h... no
checking whether TFD_NONBLOCK is declared... no
checking whether to use timerfd for timing... no (header not available)
checking for struct timespec... yes
checking for sigaction... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for gettimeofday... yes
configure: creating ./config.status
config.status: creating libusb-1.0.pc
config.status: creating Makefile
config.status: creating libusb/Makefile
config.status: creating examples/Makefile
config.status: creating doc/Makefile
config.status: creating doc/doxygen.cfg
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

Then "make":

$ make
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in libusb
  CC     libusb_1_0_la-core.lo
  CC     libusb_1_0_la-descriptor.lo
  CC     libusb_1_0_la-io.lo
  CC     libusb_1_0_la-sync.lo
  CC     libusb_1_0_la-darwin_usb.lo
os/darwin_usb.c:291:51: warning: address of array 'handle->os_priv' will always evaluate to 'true'
      [-Wpointer-bool-conversion]
      if (dpriv->location == location  && handle->os_priv) {
                                       ~~ ~~~~~~~~^~~~~~~
os/darwin_usb.c:326:3: warning: 'objc_registerThreadWithCollector' is deprecated: it does nothing. Define
      OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily silence this diagnostic. [-Wdeprecated-declarations]
  objc_registerThreadWithCollector();
  ^
/usr/include/objc/objc-auto.h:245:25: note: 'objc_registerThreadWithCollector' has been explicitly marked deprecated here
static OBJC_INLINE void objc_registerThreadWithCollector() { }
                        ^
os/darwin_usb.c:386:7: warning: 'OSAtomicIncrement32Barrier' is deprecated: first deprecated in macOS 10.12 - Use
      atomic_fetch_add() from <stdatomic.h> instead [-Wdeprecated-declarations]
  if (OSAtomicIncrement32Barrier(&initCount) == 1) {
      ^
/usr/include/libkern/OSAtomicDeprecated.h:182:9: note: 'OSAtomicIncrement32Barrier' has been explicitly marked deprecated
      here
int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue );
        ^
os/darwin_usb.c:409:7: warning: 'OSAtomicDecrement32Barrier' is deprecated: first deprecated in macOS 10.12 - Use
      atomic_fetch_sub() from <stdatomic.h> instead [-Wdeprecated-declarations]
  if (OSAtomicDecrement32Barrier(&initCount) == 0) {
      ^
/usr/include/libkern/OSAtomicDeprecated.h:201:9: note: 'OSAtomicDecrement32Barrier' has been explicitly marked deprecated
      here
int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue );
        ^
os/darwin_usb.c:1151:27: warning: expression which evaluates to zero treated as a null pointer constant of type
      'IOUSBInterfaceInterface300 **' (aka 'struct IOUSBInterfaceStruct300 **') [-Wnon-literal-null-conversion]
  cInterface->interface = IO_OBJECT_NULL;
                          ^~~~~~~~~~~~~~
/System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h:164:24: note: expanded from macro 'IO_OBJECT_NULL'
#define IO_OBJECT_NULL  ((io_object_t) 0)
                        ^~~~~~~~~~~~~~~~~
5 warnings generated.
  CC     libusb_1_0_la-threads_posix.lo
  CCLD   libusb-1.0.la
Making all in doc
make[2]: Nothing to be done for `all'.
make[2]: Nothing to be done for `all-am'.

and "make install"

$ make install
Making install in libusb
test -z "/usr/local/lib" || .././install-sh -c -d "/usr/local/lib"
 /bin/sh ../libtool   --mode=install /usr/bin/install -c   libusb-1.0.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libusb-1.0.0.dylib /usr/local/lib/libusb-1.0.0.dylib
libtool: install: (cd /usr/local/lib && { ln -s -f libusb-1.0.0.dylib libusb-1.0.dylib || { rm -f libusb-1.0.dylib && ln -s libusb-1.0.0.dylib libusb-1.0.dylib; }; })
libtool: install: /usr/bin/install -c .libs/libusb-1.0.lai /usr/local/lib/libusb-1.0.la
libtool: install: /usr/bin/install -c .libs/libusb-1.0.a /usr/local/lib/libusb-1.0.a
libtool: install: chmod 644 /usr/local/lib/libusb-1.0.a
libtool: install: ranlib /usr/local/lib/libusb-1.0.a
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
     during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include/libusb-1.0" || .././install-sh -c -d "/usr/local/include/libusb-1.0"
 /usr/bin/install -c -m 644 libusb.h '/usr/local/include/libusb-1.0'
Making install in doc
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/lib/pkgconfig" || ./install-sh -c -d "/usr/local/lib/pkgconfig"
 /usr/bin/install -c -m 644 libusb-1.0.pc '/usr/local/lib/pkgconfig'

Again, I see 4 new files in /usr/local/lib, which have the exact same name as the ones that showed up using the github source.

st-util -1 gives me the same error yet again:

$ st-util -1
st-util 1.3.1-15-g3d24377
2017-04-20T01:45:49 WARN src/sg.c: Failed to find an stlink v1 by VID:PID
2017-04-20T01:45:49 ERROR src/sg.c: Could not open stlink device

Am I doing something oddly wrong here?

(sorry for the long post, I figured it'd be best to get all console output in here in case I missed something)

Edit:
rebooted (just to be sure) but that didn't change anything either.

Edit 2:
just found the examples folder inside the libusb folder, ran a make in it and ran listdevs (one of the example projects) which lists all of the usb devices it can find. The STLink is in there too:

0483:3744 (bus 20, device 9)

Edit 3:
Just cloned the latest version of libusb from github into a separate folder, went through the same process, and ran the "listdevs" example. This one does not find the STLink V1. It does find my V2 however.

Edit 4:
Yes really, a 4th one. I started looking into the libusb github repo. Found a pull request: libusb/libusb@b623754

In the examples folder there's a file called "xusb.c" that has issues listing usb devices with a vendor code >= 0x80. I did a quick fresh clone, made the alterations to the .c file myself (just a few lines of code), did ./configure, make and make install and ran ./listdevs again. Wonders above wonders, the V1 shows up too now.

Now to get to the meat and potatoes, I have a feeling this is not solely a libusb issue. Apparently the implementation of libusb changed somewhere between 1.0.9 and 1.0.21 and this might be an issue with how st-link tries to access the list of devices, similarly to the "xusb.c" example. Although I must admit that I'm running the same st-link on the Ubuntu VM where it works without issues.

@Nandox7
Copy link

Nandox7 commented Apr 9, 2018

Got the same issue and managed to sort it loading the .kext file.
I'm running 10.13.2 and just copy the 10.10 version & changed the OS version detection code as mentioned in the README.

Problem was is the new protections in 10.13.
Was forced to boot into recovery mode and disable kext signing protection using.
csrutil disable
csrutil enable --without kext

After restart was able to load the .kext and st-util -1 works correctly.

@ryba-xek
Copy link

ryba-xek commented Jul 27, 2018

Ok, I'm still failing with OS X 10.13.6.

I've done csrutil disable/enable --without kext in recovery mode, booted back to normal.

I took 10.10 kext and moved it to /System/Library/Extensions and chown'ed it.
> ll /System/Library/Extensions/ | grep -i stli
drwxr-xr-x 3 root wheel 96B Jul 26 19:58 stlink_shield.kext

When I load it I see everything's okay:
> sudo kextload -v /System/Library/Extensions/stlink_shield.kext
Requesting load of /System/Library/Extensions/stlink_shield.kext.
/System/Library/Extensions/stlink_shield.kext loaded successfully (or already loaded).

but kextstat gives me nothing.

> sudo kextstat | grep -i stl
>

st-util -1 does not work:
> st-util -1
st-util 1.4.0
2018-07-27T17:15:39 WARN sg.c: Failed to find an stlink v1 by VID:PID
2018-07-27T17:15:39 ERROR sg.c: Could not open stlink device

Still, kextunload works well, it reports that the kext was unloaded.
> sudo kextunload -v /System/Library/Extensions/stlink_shield.kext
com.libusb.stlink_shield unloaded and personalities removed.

@xor-gate
Copy link
Member

What does st-util say when you run as root with sudo? It is not a the perfect situation but we can see if it is a permission problem.

@ryba-xek
Copy link

ryba-xek commented Jul 28, 2018

> sudo st-util -1
st-util 1.4.0
2018-07-29T00:00:08 WARN sg.c: Failed to find an stlink v1 by VID:PID
2018-07-29T00:00:08 ERROR sg.c: Could not open stlink device

I'm able to see
`STM32 STLink:

Product ID: 0x3744
Vendor ID: 0x0483 (STMicroelectronics)`
in Sytem Information.

This is what I see from libusb 1.0.9
> ./examples/listdevs
05ac:8007 (bus 20, device 0)
0483:3744 (bus 20, device 8) --- this disappers when I disconnect STM32

The same command shows nothing in libusb-1.0.22 =(

Edit:
Ok, I sort of managed to make it work. The problem is libusb which should be downgraded to 1.0.9.
Then you should recompile stlink from source (I edited brew formula disabling downloading bottle).

brew edit libusb
replace beginning with this:
desc "Library for USB device access"
homepage "https://libusb.info/"
url "https://github.com/libusb/libusb/releases/download/v1.0.9/libusb-1.0.9.tar.bz2"
mirror "https://downloads.sourceforge.net/project/libusb/libusb-1.0/libusb-1.0.9/libusb-1.0.9.tar.bz2"
sha256 "e920eedc2d06b09606611c99ec7304413c6784cba6e33928e78243d323195f9b"

then brew edit stlink
comment the bottle section.
Then uninstall libusb & stlink and install them again.

@jasonhouang
Copy link

jasonhouang commented Sep 6, 2018

I'm seems OK with OS X 10.13.6.

I've done csrutil disable in recovery mode, booted back to normal.

I took 10.10 kext and moved it to /System/Library/Extensions.

When I load it I see everything's okay:
$ sudo kextload -v /System/Library/Extensions/stlink_shield10_10.kext

Requesting load of /System/Library/Extensions/stlink_shield10_10.kext.
/System/Library/Extensions/stlink_shield10_10.kext loaded successfully (or already loaded).

And then
$ sudo touch /System/Library/Extensions

And then got this below (you must rebuild st-link yourself, my build version is 1.4.0-47-gae717b9):
$ ./build/Release/src/gdbserver/st-util -1

2018-09-06T15:22:32 WARN sg.c: Your stlink got into a real weird configuration, trying to fix it!
2018-09-06T15:22:32 INFO common.c: Loading device parameters....
2018-09-06T15:22:32 INFO common.c: Device connected is: F1 High-density device, id 0x10036414
2018-09-06T15:22:32 INFO common.c: SRAM size: 0x10000 bytes (64 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 2048 bytes
2018-09-06T15:22:32 INFO sg.c: Successfully opened a stlink v1 debugger
2018-09-06T15:22:32 INFO gdb-server.c: Chip ID is 00000414, Core ID is  1ba01477.
2018-09-06T15:22:32 INFO gdb-server.c: Listening at *:4242...

some extra tests:
$ ./build/Release/st-flash write XXX.bin 0x8000000

st-flash 1.4.0-47-gae717b9
2018-09-06T15:45:39 INFO common.c: Loading device parameters....
2018-09-06T15:45:39 INFO common.c: Device connected is: F1 High-density device, id 0x10036414
2018-09-06T15:45:39 INFO common.c: SRAM size: 0x10000 bytes (64 KiB), Flash: 0x80000 bytes (512 KiB) in pages of 2048 bytes
2018-09-06T15:45:39 INFO common.c: Attempting to write 62032 (0xf250) bytes to stm32 address: 134217728 (0x8000000)
Flash page at addr: 0x0800f000 erased
2018-09-06T15:45:40 INFO common.c: Finished erasing 31 pages of 2048 (0x800) bytes
2018-09-06T15:45:40 INFO common.c: Starting Flash write for VL/F0/F3/F1_XL core id
2018-09-06T15:45:40 INFO flash_loader.c: Successfully loaded flash loader in sram
 31/31 pages written
2018-09-06T15:45:43 INFO common.c: Starting verification of write complete
2018-09-06T15:45:44 INFO common.c: Flash written and verified! jolly good!

and my st-link is v1:

        STM32 Mass Storage:

          Product ID: 0x3744
          Vendor ID: 0x0483  (STMicroelectronics)
          Version: 1.00
          Serial Number: 000000000001
          Speed: Up to 12 Mb/sec
          Manufacturer: STMicroelectronics
          Location ID: 0x14200000 / 7
          Current Available (mA): 500
          Current Required (mA): 100
          Extra Operating Current (mA): 0

$ lsusb

Bus 020 Device 005: ID 05ac:8290 Apple Inc. Bluetooth USB Host Controller
Bus 020 Device 007: ID 0483:3744 STMicroelectronics STM32 Mass Storage  Serial: 000000000001
Bus 000 Device 001: ID 1d6b:IWPT Linux Foundation USB 3.0 Bus

@Nightwalker-87 Nightwalker-87 added this to To do in Release v1.6.1 via automation Mar 1, 2020
@Nightwalker-87 Nightwalker-87 removed this from To do in Release v1.6.1 Apr 5, 2020
@Nightwalker-87 Nightwalker-87 modified the milestones: v1.6.1, Feedback required Apr 5, 2020
@Nightwalker-87 Nightwalker-87 changed the title stink v1 driver issues on macOS Sierra [mac] stink v1 driver issues on macOS Sierra Apr 5, 2020
@Nightwalker-87
Copy link
Member

Nightwalker-87 commented Apr 6, 2020

As @jasonhouang mentioned before, the root of this problem is a system security setting introduced by Apple with OS X El Capitan (OS X 10.11) in 2015.

The so called System Integrity Protection (SIP) is active per default and prevents the operating system amongst other things to load unsigned Kernel Extension Modules (kext). Thus the ST-Link-v1 driver supplied with the tools, which installs as a kext, remains not functional, while SIP is fully activated (as is per default).

Action needs to be taken here by booting into the recovery mode where a terminal console window needs to be opened.

In contrast to the previous approach I would NOT RECOMMEND to disable SIP completely as with the command csrutil disable, because this leaves the system more vulnerable to common threats. Instead there is a more adequate and reasonable option implemented by Apple. Running csrutil enable --without kext, allows to load unsigned kernel extensions while leaving SIP active with all other security features.
So who ever intends to run the ST-Link-v1 programmer on macOS please take this into account.

Further details can be found here: https://forums.developer.apple.com/thread/17452

@Nightwalker-87
Copy link
Member

I am going to add the instructions above to our project documentation in order to make them publicly accessible and will subsequently close this issue as resolved.

@Nightwalker-87 Nightwalker-87 modified the milestones: Old issues, v1.6.1 Apr 6, 2020
@Nightwalker-87 Nightwalker-87 added this to To do in Release v1.6.1 via automation Apr 6, 2020
@Nightwalker-87 Nightwalker-87 self-assigned this Apr 6, 2020
@Nightwalker-87 Nightwalker-87 changed the title [mac] stink v1 driver issues on macOS Sierra [mac] ST-Link-v1 driver issues on macOS 10.11 and later Apr 6, 2020
@Nightwalker-87 Nightwalker-87 moved this from To do to In progress in Release v1.6.1 Apr 6, 2020
@Nightwalker-87 Nightwalker-87 changed the title [mac] ST-Link-v1 driver issues on macOS 10.11 and later [macOS] ST-Link-v1 driver issues Apr 6, 2020
Nightwalker-87 added a commit that referenced this issue Apr 7, 2020
Added documentation on how to solve a failed detection of the ST-Link-v1 
programmer in macOS v10.11 and later.
(Closes #574, #587)
@Nightwalker-87 Nightwalker-87 changed the title [macOS] ST-Link-v1 driver issues [macOS] ST-Link-v1 driver issues / libusb problems Apr 7, 2020
@Nightwalker-87
Copy link
Member

Here we actually had two separate problems in one issue:

  1. 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.
  2. ST-Link-v1 driver issue relates to Kernel Extensions (kext):
    Closed by commit 59c5cfd.

Release v1.6.1 automation moved this from In progress to Done Apr 7, 2020
grevaillot pushed a commit to grevaillot/stlink that referenced this issue Apr 10, 2020
Added documentation on how to solve a failed detection of the ST-Link-v1 
programmer in macOS v10.11 and later.
(Closes stlink-org#574, stlink-org#587)
@stlink-org stlink-org locked as resolved and limited conversation to collaborators Apr 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Status: Done
Development

No branches or pull requests

9 participants