Skip to content

Commit 92de98a

Browse files
mjcrossmartin
andauthored
update pico-examples/ide/vscode (#313)
Co-authored-by: martin <[email protected]>
1 parent b59a522 commit 92de98a

File tree

4 files changed

+81
-4
lines changed

4 files changed

+81
-4
lines changed

ide/vscode/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Sample configuration files for developing with VSCode and the SWD port
2+
3+
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.
4+
5+
Many configurations are possible. VSCode might be running on:
6+
7+
* a Raspberry Pi wired directly to a target's SWD pins
8+
* a PC or Mac connected to a target via a Pico running [picoprobe](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#debugging-using-another-raspberry-pi-pico)
9+
* a machine with an already running instance of `OpenOCD`
10+
11+
[Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) describes a basic setup for VSCode and how to build picoprobe and `OpenOCD`, a tool that connects to the GNU Debugger [GDB](https://www.sourceware.org/gdb/).
12+
13+
**Configuring VSCode to use the SWD port lets it upload code transparently and gives you step-through debugging from within the IDE.**
14+
15+
---
16+
17+
## Assumptions
18+
19+
The example assumes:
20+
21+
1. A functioning development environment with [pico-sdk](https://github.com/raspberrypi/pico-sdk), ARM Toolchain, VSCode and `OpenOCD` all built and installed according to the instructions in the [Getting Started Guide](https://rptl.io/pico-get-started).
22+
2. A target connected via the SWD port (see above).
23+
3. Reasonable familiarity with [pico-sdk](https://github.com/raspberrypi/pico-sdk), [CMake](https://cmake.org/cmake/help/latest/guide/tutorial/index.html) and [VSCode workspaces](https://code.visualstudio.com/docs/editor/workspaces).
24+
25+
> Note: The provided files illustrate working configurations but you will almost certainly want to customise them further to meet your needs.
26+
27+
28+
---
29+
30+
## Using the Example
31+
32+
1. Open a fresh VScode workspace, add a simple standalone SDK project (removing any existing `build` directory) and create a `.vscode` folder at its top level.
33+
34+
2. Choose the `launch-*-swd.json` file closest to your setup (see below), rename it to `launch.json` and copy it to the `.vscode` folder you created.
35+
36+
Start with:
37+
* `launch-probe-swd.json` if the target is connected via an SWD probe (e.g. picoprobe)
38+
* `launch-raspberrypi-swd.json` if the target is directly connected to a Raspberry Pi GPIO
39+
* `launch-remote-openocd.json` if VSCode should connect to an already running instance of `OpenOCD`.
40+
41+
> Be sure to review the selected file and make any changes needed for your environment.
42+
43+
3. Copy the `settings.json` file into the `.vscode` folder. 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.
44+
45+
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()`.
46+
47+
> 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.
48+
49+
> If `OpenOCD` reports that GDB won't launch or quits unexpectedly, you may need to adjust the *gdbPath* and/or *configFiles* settings in `launch.json`. See the comments in the example files and check the latest [Getting Started](https://rptl.io/pico-get-started).

ide/vscode/launch-probe-swd.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Pico Debug",
6+
"cwd": "${workspaceRoot}",
7+
"executable": "${command:cmake.launchTargetPath}",
8+
"request": "launch",
9+
"type": "cortex-debug",
10+
"servertype": "openocd",
11+
// This may need to be "arm-none-eabi-gdb" for some previous builds
12+
"gdbPath" : "gdb-multiarch",
13+
"device": "RP2040",
14+
"configFiles": [
15+
// This may need to be "interface/picoprobe.cfg" for some previous builds
16+
"interface/cmsis-dap.cfg",
17+
"target/rp2040.cfg"
18+
],
19+
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
20+
"runToEntryPoint": "main",
21+
// Work around for stopping at main on restart
22+
"postRestartCommands": [
23+
"break main",
24+
"continue"
25+
]
26+
}
27+
]
28+
}

ide/vscode/launch-raspberrypi-swd.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"request": "launch",
99
"type": "cortex-debug",
1010
"servertype": "openocd",
11-
// This may need to be arm-none-eabi-gdb depending on your system
11+
// This may need to be "arm-none-eabi-gdb" for some previous builds
1212
"gdbPath" : "gdb-multiarch",
1313
"device": "RP2040",
1414
"configFiles": [
1515
"interface/raspberrypi-swd.cfg",
1616
"target/rp2040.cfg"
1717
],
1818
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
19-
"runToMain": true,
19+
"runToEntryPoint": "main",
2020
// Work around for stopping at main on restart
2121
"postRestartCommands": [
2222
"break main",

ide/vscode/launch-remote-openocd.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"executable": "${command:cmake.launchTargetPath}",
99
"request": "launch",
1010
"servertype": "external",
11-
// This may need to be arm-none-eabi-gdb depending on your system
11+
// This may need to be "arm-none-eabi-gdb" for older builds
1212
"gdbPath" : "gdb-multiarch",
1313
// Connect to an already running OpenOCD instance
1414
"gdbTarget": "your-openocd:3333",
1515
"svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
16-
"runToMain": true,
16+
"runToEntryPoint": "main",
1717
// Work around for stopping at main on restart
1818
"postRestartCommands": [
1919
"break main",

0 commit comments

Comments
 (0)