Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pico-debug support #239

Merged
merged 3 commits into from
Jul 7, 2021
Merged

add pico-debug support #239

merged 3 commits into from
Jul 7, 2021

Conversation

majbthrd
Copy link
Contributor

@majbthrd majbthrd commented Jul 6, 2021

At a minimum, this depends on 7855b0c pico-quick-toolchain for CMSIS-DAP support.

Although this PR is functional, I suspect that some further tweaking may be desired, as I had to hack up a few files (in particular ./tools/makeboards.py) in a way that might offend the original author(s). For this reason (and the toolchain dependency), I marked this as draft.

I believe that I followed the No USB intent of #233 through the use of a NO_USB define, but by modifying the script rather than the boards.txt result. This macro is used in ./cores/RP2040USB.cpp, ./cores/SerialUSB.cpp, and ./cores/main.cpp

I also added a NO_MULTICORE define, as ./cores/main.cpp presently causes the 2nd CPU core to run new code. Since the 2nd CPU core is already running the debugger when pico-debug is used, this existing behavior doesn’t go down too well.

With this PR, usage of arduino-pico with pico-debug is to initially load the pico-debug .uf2 (nominally pico-debug-gimmecache.uf2) onto the target. (Keep in mind that pico-debug is a RAM-only program, so copying the .uf2 does not alter the flash in any way.)

In the Arduino IDE, select a pico-debug Board/target.

From that point on, you should be able to Sketch > Upload your sketches like one would with picoprobe, but without needing two RP2040 and wiring between the two boards.

@earlephilhower
Copy link
Owner

It only took 3 local rebuilds (one out-of-disk-space error, one typo in the release name, and one final build), but #241 will get the openocd binaries sorted.

Would it be possible to get a short writeup on how to use this in the docs? Even an unformatted .rst file would be a good start (as I know what a pain writing docs is!).

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 6, 2021

@earlephilhower, your efforts in updating the binaries are much appreciated. Added documentation will be forthcoming.

@majbthrd majbthrd marked this pull request as ready for review July 6, 2021 17:46
@earlephilhower earlephilhower self-requested a review July 6, 2021 20:58
@earlephilhower
Copy link
Owner

Thanks for the update and docs!

I will give it a try tonight and if all's well there will be a new release w/this included before tomorrow.

@earlephilhower
Copy link
Owner

The code changes look good! Maybe you'd like to add a URL to the pico-debug repo somewhere?

However, I gave this a try this morning and am not getting anywhere. I've manually uploaded the MAXRAM .UF2 release from your repo, adjusted the udev permissions, selected Pico (pico-debug) as the board, and attempted to upload the blink.ino example. openocd reports tons of errors during the upload, but on an unplug/replug cycle I do see the blnk,ino sketch did get put into flash.

Is there a different linker .map file we need to use? Move the start of the app to some other address, reduce heap (so you can use the gimmecache version), etc?

