Sample configuration files for developing with VSCode and the SWD port
This example provides files that illustrate how to use Microsoft(R) Visual Studio Code (VSCode) with a target connected via its Serial Wire Debug (SWD) port.
Many configurations are possible. VSCode might be running on:
- a Raspberry Pi wired directly to a target's SWD pins
- a PC or Mac connected to a target via a Pico running picoprobe
- a machine with an already running instance of
OpenOCD
Getting Started with the Raspberry Pi Pico describes a basic setup for VSCode and how to build picoprobe and OpenOCD, a tool that connects to the GNU Debugger GDB.
Configuring VSCode to use the SWD port lets it upload code transparently and gives you step-through debugging from within the IDE.
Assumptions
The example assumes:
- A functioning development environment with pico-sdk, ARM Toolchain, VSCode and
OpenOCDall built and installed according to the instructions in the Getting Started Guide. - A target connected via the SWD port (see above).
- Reasonable familiarity with pico-sdk, CMake and VSCode workspaces.
Note: The provided files illustrate working configurations but you will almost certainly want to customise them further to meet your needs.
Using the Example
-
Open a fresh VScode workspace, add a simple standalone SDK project (removing any existing
builddirectory) and create a.vscodefolder at its top level. -
Choose the
launch-*-swd.jsonfile closest to your setup (see below), rename it tolaunch.jsonand copy it to the.vscodefolder you created.Start with:
launch-probe-swd.jsonif the target is connected via an SWD probe (e.g. picoprobe)launch-raspberrypi-swd.jsonif the target is directly connected to a Raspberry Pi GPIOlaunch-remote-openocd.jsonif VSCode should connect to an already running instance ofOpenOCD.
Be sure to review the selected file and make any changes needed for your environment.
- Copy the
settings.jsonfile into the.vscodefolder. This illustrates how to configure the CMake plugin so that you debug using cortex-debug instead of trying to launch the executable on the host.
Lauching a debug session in the workspace (e.g. with f5) should now build the project and if successful upload it to the target, open a debug session and pause at the start of main().
VSCode has some background work to do the first time through. If appears to have stalled then leave it alone for at least a minute.
If
OpenOCDreports that GDB won't launch or quits unexpectedly, you may need to adjust the gdbPath and/or configFiles settings inlaunch.json. See the comments in the example files and check the latest Getting Started.