Note that by uploading a debug sketch you will blow away the bootloader on your Arduino Zero or Feather M0, see the next section for re-loading it!

OK now that we have all that software, the rest isn't too tough!

Load an Arduino Sketch in Atmel Studio 7

Start by launching Atmel Studio 7

Create a new Project

And select Create project from Arduino sketch

Navigate to your arduino sketchfolder and select the sketch. I recommend starting with the easy-to-understand Blink

Also select the Arduino IDE location if necessary. For Board go with Arduino/Genuino Zero (Programming Port) and under Device, ATSAMD21G18A

You'll see the following, where the sketch is in a window, you can edit the code here if you like. For now just leave it as is.

Set Up and Check Interface

OK next up we'll attach the chip & debugger. You have two options:

Arduino Zero Debug port

This is super easy, just connect a USB micro B cable to your Arduino Zero

Make sure you're plugged into the DEBUG port not the 'native' port

J-Link to SWD

If you have a board without an EDBG chip on it, you can still debug, but you'll need a helper such as a J-Link. We like using this handy adapter board

To get the large J-Link cable do the 'classic' 2x5 SWD cable connector

If you are debugging a board that doesn't even have an SWD connector on it, you may need to solder to the SWD pads

You need to connect the following to the J-Link:

  • Vref / Vtarget - Logic voltage of the chip, in this case 3.3V
  • GND to common ground
  • SWDIO to SWDIO
  • SWCLK to SWCLK

I haven't found I need to connect the chip's RESET line

Identify Interface

OK now you have your debugger plugged in, its good to check that it works, select Device Programming

Under Tool make sure you can select EDBG or J-Link

Select ATSAMD21G18A as the device, SWD as the interface and hit Apply

You can then Read the Device Signature. Make sure this all works before you continue!

If you are asked to update the J-Link or EDBG firmware, its OK to do so now.

Build & Start Debugging

OK close out the modal programming window, we dont need it for now. Build the program

Add a Break by clicking on the first DigitalWrite function call, you'll see a red dot

Now run Start Debugging and Break

Note that by uploading a debug sketch you will blow away the bootloader on your Arduino Zero or Feather M0, see the next section for re-loading it!

You'll get prompted to select a debugging tool

Go thru what you did before, selecting the programmer and processor

Once done go back and re-run Start Debugging

You'll end up in a strange code, labeled int main(void) { this is the main entry point to the sketch. Normally this part is never seen, it's what sets up the Arduino before you get to the setup section of the sketch!

Select Continue to skip ahead to your stopping point

Now you'll end up at that DigitalWrite with the red dot. Note that you stop right before this gets run.

Now select Step Over to execute that line. Since you're in step-debugging mode you'll have to Step each function call you want to run. If you just want to continue running the code without any delays or steps, click on Continue like you did before

You can also dig deeper into a function with Step Into

This will let you go into the function call, to see what goes on inside. You can then continue to step over, step in or step out (complete the function)

You can also see variable names below, and the entirety of memory. Since this is just a basic tutorial we wont go into the vast depths of debugging, stack traces, and memory twiddling!

There's a ton more details on the Atmel Studio documentation page

Fixing other errors

Thanks to dgube1 in the forums for running into and finding a fix for this one. Read the post here for more details.

If you are getting a bunch of errors when you try to build the solution, you may need to remove the "math_helper" source files from the project. In the Solution Explorer (see below):

  • Remove math_helper.h from ArduinoCore/include/core
  • Remove math_helper.c from ArduinoCore/src/core

And hopefully that will help.

This guide was first published on Feb 25, 2016. It was last updated on Mar 08, 2024.

This page (Let's go!) was last updated on Mar 08, 2024.

Text editor powered by tinymce.