earle@server:~/Arduino/hardware/pico/rp2040$ /usr/local/bin/arduino-1.8.15/arduino-builder -dump-prefs -logger=machine -hardware /usr/local/bin/arduino-1.8.15/hardware -hardware /home/earle/.arduino15/packages -hardware /home/earle/Arduino/hardware -tools /usr/local/bin/arduino-1.8.15/tools-builder -tools /usr/local/bin/arduino-1.8.15/hardware/tools/avr -tools /home/earle/.arduino15/packages -built-in-libraries /usr/local/bin/arduino-1.8.15/libraries -libraries /home/earle/Arduino/libraries -fqbn=pico:rp2040:rpipicopicodebug:flash=2097152_0,freq=125,dbgport=Disabled,dbglvl=None,usbstack=nousb -ide-version=10815 -build-path /tmp/arduino_build_854965 -warnings=none -build-cache /tmp/arduino_cache_691571 -prefs=build.warn_data_percentage=75 -verbose /usr/local/bin/arduino-1.8.15/examples/01.Basics/Blink/Blink.ino
/usr/local/bin/arduino-1.8.15/arduino-builder -compile -logger=machine -hardware /usr/local/bin/arduino-1.8.15/hardware -hardware /home/earle/.arduino15/packages -hardware /home/earle/Arduino/hardware -tools /usr/local/bin/arduino-1.8.15/tools-builder -tools /usr/local/bin/arduino-1.8.15/hardware/tools/avr -tools /home/earle/.arduino15/packages -built-in-libraries /usr/local/bin/arduino-1.8.15/libraries -libraries /home/earle/Arduino/libraries -fqbn=pico:rp2040:rpipicopicodebug:flash=2097152_0,freq=125,dbgport=Disabled,dbglvl=None,usbstack=nousb -ide-version=10815 -build-path /tmp/arduino_build_854965 -warnings=none -build-cache /tmp/arduino_cache_691571 -prefs=build.warn_data_percentage=75 -verbose /usr/local/bin/arduino-1.8.15/examples/01.Basics/Blink/Blink.ino
Using board 'rpipicopicodebug' from platform in folder: /home/earle/Arduino/hardware/pico/rp2040
Using core 'rp2040' from platform in folder: /home/earle/Arduino/hardware/pico/rp2040
Detecting libraries used...
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-g++ -c -Werror=return-type "-DNO_USB -DDISABLE_USB_SERIAL -I/home/earle/Arduino/hardware/pico/rp2040/tools/libpico" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID=0x2e8a -DUSB_PID=0x000a "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico (pico-debug)\"" -Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/home/earle/Arduino/hardware/pico/rp2040/ @/home/earle/Arduino/hardware/pico/rp2040/lib/platform_inc.txt -fno-rtti -std=gnu++17 -g -w -x c++ -E -CC -DSERIALUSB_PID=0x000a -DF_CPU=125000000L -DARDUINO=10815 -DARDUINO_RASPBERRY_PI_PICO "-DBOARD_NAME=\"RASPBERRY_PI_PICO\"" -DARDUINO_ARCH_RP2040 -I/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040 -I/home/earle/Arduino/hardware/pico/rp2040/variants/rpipico /tmp/arduino_build_854965/sketch/Blink.ino.cpp -o /dev/null
Generating function prototypes...
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-g++ -c -Werror=return-type "-DNO_USB -DDISABLE_USB_SERIAL -I/home/earle/Arduino/hardware/pico/rp2040/tools/libpico" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID=0x2e8a -DUSB_PID=0x000a "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico (pico-debug)\"" -Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/home/earle/Arduino/hardware/pico/rp2040/ @/home/earle/Arduino/hardware/pico/rp2040/lib/platform_inc.txt -fno-rtti -std=gnu++17 -g -w -x c++ -E -CC -DSERIALUSB_PID=0x000a -DF_CPU=125000000L -DARDUINO=10815 -DARDUINO_RASPBERRY_PI_PICO "-DBOARD_NAME=\"RASPBERRY_PI_PICO\"" -DARDUINO_ARCH_RP2040 -I/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040 -I/home/earle/Arduino/hardware/pico/rp2040/variants/rpipico /tmp/arduino_build_854965/sketch/Blink.ino.cpp -o /tmp/arduino_build_854965/preproc/ctags_target_for_gcc_minus_e.cpp
/home/earle/.arduino15/packages/builtin/tools/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_854965/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-g++ -c -Werror=return-type "-DNO_USB -DDISABLE_USB_SERIAL -I/home/earle/Arduino/hardware/pico/rp2040/tools/libpico" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID=0x2e8a -DUSB_PID=0x000a "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico (pico-debug)\"" -Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -iprefix/home/earle/Arduino/hardware/pico/rp2040/ @/home/earle/Arduino/hardware/pico/rp2040/lib/platform_inc.txt -fno-rtti -std=gnu++17 -g -DSERIALUSB_PID=0x000a -DF_CPU=125000000L -DARDUINO=10815 -DARDUINO_RASPBERRY_PI_PICO "-DBOARD_NAME=\"RASPBERRY_PI_PICO\"" -DARDUINO_ARCH_RP2040 -I/home/earle/Arduino/hardware/pico/rp2040/cores/rp2040 -I/home/earle/Arduino/hardware/pico/rp2040/variants/rpipico /tmp/arduino_build_854965/sketch/Blink.ino.cpp -o /tmp/arduino_build_854965/sketch/Blink.ino.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: /tmp/arduino_cache_691571/core/core_e10468fe32b2dc5068f567f06318a1e0.a
Linking everything together...
/home/earle/Arduino/hardware/pico/rp2040/system/python3/python3 /home/earle/Arduino/hardware/pico/rp2040/tools/simplesub.py --input /home/earle/Arduino/hardware/pico/rp2040/lib/memmap_default.ld --out /tmp/arduino_build_854965/memmap_default.ld --sub __FLASH_LENGTH__ 2093056 --sub __EEPROM_START__ 270528512 --sub __FS_START__ 270528512 --sub __FS_END__ 270528512
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-gcc -Werror=return-type "-DNO_USB -DDISABLE_USB_SERIAL -I/home/earle/Arduino/hardware/pico/rp2040/tools/libpico" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID=0x2e8a -DUSB_PID=0x000a "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico (pico-debug)\"" -Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -u _printf_float -u _scanf_float -c /home/earle/Arduino/hardware/pico/rp2040/boot2/boot2_w25q080_2_padded_checksum.S -I/home/earle/Arduino/hardware/pico/rp2040/pico-sdk/src/rp2040/hardware_regs/include/ -I/home/earle/Arduino/hardware/pico/rp2040/pico-sdk/src/common/pico_binary_info/include -o /tmp/arduino_build_854965/boot2.o
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-g++ -L/tmp/arduino_build_854965 -Werror=return-type "-DNO_USB -DDISABLE_USB_SERIAL -I/home/earle/Arduino/hardware/pico/rp2040/tools/libpico" -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID=0x2e8a -DUSB_PID=0x000a "-DUSB_MANUFACTURER=\"Raspberry Pi\"" "-DUSB_PRODUCT=\"Pico (pico-debug)\"" -Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions -u _printf_float -u _scanf_float @/home/earle/Arduino/hardware/pico/rp2040/lib/platform_wrap.txt -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--script=/tmp/arduino_build_854965/memmap_default.ld -Wl,-Map,/tmp/arduino_build_854965/Blink.ino.map -o /tmp/arduino_build_854965/Blink.ino.elf -Wl,--start-group /tmp/arduino_build_854965/sketch/Blink.ino.cpp.o /tmp/arduino_build_854965/../arduino_cache_691571/core/core_e10468fe32b2dc5068f567f06318a1e0.a /tmp/arduino_build_854965/boot2.o /home/earle/Arduino/hardware/pico/rp2040/lib/libpico.a -lm -lc -lstdc++ -lc -Wl,--end-group
/home/earle/Arduino/hardware/pico/rp2040/system/elf2uf2/elf2uf2 /tmp/arduino_build_854965/Blink.ino.elf /tmp/arduino_build_854965/Blink.ino.uf2
/home/earle/Arduino/hardware/pico/rp2040/system/arm-none-eabi/bin/arm-none-eabi-size -A /tmp/arduino_build_854965/Blink.ino.elf
Sketch uses 36508 bytes (1%) of program storage space. Maximum is 2093056 bytes.
Global variables use 3416 bytes (1%) of dynamic memory, leaving 258728 bytes for local variables. Maximum is 262144 bytes.
/home/earle/Arduino/hardware/pico/rp2040/system/openocd/bin/openocd -f board/pico-debug.cfg -s /home/earle/Arduino/hardware/pico/rp2040/system/openocd/share/openocd/scripts -c program /tmp/arduino_build_854965/Blink.ino.elf verify reset exit 
Open On-Chip Debugger 0.10.0+dev-ge3428fadb-dirty (2021-07-06-00:39)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Serial# = E66038B7136D9A39
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
target halted due to debug-request, current mode: Thread 
xPSR: 0xf1000000 pc: 0x000000ee msp: 0x20041f00
** Programming Started **
Info : RP2040 B0 Flash Probe: 2097152 bytes @10000000, in 512 sectors

