2021-07-31 15:50:59 +00:00
## pre-built openocd
Pre-built openocd binaries compatible with pico-debug [can be found here ](https://github.com/earlephilhower/pico-quick-toolchain/releases/ ) for several operating systems.
## Build openocd yourself (Linux specific)
2021-02-10 20:03:56 +00:00
2021-06-22 21:30:26 +00:00
Users can choose between the authentic OpenOCD or Raspberry Pi's own dated OpenOCD fork which their documentation continues to point to.
2021-05-03 18:10:34 +00:00
2021-06-22 21:30:26 +00:00
Here are the steps to build the authentic OpenOCD:
2021-02-10 20:03:56 +00:00
```
$ sudo apt install automake autoconf build-essential texinfo libtool libhidapi-dev libusb-1.0-0-dev
2021-05-03 18:10:34 +00:00
$ git clone git://git.code.sf.net/p/openocd/code openocd
2021-02-10 20:03:56 +00:00
$ cd openocd
$ ./bootstrap
$ ./configure --enable-cmsis-dap
$ make -j4
$ sudo make install
```
2021-06-22 21:30:26 +00:00
However, users that are beholden to Raspberry Pi (and its proprietary pico-probe) will find that they must continue using the RPi fork, and should freshly download the source code to something no older than 2021 Jun 18 and re-build it to ensure compatibility with pico-debug.
2021-03-13 15:51:10 +00:00
For Mac users building openocd, please also look at [the suggestions here ](https://github.com/majbthrd/pico-debug/issues/5 ).
2022-05-21 20:22:49 +00:00
For OpenBSD users, please also look at [the suggestions here ](https://github.com/majbthrd/pico-debug/discussions/23 ).
2021-02-10 20:03:56 +00:00
## Install GDB
```
$ sudo apt install gdb-multiarch
```
## Use GDB, OpenOCD, and pico-debug to debug 'blinky'
2021-02-26 21:27:22 +00:00
If you have not already built blinky (or whichever app that you might choose to debug), some [sample instructions are here ](building.md ).
2021-02-10 20:03:56 +00:00
Obtain "pico-debug-gimmecache.uf2" from the Releases at:
https://github.com/majbthrd/pico-debug
Boot the RP2040 with the BOOTSEL button pressed, copy over pico-debug-gimmecache.uf2 to the RP2040, and it immediately reboots as a CMSIS-DAP adapter (ready for OpenOCD to talk to it).
```
2021-06-22 21:30:26 +00:00
$ openocd -f board/pico-debug.cfg
2021-02-10 20:03:56 +00:00
```
Your output should look something like this:
```
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 4000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections
```
2021-02-26 21:27:22 +00:00
This OpenOCD terminal needs to be left open. So go ahead and open another terminal; in this one we’ ll attach a gdb instance to OpenOCD:
2021-02-10 20:03:56 +00:00
```
$ cd ~/pico/pico-examples/build/picoboard/blinky
2021-02-26 21:27:22 +00:00
$ gdb-multiarch picoboard_blinky.elf
2021-02-10 20:03:56 +00:00
```
Connect GDB to OpenOCD:
```
(gdb) target remote localhost:3333
```
2021-02-26 21:27:22 +00:00
and load picoboard_blinky.elf into flash:
2021-02-10 20:03:56 +00:00
```
(gdb) load
Loading section .boot2, size 0x100 lma 0x10000000
Loading section .text, size 0x4828 lma 0x10000100
Loading section .rodata, size 0xd6c lma 0x10004928
Loading section .binary_info, size 0x1c lma 0x10005694
Loading section .data, size 0xa4c lma 0x100056b0
Start address 0x100001e8, load size 24828
Transfer rate: 8 KB/sec, 4138 bytes/write.
```
and then start it running:
```
(gdb) monitor reset init
(gdb) continue
```
Or, if you want to set a breakpoint at main() before running the executable:
```
(gdb) monitor reset init
(gdb) b main
(gdb) continue
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, main () at ../main.c:48
48 sys_init();
```
before continuing after you have hit the breakpoint:
```
(gdb) continue
```
if the target is running, it can be interrupted with Ctrl-C, at which point another gdb prompt should appear:
```
(gdb)
```
To quit from gdb, type:
```
(gdb) quit
```