I've been making robot arms. There are a few projects here on hackster.io about my progress. I started out on Arduino Uno and have moved along later to Arduino Due. As things progressed they have become more complicated. I've worked to make better code that incorporates more sensors and interfaces. Everything became a little more complicated for my rusty old programmer skills and I started to look for helpful debugging tools. I naively thought that because the Due is an ARM Cortex-M3 (SAM3X8E) chipset with JTAG that it would be relatively easy choosing a hardware debugger. I had hopes of plugging straight into the Arduino 2.0 IDE which came out about then as well. The journey proved a little more twisted than that.
Arduino IDE 2.0 DebuggerThe 2.0 IDE was released in September 2022, and it has a debugger included for the first time. So far, there is very little documentation about configuring the debugger for boards other than the preconfigured offerings. It doesn't so far support the Due, or the probe I selected. The Arduino debugger seems to be based on OpenOCD so there's hope for more configurations becoming available over time.
Nonetheless, the IDE is still part of the process I've landed on. I use it to generate sketches (with "Optimize for debugging" turned on). I then pick up the .elf file output which contains the source code, symbols and executable all-in-one. This is fed into the debugger so it can do its magic.
Black Magic ProbeI selected the black magic probe because it specifically targets Cortex-M microprocessors, was open source, had good reviews, and was a good price. I haven't got experience with other probes to compare it to, but so far so good.
I initially followed the instructions on the Black magic Probe doco, but found the target toolchain has been deprecated. I ended up following the install method at https://askubuntu.com/a/1243405/1169615.
Connecting it upThe single physical USB connection to the probe creates two logical USB devices, the first a connection to the probe GDB server, and the second a connection to the probe UART. Only the first device is used in this example. You can use the dmesg command after plugging in the Black Magic probe USB to the workstation to see the details of devices allocated.
When plugging the JTAG in, pay careful attention to the orientation of the pins. Align the vRef (probe) with the 3V3 (Arduino Due). Note the small white dot screen printed on the PCB adjacent to pin 1.
- Load the Blink.ino example sketch
- Select sketch /Optimize for Debugging
- Select file / preferences / Show verbose output during compile
- Select the Arduino board and port (next to the compile and upload buttons)
- Compile and upload the sketch as normal
- In the compiler output search for and note the directory location of the .elf output.
- change directory to the temporary location the .elf is stored in
- execute arm-none-eabi-gdb passing the .elf as an argument
arm-none-eabi-gdb Blink.ino.elf
Enter the following GDB commands (replacing the USB device with the correct device for your situation):
- target extended-remote /dev/ttyACM1
- monitor jtag_scan
- attach 1
At this point in GDB on the laptop you can use the general GDB commands to set up breakpoint, and inspect code execution pretty much the same as most debuggers work.
The last thing I wanted to point out was the GDB Text User Interface which does a split screen where you can see code, or assembly, or registers alongside a GDB command window.
- tui enable
As you can see above, this shows our sketch code, running in debug, with breakpoints. I think it's the same functionality as the Arduino IDE debugger, just running in a terminal window alonside the IDE rather than integrated.Hope this helps.
More InformationThe book "Embedded Debugging with the Black Magic Probe" by Thiadmer Riemersma, 2023. Is highly recommended.
Comments
Please log in or sign up to comment.