Info : Writing 40960 bytes starting at 0x0
Error: error writing data: (null)
Error: CMSIS-DAP command CMD_DISCONNECT failed.
Error: error writing data: (null)
Error: CMSIS-DAP command CMD_CONNECT failed.

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 7, 2021

However, I gave this a try this morning and am not getting anywhere. I've manually uploaded the MAXRAM .UF2 release from your repo,

Don't use MAXRAM; use the GIMMECACHE linked to in the README.md.

The MAXRAM variant exists in the cache memory, and the arduino-pico builds operate with the cache enabled. In contrast, the GIMMECACHE leaves the cache alone and resides in the top of the SRAM.

@earlephilhower
Copy link
Owner

Don't use MAXRAM; use the GIMMECACHE linked to in the README.md.
The MAXRAM variant exists in the cache memory, and the arduino-pico builds operate with the cache enabled. In contrast, the GIMMECACHE leaves the cache alone and resides in the top of the SRAM.

I think the linker .LD needs to be changed, then, or else the heap could end up overwriting the debugger code, no? That's why I was using the maxram version (since it looks to live outside heap). There's a substitution stage where the linker .LD file is finalized for things like flash size, EEPROM location, etc. This change could be part of that,

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 7, 2021

I think the linker .LD needs to be changed, then, or else the heap could end up overwriting the debugger code, no?

