Upload to STM32 blackpill_f411ce fails over STLink-V2 - Incompatible library version

Environment:
Host OS: macOS 11.6.1 Big Sur
PlatformIO Core: 5.2, Home: 3.3.4

Issue:
Unable to upload code to STM32 (blackpill_f411ce) over STLink-V2.

Uploads to STM32 over STLink-V2 work fine under

  • macOS 10.14.6 Mojave, PlatformIO Core 5.2.4 - Home 3.4.0
  • macOS 10.15.7 Catalina, PlatformIO Core 5.2.4 - Home 3.4.0

I’m not sure if the problem is related to PlatformIO Core/Home version being older on macOS 11.6.1. I’m unable to upgrade PlatformIO to the latest Core/Home version under macOS 11.6.1

I get the following message when attempting to upgrade.

$ pio upgrade
Please wait while upgrading PlatformIO ...
PlatformIO has been successfully upgraded to 5.2.0
Release notes: https://docs.platformio.org/en/latest/history.html

The libusb-1.0.0.dylib at
~/.platformio/packages/tool-openocd/libexec in macOS 11.6.1 matches the corresponding file in macOS 10.15.7/macOS 10.14.6.

I’d appreciate any feedback on possible cause and how I can fix the issue. Thank you.

Error messages:

> Executing task in folder xenon_arduino_w5500_webclient: platformio run --target upload <
Processing stm32 (platform: ststm32; board: blackpill_f411ce; framework: arduino)
----------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f411ce.html
PLATFORM: ST STM32 (15.1.0) > WeAct Studio BlackPill V2.0 (STM32F411CE)
HARDWARE: STM32F411CEU6 100MHz, 128KB RAM, 512KB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-arduinoststm32 4.20100.211028 (2.1.0) 
 - framework-cmsis 2.50700.210515 (5.7.0) 
 - tool-dfuutil 1.9.200310 
 - tool-openocd 2.1100.211028 (11.0) 
 - tool-stm32duino 1.0.1 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 12 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Ethernet> 2.0.0
|   |-- <SPI> 1.0
|-- <SPI> 1.0
Building in release mode
Checking size .pio/build/stm32/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   3.3% (used 4384 bytes from 131072 bytes)
Flash: [=         ]   7.6% (used 39720 bytes from 524288 bytes)
Configuring upload protocol...
AVAILABLE: blackmagic, cmsis-dap, dfu, jlink, serial, stlink
CURRENT: upload_protocol = stlink
Uploading .pio/build/stm32/firmware.elf
dyld: Library not loaded: @loader_path/../libexec/libusb-1.0.0.dylib
  Referenced from: /Users/quark11/.platformio/packages/tool-openocd/bin/openocd
  Reason: Incompatible library version: openocd requires version 4.0.0 or later, but libusb-1.0.0.dylib provides version 3.0.0
*** [upload] Error -6
======================================= [FAILED] Took 2.98 seconds =======================================

Environment    Status    Duration
-------------  --------  ------------
stm32          FAILED    00:00:02.980
================================= 1 failed, 0 succeeded in 00:00:02.980 =================================
The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.

CC @ivankravets is this a fault in the Mac version of tool-openocd that the wrong libusb dynamic library is packaged with it? Or is it a case of “wrong libusb version installed in OS”?

I can’t reproduce it on my machine. I used different macOS versions.
Screen Shot 2021-12-16 at 11.00.01

@zpm1066 have you installed a custom libusb? Could you try brew install libusb?

1 Like

There’s no custom installation of libusb. I did install the latest libusb via new yesterday.

Which libusb does PlatformIO use?
From the error message, it would appear to be from
.platformio/packages/tool-openocd/libexec .

I have also tried removing tool-openocd & stm32 packages, then restarting VScode. This still results in the dyld: Library not loaded error.

It’s odd that the same setup has no issues in STM32 uploads on macOS Catalina & Mojave.

Any other suggestions? Thanks.

@ivankravets What versions of macOS are you running?
For me, STM32 uploads work fine on macOS 10.14.6 and macOS 10.15.7. The STM32 upload issue occurs only on macOS 11.6.1.

All other platform uploads (nRF52, ESP32, RP2040, AVR) work fine on macOS 11.6.1, macOS 10.14.6 and macOS 10.15.7.

I used 11.6 before and didn’t have issues. Now, 12.1, updated a few days ago. Just tried and it works.

@maxgerhardt what is your macOS version?

I have no Mac to test, hence why I tagged you :smiley:

For me, the issue is on macOS 11.6.1. The STM32 uploads work fine only Macs with macOS 10.14.6 & macOS 10.15.7.

I’m going to use locate (from terminal) to find all installs of libusb-1.0.0.dylib on the MBP running macOS 11.6.1, then check their hash & compare with the ones on macOS 10.14.6 & macOS 10.15.7. It’s possible the wrong version of libusb-1.0.0.dylib is being pickup up.

Which libusb-1.0.0.dylib does PlatformIO use when attempting a STM32 upload?

My PATH has /usr/local/bin first, so the brew version of libusb-1.0.0.dylib should get invoked.

There are several locations where libusb-1.0.0.dylib resides or is sym-linked.

/usr/local/lib/libusb-1.0.0.dylib.   (symlinks to /usr/local/Cellar/libusb/1.0.24/lib/libusb-1.0.0.dylib)

/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/Drivers/FirmwareUpgrade/native/mac_x64/libusb-1.0.0.dylib

/Applications/STMicroelectronics/STM32Cube/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/libusb-1.0.0.dylib

