Why not use the new built-in Arduino debugger for microcontroller development?

A reader pointed out that:

“The [the SAMD21 alternative] Arduino Zero not only comes with a preinstalled debug header, it comes with the debug hardware included. There is no additional debug hardware required at all. You can debug directly using the Arduino IDE.

Although more expensive than the other M0+ boards, it turns out cheaper in total as you don’t need the debug hardware.”

My response:

When I created the new microcontroller lessons in summer 2020 the debugger IDE was not available (except as a beta).  I did try it out at the time but had trouble getting it to work.  Even now, the Arduino IDE debugger is still somewhat limited – offering only high-level access (at the C code level) and tied to the Arduino ecosphere. It also is limited to a small number of boards without the hardware debugger (it was even fewer then).   Also, I prefer (for pedological reasons) to be able to examine disassembled code and raw memory (see Figure 25S.3 in the book – reproduced below).  At the time, the J-Link EDU Mini was only $13 (it has gone up significantly to $60 since then) so I did not see it as cost impediment.  In my opinion, the Segger debugger is much more representative of modern development/debugging environments and I still feel it provides a better introduction to serious embedded systems development.  It also interfaces well with the Segger embOS RTOS, which I believe is one of the two most important contributions in the second half of the new edition of LAoE (the other being finite state machine software and hardware design concepts).

Seeger IDE state of microcontroller after program loading

Finally, I want readers to consider a microcontroller just another component in a circuit/product design.  The traditional Arduino footprint of the Arduino Zero is not well suited to breadboarding. (See image below.)  I only considered breadboard compatible microcontroller boards in developing the book’s embedded systems labs; however, I did include the  Arduino Zero in the list of alternatives microcontroller boards in Chapter 22O. See https://laoe.link/LAoE_Chapter_22O.pdf, Section 22O.1.2.2, where I also note that the debug header is included (but it may no longer be populated based on the current images on the Arduino store web site).

That said, my undergraduate course used the Arduino environment because it was an easy and fast way to learn embedded systems.  The purpose of this book was to go beyond that into professional development tools, hence the switch to the Segger tool chain.

Arduino Zero and breadboard to test code in book using EDBG and Arduino IDE

I did recently try the internal Atmel Embedded Debugger (EDBG) hardware on the Arduino Zero board with both Segger Embedded Studio and the Arduino IDE (Version 2).  It does not work with Segger Embedded Studio, which only supports J-Link.  There is a no longer supported firmware update for EDBG boards that makes them look like they have an on-board J-Link but the Arduino Zero is not listed as supported and I did not try it. (It requires you to install Atmel Studio.) Your mileage may vary. Please let me know if you get it working.

I was able to compile and test all the exercises in Lab 22L using the Arduino IDE and the Arduino Zero EDBG.  You must remove or comment out the line

  #include "samd21.h"     	  // add to use CMSIS

in each program or you will get a compile error.

Arduino IDE debugging Chapter 22L blink delay function program

Nevertheless, the Arduino IDE supports CMSIS and all the code compiled and ran.  The Arduino IDE runs the SAMD21 at full speed (48Mhz) so you have to slow down the  Delay() routine (I changed the DELAYMUL value from 60 to 6000)  to see the LED blink.

However, when I tried the Chapter 23 Labs, the programs would not compile because the internal Arduino support code already set the SysTick_Handler() to its own interrupt service routine.

C:\Users\David\AppData\Local\arduino\sketches\35BDD63E14BC04C0ACBA81EB7D1B6C1F/..\..\cores\arduino_samd_arduino_zero_edbg_7ab4d6888def7306e779da082f31f5d6\core.a(cortex_handlers.c.o): In function `SysTick_Handler':
C:\Users\David\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.14\cores\arduino/cortex_handlers.c:171: multiple definition of `SysTick_Handler'
C:\Users\David\AppData\Local\arduino\sketches\35BDD63E14BC04C0ACBA81EB7D1B6C1F\sketch\JLink_Blink.ino.cpp.o:D:\Users\David\Documents\Arduino\JLink_Blink/JLink_Blink.ino:37: first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1

Since the embedded system lessons in Learning the Art of Electronics program the SAMD12 “bare metal” (i.e. as though they have control of the entire microcontroller), the lessons in the book conflict with similar code in the Arduino environment. So, while the Arduino Zero should work fine when used with the Segger IDE and J-Link (which do not load the Arduino support code) to implement the lessons in Chapters 23 through 27 in the book, the Arduino Zero will not work with all the lessons when used in the Arduino IDE environment even though the Arduino IDE does support CMSIS.  Looking at the Arduino init() function,  Arduino enables all the SERCOM peripherals (SERCOM0 through SERCOM5), the Timer/Counters (TCC0 – TCC2 and TC3 – TC5), and  the ADC and DAC, so the book code that tries to use these peripherals is likely to conflict with Arduino code.

Return to Blog Index or All Blog Posts
As an Amazon Associate I may earn from qualifying purchases on some links.