EXAMPLE Setting up VSCode/OpenOCD (XPack)/ST-Link for debugging on MacOS Big Sur

bretvh

Member
Ok, since it took me a brutally time-consuming scavenger hunt to get this set up, I am going to document it here for others. I had a lot of issues having to find documentation on several different websites, and with paths not being found once I got everything installed, so here are detailed instructions that have worked for me so far. It works great for single-command build and flash (no more enclosure flipping and button smashing!) with:
Bash:
make && make program
So now you can run that command and it will compile your code, and automatically flash the memory on the SEED, thereby eliminating the need to flip your enclosure over and push the two tiny buttons to put it into bootloader mode. Also: debug output and being able to see variables and data as the patch is running.

One last caveat: be forewarned that you may have to do some detective work and/or keep track of the paths in which things are installed so you can update your PATH variable in your ~/.zshrc file. Always remember to either close your terminal after editing this file, or do a
Bash:
source ~/.zshrc
to tell your terminal session to reload those variables.
  1. First, install Visual Studio Code, and then install the C++ and Cortex Debug plugins
  2. You will need a ST-Link programmer. I ordered this one from Mouser (it comes with the ribbon cable and note the cable has to overhang by 4 pins on each side as evidenced in this post), but there are a bunch of other options out there.
  3. Install OpenOCD from XPack (links below). The Homebrew version is too old to work with the STM32H750 chips. This one seems to work. Note that you should have Node and NPM installed. Also note that I had a lot of trouble with my system not finding Node or NPM once installed (even though I've had them installed for years and use them daily in web development). I eventually removed the Homebrew install and used the official LTS release installer from the node website, and had to add its paths to my .zshrc file:
    1. /usr/local/bin/npm
    2. /usr/local/share/npm/bin
  4. Once you have Node and NPM working:
    1. Install XPM:
      1. Bash:
        npm install --global xpm@latest
      2. Check to make sure it installed correctly with:
        Bash:
        which xpm
        1. If it does not find it, you will have to update the PATH environment variable (because again, node uses weird directory structures) to include the following paths in your ~/.zshrc file, as such:
          1. /Users/YOURUSERNAMEHERE/.npm-global/bin
    2. Install OpenOCD:
      1. Bash:
        xpm install --global @xpack-dev-tools/openocd@latest
      2. Test to make sure OpenOCD installed and your system can find it
        Bash:
        openocd --version
      3. If it can't find it, then you need to add this to your .zshrc PATH:
        1. /Users/YOURUSERNAMEHERE/Library/xPacks/@xpack-dev-tools/openocd/0.10.0-15.1/.content/bin
  5. In your project, you will need the following files in the hidden .vscode folder that is created for your project:
    STM32H750x.svd (link)
    launch.json (contents below):
    JSON:
    { // 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": "build/PitchDiver.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"
    }
    ]
    }

Note that the files referenced in "configFiles" are contained in the OpenOCD install directory and if you have the correct version of OpenOCD (the XPack version), they will be found at runtime.

How your project should look (note that the this folder is in a parent folder located inside the DaisyExamples folder on my desktop):

Screen Shot 2020-12-04 at 2.08.47 PM.png

7. Now you will connect your ST-Link to your laptop, the ribbon cables to your Daisy, then execute from the terminal in your project folder:
Bash:
make program

If all goes well, you will see output in your terminal connecting to the ST-Link, which will in turn attempt to connect to the Daisy Seed and flash it with your build. You can open the debugging panel on the left, start the debugger, then see your variables and set the ones you want to watch to be watched in the watch panel by right-clicking on them in the variables panel.

Hope this helps... if anyone has changes or suggestions, let me know.
 
Last edited:
Thanks for the writeup! I did something similar following some instructions on the Daisy forum for Mojave. I can do the debug stuff within VS Code....but still prefer to just use the terminal. Maybe that is because I don't really understand running the debug thing. While it is actually running I am not able to see the variables, but once I pause the debugger I can see the current values of the variable - but if I change things on the pedal the variables don't update in real time.

