Ardunio 2.0 IDE debugger with a custom board

Hey all,

I have a custom board that is mostly based off of the Adafruit Grand Central M4 Express with a SAMD51 microcontroller. I'd like to get debugging up and running in the Arduino 2.0 IDE.

I've edited my platform.txt file of my board definition so that it now contains the compiler optimization flags and a debug configuration (similar to what was done in the Arduino SAMD core, link here: ArduinoCore-samd/platform.txt at master · arduino/ArduinoCore-samd · GitHub)

Here is the "compiler" section of the platform.txt file:

# Compile variables
# -----------------

compiler.optimization_flags=-Os
compiler.optimization_flags.release=-Os
compiler.optimization_flags.debug=-Og -g3

compiler.warning_flags=-w
compiler.warning_flags.none=-w
compiler.warning_flags.default=
compiler.warning_flags.more=-Wall -Wno-expansion-to-defined
compiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined

compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.c.elf.cmd=arm-none-eabi-g++
compiler.c.elf.flags={compiler.optimization_flags} -Wl,--gc-sections -save-temps
compiler.S.cmd=arm-none-eabi-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD -D__SKETCH_NAME__="""{build.project_name}"""
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
compiler.objcopy.cmd=arm-none-eabi-objcopy
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
compiler.elf2hex.bin.flags=-O binary
compiler.elf2hex.hex.flags=-O ihex -R .eeprom
compiler.elf2hex.cmd=arm-none-eabi-objcopy
compiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
compiler.size.cmd=arm-none-eabi-size
compiler.define=-DARDUINO=
compiler.readelf.cmd=arm-none-eabi-readelf

And here is the debug configuration:

# Debugger configuration (general options)
# ----------------------------------------
# EXPERIMENTAL feature:
#  - this is alpha and may be subject to change without notice
debug.executable={build.path}/{build.project_name}.elf
debug.toolchain=gcc
debug.toolchain.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
debug.toolchain.prefix=arm-none-eabi-
debug.server=openocd
debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd
debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/
debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript}

Unfortunately, I can't seem to get it to work. When I click the "debug" button in the IDE, here is the output that I receive:

Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
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>'.
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 1.0
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 400 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91samd51p20.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
target halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x00004382 msp: 0x2002ffe8
Error: Couldn't find part corresponding to DID 60060001
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected

I have my custom board connected to an Atmel-ICE unit via an SWD interface.

Any help would be appreciated. Thanks!

Your way ahead of me, however can you program and run the SAMD51? Even if only the "blink w/o delay".

Yep I am able to upload code and run a sketch just fine - both in Arduino IDE 1.8 as well as in Arduino IDE 2.0.

I'd just like to be able to step through my code and debug some issues, hence why I'm hoping to get the debugger working for my board in Arduino IDE 2.0.

1 Like

Hi @davidpruitt. I found this:
https://sourceforge.net/p/openocd/tickets/240/

It seems that this error message is caused by using a version of openocd prior to the addition of ATSAMD51 support in 0.11.0. You are using 0.10.0

I see openocd@0.11.0 binaries are available from Arduino. If the platform for your board is only being installed manually then the easiest way to get that installed is probably to use the Arduino IDE Boards Manager to install version 3.3.0 of any of the "Arduino Mbed OS Boards" platforms (e.g., "Arduino Mbed OS Nano Boards"). This platform has a dependency on openocd@0.11.0, so installing it will also install that version of openocd.

After that, you can configure your platform to use the newer version of openocd by changing this line:

to this:

debug.server.openocd.path={runtime.tools.openocd-0.11.0-arduino2.path}/bin/openocd

Restart the Arduino IDE to cause the change to platform.txt to take effect, and then try starting another debug session.


If you have a package index set up for your custom boards platform, you can specify a dependency on arduino:openocd@0.11.0-arduino2 in order to cause that tool to be automatically installed by Boards Manager along with your platform. You can learn about that here:

https://arduino.github.io/arduino-cli/latest/package_index_json-specification/#platforms-definitions

1 Like

Thank you for the informative response!

I changed the OpenOCD dependency to 0.11 instead of 0.10 as you suggested (and I installed the Mbed boards to make sure that version 0.11 of OpenOCD got installed as well). After doing this, however, I was still having some issues, so I did some further digging (which also included cloning the OpenOCD git repository onto my machine to search through their code).

In the end, the final nail that got everything working was changing my OpenOCD config file. Originally, I had this line in my OpenOCD config file:

source [find target/at91samdXX.cfg]

Now, I've changed it to this line:

source [find target/atsame5x.cfg]

This is because OpenOCD groups the SAMD51 with the SAME54 chip in their code, rather than with the SAMD21.

After making this change, I ran the debugger in Arduino IDE 2.0, and received the following output:

Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:45)
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 : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Serial# = J42700023027
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x2ba01477
Info : at91samd51p19.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for at91samd51p19.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x00007dd6 msp: 0x2002fff0
Info : SAM MCU: SAMD51P19A (512KB Flash, 192KB RAM)

It then successfully hit the breakpoints that I had set in my code, and I was able to step through my code.

Edit:

If anyone else encounters this issue in the future, I also found the following links helpful in my search:
(1) Omzlo: Programming the SAMD21 using Atmel ICE with OpenOCD
(2) https://www.avrfreaks.net/forum/samd51-and-openocd

Excellent! I'm glad you were able to get it working @davidpruitt. Thanks so much for taking the time to share your findings.

I have been a bit disappointed that I haven't previously seen any 3rd party boards platforms add support for the Arduino IDE 2.x debugger. Certainly the lack of any formal documentation of the system from Arduino is part of the problem, but in theory it should be fairly easy to do just by using the Arduino SAMD boards platform as a reference. As you found, sometimes technical work that is theoretically simple ends up not being so easy after all.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.