You are right. In addition to it must be GIMMECACHE used, the memmap needs changing as well to avoid the 16kB at the top. I could have sworn the linker script was different in pico-sdk (at least in January). Please give me the chance to revise the PR.

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 7, 2021

@earlephilhower, I have added a commit to address the memmap issue. At the same time, I added the URL that you also suggested. Thanks.

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One request, please: You can get rid of the copy (git rm memmap_picodebug.ld) of the linker file with a simple define substitution. Here's the git diff (minus boards.txt rebuild):

diff --git a/lib/memmap_default.ld b/lib/memmap_default.ld
index 28e77f1..8749c75 100644
--- a/lib/memmap_default.ld
+++ b/lib/memmap_default.ld
@@ -24,7 +24,7 @@
 MEMORY
 {
     FLASH(rx) : ORIGIN = 0x10000000, LENGTH = __FLASH_LENGTH__
-    RAM(rwx) : ORIGIN =  0x20000000, LENGTH = 256k
+    RAM(rwx) : ORIGIN =  0x20000000, LENGTH = __RAM_LENGTH__
     SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
     SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
 }
diff --git a/platform.txt b/platform.txt
index f2edea9..302ca9d 100644
--- a/platform.txt
+++ b/platform.txt
@@ -107,7 +107,7 @@ archive_file_path={build.path}/{archive_file}
 recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
 
 ## Generate the linker map with specific flash sizes/locations
-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}
+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}
 
 ## Compile the boot stage 2 blob
 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"
diff --git a/tools/makeboards.py b/tools/makeboards.py
index bd6797d..f0ef7b4 100755
--- a/tools/makeboards.py
+++ b/tools/makeboards.py
@@ -78,10 +78,8 @@ def BuildHeader(name, vendor_name, product_name, vidtouse, pidtouse, vid, pid, b
     print("%s.build.led=" % (name))
     print("%s.build.core=rp2040" % (name))
     print("%s.build.mcu=rp2040" % (name))
-    if ramsize == (256 * 1024):
-        print("%s.build.ldscript=memmap_default.ld" % (name))
-    else:
-        print("%s.build.ldscript=memmap_picodebug.ld" % (name))
+    print("%s.build.ldscript=memmap_default.ld" % (name))
+    print("%s.build.ram_length=%dk" % (name, ramsize / 1024))
     print("%s.build.boot2=%s" % (name, boot2))
     print("%s.build.vid=%s" % (name, vid))
     print("%s.build.pid=%s" % (name, pid))

I just ran w/the gimmecache.uf2 one and the above change and it worked a charm. Very cool and pretty painless!

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 7, 2021

Thanks @earlephilhower for the excellent suggestion. I've committed the requested changes.

Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just ran the latest push and was able to bring up a 1-board debug session on blink.ino. Thanks!

@earlephilhower earlephilhower merged commit 47a4d9f into earlephilhower:master Jul 7, 2021
@earlephilhower
Copy link
Owner

Release 1.9.2 should be auto-published in a couple minutes with this update and the supporting toolchain.

@majbthrd
Copy link
Contributor Author

majbthrd commented Jul 7, 2021

Fantastic! Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants