Skip to content

Commit 47a4d9f

Browse files
authored
Add pico-debug support (earlephilhower#239)
1 parent e4185ce commit 47a4d9f

File tree

9 files changed

+1597
-15
lines changed

9 files changed

+1597
-15
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,25 @@ The first line creates a file with the USB vendor and ID of the Picoprobe and te
102102
103103
Once Picoprobe permissions are set up properly, then select the board "Raspberry Pi Pico (Picoprobe)" in the Tools menu and upload as normal.
104104
105-
# Debugging with Picoprobe, OpenOCD, and GDB
106-
The installed tools include a version of OpenOCD (in the pqt-openocd directory) and GDB (in the pqt-gcc directory). These may be used to run GDB in an interactive window as documented in the Pico Getting Started manuals from the Raspberry Pi Foundation.
105+
# Uploading Sketches with pico-debug
106+
[pico-debug](https://github.com/majbthrd/pico-debug/) differs from Picoprobe in that pico-debug is a virtual debug pod that runs side-by-side on the same RP2040 that you run your code on; so, you only need one RP2040 board instead of two. pico-debug also differs from Picoprobe in that pico-debug is standards-based; it uses the CMSIS-DAP protocol, which means even software not specially written for the Raspberry Pi Pico can support it. pico-debug uses OpenOCD to handle your sketch uploads, and debugging can be accomplished with CMSIS-DAP capable debuggers including GDB.
107+
108+
Under Windows and macOS, any user should be able to access pico-debug automatically, but under Linux `udev` must be told about the device and to allow normal users access.
109+
110+
To set up user-level access to all CMSIS-DAP adapters on Ubuntu (and other OSes which use `udev`):
111+
````
112+
echo 'ATTRS{product}=="*CMSIS-DAP*", MODE="664", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/98-CMSIS-DAP.rules
113+
sudo udevadm control --reload
114+
````
115+
116+
The first line creates a file that recognizes all CMSIS-DAP adapters and tells UDEV to give users full access to it. The second causes `udev` to load this new rule. Note that you will need to unplug and re-plug in your device the first time you create this file, to allow udev to make the device node properly.
117+
118+
Once CMSIS-DAP permissions are set up properly, then select the board "Raspberry Pi Pico (pico-debug)" in the Tools menu.
119+
120+
When first connecting the USB port to your PC, you must copy [pico-debug-gimmecache.uf2](https://github.com/majbthrd/pico-debug/releases/) to the Pi Pico to load pico-debug into RAM; after this, upload as normal.
121+
122+
# Debugging with Picoprobe/pico-debug, OpenOCD, and GDB
123+
The installed tools include a version of OpenOCD (in the pqt-openocd directory) and GDB (in the pqt-gcc directory). These may be used to run GDB in an interactive window as documented in the Pico Getting Started manuals from the Raspberry Pi Foundation. For [pico-debug](https://github.com/majbthrd/pico-debug/), replace the raspberrypi-swd and picoprobe example OpenOCD arguments of "-f interface/raspberrypi-swd.cfg -f target/rp2040.cfg" or "-f interface/picoprobe.cfg -f target/rp2040.cfg" respectively in the Pico Getting Started manual with "-f board/pico-debug.cfg".
107124
108125
# Features
109126
* Adafruit TinyUSB Arduino (USB mouse, keyboard, flash drive, generic HID, CDC Serial, MIDI, WebUSB, others)

boards.txt

Lines changed: 1522 additions & 0 deletions
Large diffs are not rendered by default.

cores/rp2040/RP2040USB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22-
#ifndef USE_TINYUSB
22+
#if !defined(USE_TINYUSB) && !defined(NO_USB)
2323

2424
#include <Arduino.h>
2525
#include "CoreMutex.h"

cores/rp2040/SerialUSB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2121
*/
2222

23-
#ifndef USE_TINYUSB
23+
#if !defined(USE_TINYUSB) && !defined(NO_USB)
2424

2525
#include <Arduino.h>
2626
#include "CoreMutex.h"

cores/rp2040/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ extern "C" int main() {
6161
mutex_init(&_pioMutex);
6262
initVariant();
6363

64+
#ifndef NO_USB
6465
#ifdef USE_TINYUSB
6566
TinyUSB_Device_Init(0);
6667

@@ -72,18 +73,21 @@ extern "C" int main() {
7273
Serial.begin(115200);
7374
#endif
7475
#endif
76+
#endif
7577

7678
#if defined DEBUG_RP2040_PORT
7779
DEBUG_RP2040_PORT.begin();
7880
#endif
7981

82+
#ifndef NO_USB
8083
if (setup1 || loop1) {
8184
rp2040.fifo.begin(2);
8285
multicore_launch_core1(main1);
8386
} else {
8487
rp2040.fifo.begin(1);
8588
}
8689
rp2040.fifo.registerCore();
90+
#endif
8791

8892
setup();
8993
while (true) {

docs/install.rst

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ The first line creates a file with the USB vendor and ID of the Picoprobe and te
135135

136136
Once Picoprobe permissions are set up properly, then select the board "Raspberry Pi Pico (Picoprobe)" in the Tools menu and upload as normal.
137137

138-
Debugging with Picoprobe, OpenOCD, and GDB
139-
------------------------------------------
140-
The installed tools include a version of OpenOCD (in the pqt-openocd directory) and GDB (in the pqt-gcc directory). These may be used to run GDB in an interactive window as documented in the Pico Getting Started manuals from the Raspberry Pi Foundation.
138+
Uploading Sketches with pico-debug
139+
----------------------------------
140+
pico-debug differs from Picoprobe in that pico-debug is a virtual debug pod that runs side-by-side on the same RP2040 that you run your code on; so, you only need one RP2040 board instead of two. pico-debug also differs from Picoprobe in that pico-debug is standards-based; it uses the CMSIS-DAP protocol, which means even software not specially written for the Raspberry Pi Pico can support it. pico-debug uses OpenOCD to handle your sketch uploads, and debugging can be accomplished with CMSIS-DAP capable debuggers including GDB.
141+
142+
Under Windows and macOS, any user should be able to access pico-debug automatically, but under Linux `udev` must be told about the device and to allow normal users access.
143+
144+
To set up user-level access to all CMSIS-DAP adapters on Ubuntu (and other OSes which use `udev`):
145+
146+
.. code::
147+
148+
echo 'ATTRS{product}=="*CMSIS-DAP*", MODE="664", GROUP="plugdev"' | sudo tee -a /etc/udev/rules.d/98-CMSIS-DAP.rules
149+
sudo udevadm control --reload
150+
151+
The first line creates a file that recognizes all CMSIS-DAP adapters and tells UDEV to give users full access to it. The second causes `udev` to load this new rule. Note that you will need to unplug and re-plug in your device the first time you create this file, to allow udev to make the device node properly.
152+
153+
Once CMSIS-DAP permissions are set up properly, then select the board "Raspberry Pi Pico (pico-debug)" in the Tools menu.
154+
155+
When first connecting the USB port to your PC, you must copy pico-debug-gimmecache.uf2 to the Pi Pico to load pico-debug into RAM; after this, upload as normal.
156+
157+
Debugging with Picoprobe/pico-debug, OpenOCD, and GDB
158+
-----------------------------------------------------
159+
The installed tools include a version of OpenOCD (in the pqt-openocd directory) and GDB (in the pqt-gcc directory). These may be used to run GDB in an interactive window as documented in the Pico Getting Started manuals from the Raspberry Pi Foundation. For pico-debug, replace the raspberrypi-swd and picoprobe example OpenOCD arguments of "-f interface/raspberrypi-swd.cfg -f target/rp2040.cfg" or "-f interface/picoprobe.cfg -f target/rp2040.cfg" respectively in the Pico Getting Started manual with "-f board/pico-debug.cfg".

lib/memmap_default.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
MEMORY
2525
{
2626
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = __FLASH_LENGTH__
27-
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
27+
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = __RAM_LENGTH__
2828
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
2929
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
3030
}

platform.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ archive_file_path={build.path}/{archive_file}
107107
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
108108

109109
## Generate the linker map with specific flash sizes/locations
110-
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
110+
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end} --sub __RAM_LENGTH__ {build.ram_length}
111111

112112
## Compile the boot stage 2 blob
113113
recipe.hooks.linking.prelink.2.pattern="{compiler.path}{compiler.S.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -c "{runtime.platform.path}/boot2/{build.boot2}.S" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" -o "{build.path}/boot2.o"
@@ -147,3 +147,9 @@ tools.picoprobe.upload.protocol=picoprobe
147147
tools.picoprobe.upload.params.verbose=
148148
tools.picoprobe.upload.params.quiet=
149149
tools.picoprobe.upload.pattern="{cmd}/bin/openocd" -f "interface/picoprobe.cfg" -f "target/rp2040.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"
150+
151+
tools.picodebug.cmd={runtime.platform.path}/system/openocd
152+
tools.picodebug.upload.protocol=pico-debug
153+
tools.picodebug.upload.params.verbose=
154+
tools.picodebug.upload.params.quiet=
155+
tools.picodebug.upload.pattern="{cmd}/bin/openocd" -f "board/pico-debug.cfg" -s "{cmd}/share/openocd/scripts" -c "program {build.path}/{build.project_name}.elf verify reset exit"

tools/makeboards.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,26 @@ def BuildUSBStack(name):
5050
print("%s.menu.usbstack.tinyusb=Adafruit TinyUSB" % (name))
5151
print('%s.menu.usbstack.tinyusb.build.usbstack_flags=-DUSE_TINYUSB "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"' % (name))
5252

53-
def BuildHeader(name, vendor_name, product_name, pidtouse, vid, pid, boarddefine, variant, uploadtool, flashsize, boot2):
53+
def BuildWithoutUSBStack(name):
54+
print("%s.menu.usbstack.nousb=No USB" % (name))
55+
print('%s.menu.usbstack.nousb.build.usbstack_flags="-DNO_USB -DDISABLE_USB_SERIAL -I{runtime.platform.path}/tools/libpico"' % (name))
56+
57+
def BuildHeader(name, vendor_name, product_name, vidtouse, pidtouse, vid, pid, boarddefine, variant, uploadtool, flashsize, ramsize, boot2):
5458
prettyname = vendor_name + " " + product_name
5559
print()
5660
print("# -----------------------------------")
5761
print("# %s" % (prettyname))
5862
print("# -----------------------------------")
5963
print("%s.name=%s" % (name, prettyname))
60-
print("%s.vid.0=%s" % (name, vid))
64+
print("%s.vid.0=%s" % (name, vidtouse))
6165
print("%s.pid.0=%s" % (name, pidtouse))
6266
print("%s.build.usbpid=-DSERIALUSB_PID=%s" % (name, pid))
6367
print("%s.build.board=%s" % (name, boarddefine))
6468
print("%s.build.mcu=cortex-m0plus" % (name))
6569
print("%s.build.variant=%s" % (name, variant))
6670
print("%s.upload.tool=%s" % (name, uploadtool))
6771
print("%s.upload.maximum_size=%d" % (name, flashsize))
68-
print("%s.upload.maximum_data_size=262144" % (name))
72+
print("%s.upload.maximum_data_size=%d" % (name, ramsize))
6973
print("%s.upload.wait_for_upload_port=true" % (name))
7074
print("%s.upload.erase_cmd=" % (name))
7175
print("%s.serial.disableDTR=false" % (name))
@@ -75,6 +79,7 @@ def BuildHeader(name, vendor_name, product_name, pidtouse, vid, pid, boarddefine
7579
print("%s.build.core=rp2040" % (name))
7680
print("%s.build.mcu=rp2040" % (name))
7781
print("%s.build.ldscript=memmap_default.ld" % (name))
82+
print("%s.build.ram_length=%dk" % (name, ramsize / 1024))
7883
print("%s.build.boot2=%s" % (name, boot2))
7984
print("%s.build.vid=%s" % (name, vid))
8085
print("%s.build.pid=%s" % (name, pid))
@@ -92,17 +97,23 @@ def BuildGlobalMenuList():
9297

9398

9499
def MakeBoard(name, vendor_name, product_name, vid, pid, boarddefine, flashsizemb, boot2):
95-
for a, b, c in [ ["", "", "uf2conv"], ["picoprobe", " (Picoprobe)", "picoprobe"]]:
100+
for a, b, c in [ ["", "", "uf2conv"], ["picoprobe", " (Picoprobe)", "picoprobe"], ["picodebug", " (pico-debug)", "picodebug"]]:
96101
n = name + a
97102
p = product_name + b
98103
fssizelist = [ 0, 64 * 1024, 128 * 1024, 256 * 1024, 512 * 1024 ]
99104
for i in range(1, flashsizemb):
100105
fssizelist.append(i * 1024 * 1024)
106+
vidtouse = vid;
107+
ramsizekb = 256;
101108
if a == "picoprobe":
102109
pidtouse = '0x0004'
110+
elif a == "picodebug":
111+
vidtouse = '0x1209'
112+
pidtouse = '0x2488'
113+
ramsizekb = 240;
103114
else:
104115
pidtouse = pid
105-
BuildHeader(n, vendor_name, p, pidtouse, vid, pid, boarddefine, name, c, flashsizemb * 1024 * 1024, boot2)
116+
BuildHeader(n, vendor_name, p, vidtouse, pidtouse, vid, pid, boarddefine, name, c, flashsizemb * 1024 * 1024, ramsizekb * 1024, boot2)
106117
if name == "generic":
107118
BuildFlashMenu(n, 2*1024*1024, [0, 1*1024*1024])
108119
BuildFlashMenu(n, 4*1024*1024, [0, 2*1024*1024])
@@ -113,7 +124,10 @@ def MakeBoard(name, vendor_name, product_name, vid, pid, boarddefine, flashsizem
113124
BuildFreq(n)
114125
BuildDebugPort(n)
115126
BuildDebugLevel(n)
116-
BuildUSBStack(n)
127+
if a == "picodebug":
128+
BuildWithoutUSBStack(n)
129+
else:
130+
BuildUSBStack(n)
117131
if name == "generic":
118132
BuildBoot(n)
119133

0 commit comments

Comments
 (0)