I know you linked to a USB version of the STlink, but I have been using these STlink-V3mini ones with good success. They come with a little ribbon cable, but not a micro-USB cable.

The other thing I will mention is that even if people cannot get the VS Code stuff setup, just getting the openOCD working with the STlink is enough to do the 'make program' and flash the Daisy over the JTAG ribbon cable without having to press the reset & boot buttons.
 

bretvh

Member
Yeah, I think I am mostly wanting to be able to run make program and not have to do the enclosure flip/button push dance every couple minutes. But even if I can see the variables in any form, that would be helpful. So on the STLink, I ordered the wrong ribbon cable and have not been able to verify it all works yet, but in the process, Stephen over at ElectroSmith suggested the STlink-V3mini to me and I just ordered one of them since they seem to be reliable. It should be here tomorrow. Thanks for the info!
 

bretvh

Member
Just wanted to chime in here that I just got my STLinkV3 Mini and verified this all works. I have to say, being able to flash without the enclosure flip/button smash routine is huge. Also, I can see the debugging working (although the noise when pausing the debugger is annoying as hell), which is going to be super helpful.
 

bretvh

Member
FYI, edited to point to the STLinkV3 item and a Daisy forum post showing how to connect the ribbon cable.
 

untamedfrontier

Active member
I'm currently on Catalina, but just set up mine to flash (haven't tried any debugging yet). Big thanks for the write up, it definitely helped a lot.

Looks like you can install from homebrew now you just need to do this:
Code:
brew install openocd --HEAD
and then add to your path:
Code:
/usr/local/Cellar/open-ocd/HEAD-f68ade5/bin
My version of openocd is:
Code:
Open On-Chip Debugger 0.11.0-rc2+dev-gf68ade5-dirty (2021-02-04-15:42)

Here's a sample output for a successful flash
Code:
openocd -s /usr/local/share/openocd/scripts -f interface/stlink.cfg -f target/stm32h7x.cfg \
    -c "program ./build/tremolo.elf verify reset exit"
Open On-Chip Debugger 0.11.0-rc2+dev-gf68ade5-dirty (2021-02-04-15:42)
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 V3J3M2 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.176143
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
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000654 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 128
Info : STM32H7 flash has a single bank
Info : Bank (0) size is 128 kb, base address is 0x08000000
Info : Padding image section 1 at 0x0800be74 with 12 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x0800be80 .. 0x0801ffff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
 

bretvh

Member
I'm currently on Catalina, but just set up mine to flash (haven't tried any debugging yet). Big thanks for the write up, it definitely helped a lot.

Looks like you can install from homebrew now you just need to do this:
Code:
brew install openocd --HEAD
and then add to your path:
Code:
/usr/local/Cellar/open-ocd/HEAD-f68ade5/bin
My version of openocd is:
Code:
Open On-Chip Debugger 0.11.0-rc2+dev-gf68ade5-dirty (2021-02-04-15:42)

Here's a sample output for a successful flash
Code:
openocd -s /usr/local/share/openocd/scripts -f interface/stlink.cfg -f target/stm32h7x.cfg \
    -c "program ./build/tremolo.elf verify reset exit"
Open On-Chip Debugger 0.11.0-rc2+dev-gf68ade5-dirty (2021-02-04-15:42)
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 V3J3M2 (API v3) VID:PID 0483:374E
Info : Target voltage: 3.176143
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
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000654 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 128
Info : STM32H7 flash has a single bank
Info : Bank (0) size is 128 kb, base address is 0x08000000
Info : Padding image section 1 at 0x0800be74 with 12 bytes (bank write end alignment)
Warn : Adding extra erase range, 0x0800be80 .. 0x0801ffff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
This is good to know, I tried that route first, but had no luck. Thanks for the update!
 
Top