/opt/nordic/ncs/v1.7.0/toolchain

I’ll check compare their sha256 hash.

There is a wrapper script inside tool-openocd package. It manipulates with LD_PATH.

Thanks.
Does PlatformIO use the following for STM32 uploads via STLInkv2?

.platformio/packages/tool-openocd/bin/openocd

.platformio/packages/tool-openocd/libexec/libusb-1.0.0.dylib

or, Does PlatformIO use the /usr/local/lib/libusb-1.0.0.dylib?

btw - On different macOS versions, the sha256 hash is different for /usr/local/lib/libusb-1.0.0.dylib.

Mabye executing PIO’s openocd version with these extra environment variables turned on gives you more info where the library comes from? macos - MacOSX: which dynamic libraries linked by binary? - Stack Overflow

Or otool -L <path to opencod> (windows - Discovery of Dynamic library dependency on Mac OS & Linux - Stack Overflow)

Thanks. An interesting utility that I have not come across before.

Here’s what I get.

macOS 11.6.1 (where the issue exists):

macOS 10.15.7 (STM32 uploads work):

Screen Shot 2021-12-16 at 2.52.57 PM

The STM32 upload error was:

Both macOS versions of .platformio/packages/tool-openocd/libexec/libusb-1.0.0.dylib have version 4.0.0 compatibility, so pio openocd should load the libexec/libusb-1.0.0.dylib.

Does this mean that the PlatformIO version of openocd is not being invoked for STM32 / STLInkv2 upload?

A little confused! I’ll investigate further.

Using Xcode, I’ve built executables for the MacDependency tool (A GUI version of otool utility, similar to Windows Dependency Walker, that shows all dependent libraries and frameworks of a given executable, dynamic library or framework on macOS. MacDependency tool was built separately using Xcode 12.4 on macOS 10.15.7 & Xcode 13.1 on macOS 11.6.1.

MacDependency tool is available at GitHub - kwin/macdependency: MacDependency shows all dependent libraries and frameworks of a given executable, dynamic library or framework on Mac OS X.

From the pio openocd results, it appears that on macOS 11.6.1, some of the dependencies are not being satisfied (MacDependency entries in red below are missing). I have no idea what application (STMProgrammerCube?) installs these missing items. I’m not sure on the their importance. It just could be a red herring!

Here are the results from MacDependency.

macOS 11.6.1:

macOS 10.15.7:

I’m not sure what to try next. Perhaps a small fresh install of macOS 11.6.x, PlatformIO, and STM32CubeProgrammer on a separate external drive.

This problem exists only in PlatformIO / macOS 11.6.1 for STM32 / STLinkV2 uploads, as I am able to upload code to blackpill_f411ce in Arduino IDE1.8.16 using STLinkV2.

Weird! Any other suggestions would be welcome!

Max, @ivankravets - I performed a fresh install of macOS 10.16, PlatformIO, and STM32CubeProgrammer (SetupSTM32CubeProgrammer-2.9.0). I got the exact same error message as before when attempting uploads to a STM32 blackpill_f411ce board using STLinkV2.

I have install of macOS 12 Monterey VM running under VMware Fusion Pro on a Mac Mini 2012 & VMware ESXi Server on a Mac Mini 2012.

Mac OS 11 or 12 are not officially supported on a Mac Mini 2012 but the VMs run fine without any changes.

I’ll test out STM32 uploads via STLinkV2 under a macOS 12 Monterey VM.

STM32 uploads via STLinkV2 under a macOS 12 Monterey VM work fine.

Btw - I’ve been testing out a W5500 Ethernet breakout across a suite of nRF52840, Raspberry Pi Pico, ESP32, STM32, and a micro:bit v2 boards.

I’m still puzzled why the STM32 / STLinkV2 upload doesn’t work on macOS 11.6.1. I’ll try a further test on a fresh macOS 11.6.1 VM.

I tried another test, this time installed PlatformIO and VScode but no STM32CubeProgrammer (SetupSTM32CubeProgrammer-2.9.0) in a fresh macOS 11.6 VM.

I can confirm that STM32 uploads to a blackpill_f411ce board using STLinkV2 were successful. It’s possible that the latest STM32CubeProgrammer installer conflicts somehow or it could be some other libusb conflict.

I’ll run some further tests on the macOS 11.6 VM to rule out possible conflict with the STM32CubeProgrammer installer, though I have my doubts. The libusb conflict may be elsewhere.

I’m not quite sure how I’ll fix the issue on my main macOS 11.6 system.

@maxgerhardt, @ivankravets, Do you have any other suggestions? Thanks.

There must be something wrong with the LDPATH or the order thereof. I’m not good enough on Mac to know what the loading order and priorities are though – or if STM32CubeProgrammer somehow intereferes with it. I had another person check it with no STM32CubeProgrammer installed and there were no problems. (https://github.com/CommunityGD32Cores/ArduinoCore-GD32/issues/55#issuecomment-996730655)

Thanks Max.

I’ll try to rule out STM32CubeProgrammer (v2.9) in some further testing over the weekend, though I have it installed on macOS 10.4.6 & macOS 10.15.7 where I don’t have any STM32 upload issues. The STM32CubeProgrammer is needed by Arduino IDE for STLink uploads.

@ivankravets Would you or one of your Dev colleagues know what may be incorrect with the LDPATH?

Can you run these commands and post the output:

file ~/.platformio/packages/tool-openocd/bin/openocd
otool -L ~/.platformio/packages/tool-openocd/bin/openocd
otool -L ~/.platformio/packages/tool-openocd/libexec/libusb-1.0.0.dylib