Browse Source

Document procedure for debugging with another Pico board.

Thomas Buck 1 year ago
parent
commit
22f9c82ac1
4 changed files with 91 additions and 3 deletions
  1. 1
    0
      .gitignore
  2. 65
    3
      firmware/README.md
  3. 21
    0
      firmware/debug_swd.sh
  4. 4
    0
      firmware/flash_swd.sh

+ 1
- 0
.gitignore View File

1
 build
1
 build
2
+build_debug

+ 65
- 3
firmware/README.md View File

19
     mkdir build
19
     mkdir build
20
     cd build
20
     cd build
21
     cmake ..
21
     cmake ..
22
-    make trackball
22
+    make -j4 trackball
23
 
23
 
24
 And flash the resulting `trackball.uf2` file to your Pico as usual.
24
 And flash the resulting `trackball.uf2` file to your Pico as usual.
25
 
25
 
26
 For convenience you can use the included `flash.sh`, as long as you flashed the binary manually once before.
26
 For convenience you can use the included `flash.sh`, as long as you flashed the binary manually once before.
27
 
27
 
28
-    make trackball
28
+    make -j4 trackball
29
     ../flash.sh trackball.uf2
29
     ../flash.sh trackball.uf2
30
 
30
 
31
-For debugging a serial port will be presented by the firmware.
31
+This will use the mass storage bootloader to upload a new uf2 image.
32
+
33
+For old-school debugging a serial port will be presented by the firmware.
32
 Open it using eg. `picocom`, or with the included `debug.sh` script.
34
 Open it using eg. `picocom`, or with the included `debug.sh` script.
35
+
36
+## Proper Debugging
37
+
38
+You can also use the SWD interface for proper hardware debugging.
39
+
40
+This follows the instructions from the [RP2040 Getting Started document](https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf) from chapter 5 and 6.
41
+
42
+For ease of reading the disassembly, create a debug build.
43
+
44
+    mkdir build_debug
45
+    cd build_debug
46
+    cmake -DCMAKE_BUILD_TYPE=Debug ..
47
+    make -j4 trackball
48
+
49
+You need a hardware SWD probe.
50
+This can be made from another Pico, see Appendix A in the document linked above.
51
+For this you need to compile the `picoprobe` firmware, like this.
52
+
53
+    git clone https://github.com/raspberrypi/picoprobe.git
54
+    cd picoprobe
55
+    git submodule update --init
56
+    mkdir build
57
+    cd build
58
+    PICO_SDK_PATH=../../../pico-sdk cmake ..
59
+    make -j4
60
+
61
+And flash the resulting `picoprobe.uf2` to your probe.
62
+Connect `GP2` of the probe to `SWCLK` of the target and `GP3` of the probe to `SWDIO` of the target.
63
+Of course you also need to connect GND between both.
64
+
65
+You need some dependencies, mainly `gdb-multiarch` and the RP2040 fork of `OpenOCD`.
66
+
67
+    sudo apt install gdb-multiarch   # Debian / Ubuntu
68
+    sudo pacman -S arm-none-eabi-gdb # Arch Linux
69
+
70
+    cd ../.. # back to build_debug directory from before
71
+
72
+    git clone https://github.com/raspberrypi/openocd.git --branch rp2040 --recursive --depth=1
73
+    cd openocd
74
+
75
+    # install udev rules
76
+    sudo cp contrib/60-openocd.rules /etc/udev/rules.d
77
+    sudo udevadm control --reload-rules && sudo udevadm trigger
78
+
79
+    ./bootstrap
80
+    ./configure --enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio
81
+    make -j4
82
+
83
+Now we can flash a firmware image via OpenOCD.
84
+
85
+    ./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" -c "program trackball.elf verify reset exit"
86
+
87
+And also start a GDB debugging session.
88
+
89
+    ./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c"
90
+    arm-none-eabi-gdb trackball.elf
91
+    target extended-remote localhost:3333
92
+
93
+These commands have also been put in the `flash_swd.sh` and `debug_swd.sh` scripts, respectively.
94
+Call them from the `build_debug` folder where you checked out and built OpenOCD.

+ 21
- 0
firmware/debug_swd.sh View File

1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+echo Starting OpenOCD in background
5
+./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" &
6
+OPENOCD_PID=$!
7
+
8
+# give OpenOCD some time to output stuff
9
+sleep 1
10
+
11
+echo -n Waiting for debugger to appear
12
+while ! netstat -tna | grep 'LISTEN\>' | grep -q ':3333\>'; do
13
+    echo -n .
14
+    sleep 1
15
+done
16
+
17
+echo Starting GDB
18
+arm-none-eabi-gdb -ex "target extended-remote localhost:3333" $1
19
+
20
+echo Killing OpenOCD instance in background
21
+kill $OPENOCD_PID

+ 4
- 0
firmware/flash_swd.sh View File

1
+#!/bin/bash
2
+set -euo pipefail
3
+
4
+./openocd/src/openocd -s openocd/tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "cmsis_dap_vid_pid 0x2e8a 0x000c" -c "program $1 verify reset exit"

Loading…
Cancel
Save