Using Eclipse to Debug - BitKnitting/wakey_circuitpython GitHub Wiki

Goal

Use Eclipse to debug start_wakey.

Why

A tool is a tool, right? So many ways to debug. I decided to give Eclipse a twirl because it provides a rich debugging environment. Of the many aspects, the one I appreciate the most is the embsysregview plugin. With plugins like embsysregview, we can enhance/increase our understanding of how our mcu works. It is a great complement to the chip's datasheet.

  • Better understand register bits: View results of changes to EIC registers.
  • Step through code. View variables.
    Seriously - it is so awesome to be able to explore what happens when I set the register bits:

What

I created the start_wakey project to figure out how to write to registers on an Adafruit Itsy Bitsy M0 Express. Now let's debug it.

Environment Set up

  • Install Eclipse and ARM GNU toolchain: Through Google, it was fairly simple to install Eclipse (I am running the most current version which is Photon) and the ARM GNU toolchain.
  • Create an Eclipse project based on "Makefile from Existing Code." This is another step that can be Googled. Don't forget to choose the ARM Cross Compiler.
  • Tell Eclipse where the Makefile is located. Open up the Project's Properties dialog, click on C/C++ Build. Add gcc to the build directory path. OH - GEEZ - to increase our chances of maintaining sanity, unclick "Use default build command" and change the build command to make. Click on Apply and Close.
  • Tell Eclipse we'll be using the arm-none-eabi-gcc compiler. Under C/C++ Build, go to Settings and change the C compiler entry.
  • Install the EmbSysRegView plug-in.
  • Tell EmbSysRegView about the SamD21G18A. Now here is the trickiest part of all of this. But well worth the effort. Lucky for us, EmbSysRegView can read CMSIS.SVD files. Atmel makes these files available in Packs. Go to the CMSIS Packs Manager and install the Keil SAMD21_DFP goop. I installed 1.3.0. One of the files that will be copied to our Mac is ATSAMD21G18A.svd. We'll be placing this file with the ones EmbSysRegView knows about.
    • Go to Eclipse.app (mine is in my Applications folder). Right-click and choose SHOW PACKAGE CONTENTS. Navigate to Contents/Eclipse/plugins/org.eclipse.cdt.embsysregview.data_0.2.6.r191/data/SVD(CMSIS)/Atmel
    • Find ATSAMD21G18A.svd (mine is in eclipse-workspace/Packages/Keil/SAMD21_DFP/1.3.0/SVD/SAMD21A). COPY this file into the Atmel folder from the above step. RENAME the file extension TO .xml FROM .svd .
    • Edit the Contexts.txt file in the Atmel folder. Add the line ATSAMD21G18A,ATSAMD21G18A.svd to the file and save.
    • Go into the Eclipse Proprties page Debug -> EmbSys Register Viewer. Choose SVD(CMSIS) for the architecture. Atmel for the vendor. ATSAMD21G18A for the chip. Choose Apply and Close.
  • Add loading the binary to the Makefile. Oh right, I thought this was tricky too.
    • Open up the Makefile in the gcc folder. Go to the bottom and add:
JLINK_OPTS = -if SWD -speed 4000 -device ATSAMD21G18
JLINK = JLinkExe $(JLINK_OPTS)

#############################################################################
# Target: flash
# load app onto target
#############################################################################
flash: flash.jlink
	$(JLINK) flash.jlink
flash.jlink:
	printf "loadfile /Users/margaret/Documents/myLadybugHelper/wakey_circuitpython/Feather_start_test/start_wakey/gcc/AtmelStart.hex\nr\ng\nexit\n" > flash.jlink        

of course, modify the paths to be relevant to your project.

  • Add a Build Target named flash (here yet again Google is your friend).

Debug

I'm assuming you have a JLink connected to the SWD lines of an Itsy Bitsy and the JLink is connected to the Mac through a USB port. I mean - who doesn't? - am I right?

  • Run the flash Build Target.
  • Go into the debugger...

YIPPEE!!!! Now on to debugging an app that wakes up when an external interrupt is triggered.