@v8dave: Here is my guide to setting up Visual Studio Code and OpenOCD on Ubuntu Linux to do source code debugging with the Xenon/Argon and Particle debugger. It took a while, but it is now working!
To install OpenOCD on Ubuntu Linux:
sudo apt install openocd
Mine ends up in /usr/bin/openocd and /usr/share/openocd
Download the OpenOCD target file nrf52-var.cfg.
I put mine in /usr/share/openocd/scripts/target/
For your operating system, download Visual Studio Code.
Apply for and download the Particle Workbench, Themes, and Code Snippets extensions (currently 1.0.0-alpha.6) for VS Code Here.
In VS Code, press the Extensions button on the left, go up to the … (More Actions) menu and pick Install from VSIX… and one by one, install your previously downloaded Particle extensions, Workbench last, and follow the prompts. Make sure the Cortex-Debug extension is installed.
In VS Code, set up your Project and customize the YourProgram.code-workspace file to look similar to this:
- In VS Code, customize your launch.json file to look similar to this:
"name": "Debug (OpenOCD)",
If you change "request": to "launch" type, it does not work properly, the Debugging session gets lost and corrupts the Particle Device OS. You will then have to re-flash the Particle Device OS !
Connect your Xenon to a usb port on your computer and place it in DFU mode (RGB LED blinking Yellow) for local flashing.
In VS Code, code your program, press Ctrl-shift-b to bring up the Particle Build commands and pick Particle: Flash application for debug (local). Place a couple of breakpoints in your program for testing.
Connect the Particle (mesh) Debugger cable to the Xenon SWD port and plug in the interface to another usb port. Remember not to use pin D7 (User LED) in your own programs because it will mess up SWD debugging!
In VS Code, press the Debug button on the left then the green arrow above it to start debugging. Your Particle Debugger board should be blinking blue frenetically. This is good! Now look at your source file. The debugger never made it to your breakpoints. Select the Debug Console and see that your program is paused. Now press on the floating Debugger panel Continue (F5) button and wait a long time for it to get to the first breakpoint. You are ready to debug when the breakpoint is highlighted in yellow. You made it!
At the bottom of the Debug Console is a prompt > to enter GDB commands like help and you can talk to the debugger interface with monitor commands like monitor help. This is the same as telnet localhost 4444 from a terminal to talk to the interface through OpenOCD.
Other useful consoles are Output with Adapter Output selected. Also press F1 and select Particle: Serial Monitor to see your program’s usb output on the Terminal.
When done debugging, select Stop Debugging from the Debug menu. Before you can debug another session, you will need to press reset on the Xenon board.
Some Gotchas: You only have 2 breakpoints. If you add more, it will only cycle through the first two! So, when the 2nd breakpoint is hit, remove the first, move it down below the last breakpoint and continue to slinky down as you debug! Even though the breakpoints might be close together in loop(), the debugger will cycle through setup() to get to that 2nd breakpoint! Doesn’t make a lot of sense, but that is the current behavior . . .
If you are having difficulties flashing locally with usb and accessing the usb port, you may have smacked up against the UDEV Wall! You should download 50-particle.rules and then
sudo cp 50-particle.rules /etc/udev/rules.d/
and restart your system.
I hope this info has saved you some time! Happy debugging . . .