Openocd OSX (M2) Fail

Hi there,
I’m having problems with getting the STlink v3 Mini Debugger to work on OSX (M2).
What can I do?
this is my output:

Open On-Chip Debugger v0.12.0-esp32-20230419 (2023-04-21-16:09)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1800 kHz
Info : STLINK V3J7M2 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.217021
Info : [stm32h7x.cpu0] Cortex-M7 r1p1 processor detected
Info : [stm32h7x.cpu0] target has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32h7x.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
[stm32h7x.cpu0] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08009d58 msp: 0x20020000
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
** Programming Started **
Info : Device: STM32H74x/75x
Info : flash size probed value 128k
Info : STM32H7 flash has a single bank
Info : Bank (0) size is 128 kb, base address is 0x08000000
Info : Padding image section 2 at 0x080119e4 with 28 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x08011a00 .. 0x0801ffff
Error: error while writing to address 0x52002004
Error: error while writing to address 0x5200200c
Error: error during the lock of flash
Error: failed erasing sectors 0 to 0
Error: jtag status contains invalid mode value - communication failure
Polling target stm32h7x.cpu0 failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
** Programming Failed **
shutdown command invoked

make: *** [program] Error 1

little help would be great!

My only suggestion is that you provide specific details about what you are doing, how you installed openocd, has it ever worked for you, anything else which might be useful.

STLINK V3 works for me on M1 MacBook Air.

1 Like

I’m trying to get the blink example going.
On Linux I had no problems. On OSX it is my first try.
I’m using vscode. I installed openocd with brew.
I have a cable with an adapter (microUSB → USB_A → USB_A to USB_C Adapter)

What else could be relevant?

EDIT: on the output above I had openocd compiled from source, but meanwhile I reverted to the brew version.

I’m trying to determine what is different about my setup.

The firmware on my STLINK is V3J8M3.
My openocd output has the following line:

Info : Padding image section 1 at 0x0800e5d4 with 12 bytes (bank write end alignment)

Did you modify the Makefile?

1 Like

Updated my firmware to V3J12M3 (had to use my old linux for that since there is a java hassle on the m2).
still no luck…
What do you mean by modifying the makefile?

I’m pretty sure there is a usb problem, but how to fix it?

Error: libusb_open() failed with LIBUSB_ERROR_OTHER
Error: open failed

Here my latest output:

Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 1800 kHz
Info : STLINK V3J12M3 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.193625
Info : [stm32h7x.cpu0] Cortex-M7 r1p1 processor detected
Info : [stm32h7x.cpu0] target has 8 breakpoints, 4 watchpoints
Info : starting gdb server for stm32h7x.cpu0 on 3333
Info : Listening on port 3333 for gdb connections
[stm32h7x.cpu0] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080006d4 msp: 0x20020000
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
Info : Unable to match requested speed 4000 kHz, using 3300 kHz
** Programming Started **
Info : Device: STM32H74x/75x
Info : flash size probed value 128k
Info : STM32H7 flash has a single bank
Info : Bank (0) size is 128 kb, base address is 0x08000000
Info : Padding image section 1 at 0x08011598 with 8 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x080115a0 .. 0x0801ffff
Error: jtag status contains invalid mode value - communication failure
Error: error waiting for target flash write algorithm
Error: error while writing to address 0x5200200c
Error: error during the lock of flash
Error: error writing to flash at address 0x08000000 at offset 0x00000000
Info : Previous state query failed, trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32h7x.cpu0 failed, trying to reexamine
Examination failed, GDB will be halted. Polling again in 100ms
** Programming Failed **
shutdown command invoked

Your latest output doesn’t appear to have a USB problem.
is the ribbon cable correctly attached?
Is the Daisy known to be working correctly?
Does the Daisy load and run correctly using USB cable (program-dfu)?

1 Like

is the ribbon cable correctly attached?

yes, no problems on linux.

Is the Daisy known to be working correctly?

yes.

Does the Daisy load and run correctly using USB cable (program-dfu)?

yes.

I’m using a Usb_A → USB_C adaptor. could this be an issue? I have no other issues with this adapter, like programming Arduino etc…

I use a USB C to USB A adapter on my M1 MacBook Air with STLINK, it works correctly. You showed a libusb_open() error, but then you show that openocd is obviously connecting to the STLINK on USB. I don’t know what this might mean.

1 Like

thank you for your time!
I hope someone else who has the solution appears…

Just to be certain - was this openocd built to run natively on Apple Silicon (M1/M2) ? Or is it using Rosetta2?

hm… how can I check this out?

I don’t want to appear unhelpful, but Google is good for this stuff.

Anyway, in a terminal window:

file `which openocd`

Note: those are back-quotes.

It can also be checked using Finder.

1 Like

yes sorry here is my output:

/opt/homebrew/bin/openocd: Mach-O 64-bit executable arm64

does it mean it runs natively?

Yes, that is correct for Apple silicon, which is 64bit ARM CPU.

1 Like

Alright, I suppose I am currently without a solution and stuck.

I asked if somebody had M2 on our Discord and one user said they should be getting one soon. I’ll keep you posted here. They’re planning on using ST Link with it ofc.

1 Like

Thank you! I saw the post on the discord channel :slight_smile:

1 Like

Any news on this topic? :slight_smile:

EDIT:
this is what I’m gettin from:

st-info --probe
2023-05-11T17:04:24 ERROR usb.c: Failed to open USB device 0x0483:0x374e, libusb error: -99)
Found 0 stlink programmers

so it’s a libusb error or something with permissions… OSX guru wanted :wink:

Hey KoSv,

I unfortunately don’t have any news as I don’t have an M2 Mac. Though, there’s a possibility that it could not be related to it?

I saw you ping-ing another user who has an M2 and ST-Link, so I hope they might have some insight.
But yeah, since M2 is still new and not many people seem to have it yet, there is lack of resource on this online unfortunately.

By the way, did you use the brew to install libusb?
Could you go to /opt/homebrew/lib/ folder to see if the libusb-1.0.0.dylib file is installed there? I just wanna confirm that with you. That libusb error: -99 has existed for a while and even on Windows.