Unable to complete installation of OpenOCD on mac

Hi guys, I’m attempting to install OpenOCD for debugging using an ST-Link on mac. I’ve been following these instructions:

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/jtag-debugging/building-openocd-macos.html

I get all the way to ./configure , which appears to work, but I notice that only the SEGGER J-Link Programmer has been setup. Does anyone know what command to enter to setup the ST-Link?

I then continued to make, but I get the following error:

discovery_tcp.c:305:9: error: implicit declaration of function ‘select’ is
invalid in C99 [-Werror,-Wimplicit-function-declaration]
ret = select(sock + 1, &rfds, NULL, NULL, &timeout);
^
1 error generated.
make[4]: *** [libjaylink_la-discovery_tcp.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Does anyone know what may have gone wrong? Thanks in advance!

Sorry to hear you’re having a hard time. It’s hard to tell from the single error what might have gone wrong with your build.

The recommendation to build openocd from source was due to the fact that homebrew’s formula is too outdated to work with the daisy.

What you may be able to try instead (I can give this a try in the next day or so when I get to a mac) is installing via xpack as this is how eclipse recommends installing it now. It does require node/npm, but looks like a fairly simple install once that’s set up.

If this does work as an alternative source we can add it to the wiki instead of recommending openocd be built from source.

Hope that helps!

1 Like

Thanks - yes I’ve managed to install opened using the xpack link, and with the command:

openocd -f interface/stlink-v2.cfg -f target/STM32h7x.cfg

I get the following output:

xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-12:31)

Licensed under GNU GPL v2

For bug reports, read

http://openocd.org/doc/doxygen/bugs.html

WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg

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 : Listening on port 6666 for tcl connections

Info : Listening on port 4444 for telnet connections

Info : clock speed 1800 kHz

Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748

Info : Target voltage: 3.184707

Info : stm32h7x.cpu0: hardware has 8 breakpoints, 4 watchpoints

Info : starting gdb server for stm32h7x.cpu0 on 3333

Info : Listening on port 3333 for gdb connections

So I think this means it’s working? :raised_hands:

So next question - how do I use it?! What do you recommend? I’m looking into the Cortex Debug extension for VSCode, but not really sure how to set it all up.

Thanks again!

Yeah that seems to be working!

I just started messing around with VS Code+Cortex Debug. As a free solution, its not bad, and its quick to set up.

I think there’s another thread talking about it. But this the launch.json I have that works so far.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceRoot}",
            "executable": "{$workspaceRoot}/build/YOURFILENAME.elf",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "configFiles": [
                "interface/stlink.cfg",
                "target/stm32h7x.cfg",
            ],
            "openOCDLaunchCommands": ["init", "reset init"],
            "runToMain": true,
            "svdFile": "./.vscode/STM32H750x.svd"
        }
    ]
}

the svd file can be found here.

Alternatively, other free options you can use are Eclipse with some extensions, or STM32CubeIDE. I’m sure there are others as well, but those are the two I can think of off the top of my head.

I’ve also used VisualStudio with the VisualGDB extension, but this is Windows only, and also not free.

You may want to update the firmware of the ST-Link-v2 device to V2J37S7.

On Windows, you may need the ST USB drivers too, if the firmware updater can’t find the STLink.

Ok I tried that launch.json file but not luck so far. I get this error:

**Failed to launch OpenOCD GDB Server: Error: spawn openocd ENOENT**

One question, where should openOCD be installed? In the debug console window I get this:

Launching server: "openocd" "-c" "gdb_port 50000" "-s" "/Users/adamfulford/Documents/DaisyWorkspace" "-f" "interface/stlink.cfg" "-f" "target/stm32h7x.cfg" "-c" "init" "-c" "reset init"

However that path is my workspace not for openOCD, which is located at:

/Users/adamfulford/Library/xPacks/@xpack-dev-tools/openocd/0.10.0-14.3/.content/bin

Not sure if that’s correct? I’m just going to check if my ST Link has the latest firmware, although I’m sure I did this not long ago.

Thanks again!

If your openocd is installed so that it’s within your PATH environment variable (i.e. you can type openocd from a fresh terminal) then it shouldn’t matter.

Otherwise there may be a way to set the openocd installation directory from launch.json

I can reinstall from xpack tomorrow and try this out as well.

I see, no I don’t think it is. I tried in a fresh terminal and openocd command was not found, I need to type in the entire path of the install for it to work.

Gotcha. If you go to your system Environment Variables and edit the PATH variable to have the directory of the openocd.exe then you should be able to get it working.

Perfect, that worked! I’m able to step through the file in the debugger now. I’ll have a play and see if it’s all working as expected, but it appears to be. Thanks for all your help! :pray:

Edit: for anyone also trying this on mac - I used the command: sudo nano /etc/paths from terminal to set a new location for the $PATH variable (pointing at my openOCD install).

No problem! Glad I could help!