Proper Debugging of ATSAMD21 Processors

Similar documents
Introducting Itsy Bitsy 32u4

Programming Microcontrollers using OpenOCD on a Raspberry Pi

Stand-alone programming AVRs using CircuitPython

Exen Mini. Setup Guide - V1. nerdonic.com

Adafruit Metro Mini. Created by lady ada. Last updated on :12:28 PM UTC

Adafruit 1-Wire Thermocouple Amplifier - MAX31850K

Adafruit 1-Wire Thermocouple Amplifier - MAX31850K

Exen Mini. Setup Guide - V2. nerdonic.com

Adafruit Optical Fingerprint Sensor

Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports

SeeMeCNC Guides. Step 5: Installing the Firmware. This guide will show you how to install the firmware on your Rostock MAX v3 3D printer.

Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports

Adafruit DS3231 Precision RTC Breakout

36mm LED Pixels. Created by Phillip Burgess. Last updated on :45:20 PM EDT

keyestudio Keyestudio MEGA 2560 R3 Board

2.2" TFT Display. Created by lady ada. Last updated on :19:15 PM UTC

Getting Started with the LPC810

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

ARDUINO M0 PRO Code: A000111

USB NeXT Keyboard with an Arduino Micro

Building your own special-purpose embedded system gadget.

Adafruit Feather nrf52840 Express

Adafruit DotStar FeatherWing

SeeMeCNC Guides. RAMBo Control Firmware. This guide will show you how to install the firmware on your SeeMeCNC 3D printer.

Adafruit seesaw. Created by Dean Miller. Last updated on :30:23 AM UTC

Arduino IDE Friday, 26 October 2018

CircuitPython on the nrf52

Adafruit PDM Microphone Breakout

Circuit Playground Express: Piano in the Key of Lime

ARDUINO UNO REV3 Code: A000066

Adafruit HMC5883L Breakout - Triple-Axis Magnetometer Compass Sensor

FPGA RGB Matrix. Created by lady ada. Last updated on :15:42 PM UTC

Adafruit CAP1188 Breakout

Rephone Core 2G-AtmelSAMD21

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Circuit Playground Firmata

FTDI Friend. Created by lady ada. Last updated on :28:54 PM UTC

12mm LED Pixels. Created by Phillip Burgess. Last updated on :38:47 AM UTC

Adafruit Optical Fingerprint Sensor

Using the Android CircuitPython Editor

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Native MP3 decoding on Arduino

Using X-Particles with Team Render

Adafruit I2S MEMS Microphone Breakout

Adafruit Feather 32u4 Basic Proto

Arduino Micro Breadboard Laboratory Interface Processor (Micro BLIP) User Manual

Fujitsu 2010 FAE Training Lab Sunnyvale, CA

Adafruit TB A DC/Stepper Motor Driver Breakout Board

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

The Stack, Free Store, and Global Namespace

ArduCAM CC3200 UNO board

Adafruit WebIDE. Created by Tyler Cooper. Last updated on :29:47 PM UTC

AT06467: Getting started with SAM D09/D10/D11. Features. Description. SMART ARM-based Microcontrollers APPLICATION NOTE

ARDUINO UNO REV3 SMD Code: A The board everybody gets started with, based on the ATmega328 (SMD).

IR Breakbeam Sensors. Created by lady ada. Last updated on :32:59 PM UTC

Start a New Project with Keil MDK-ARM Version 5 and ST Micro Nucleo-F446RE

Adafruit Powerboost 1000C

Getting Started in C Programming with Keil MDK-ARM Version 5

Introducing Circuit Playground

Adafruit's Raspberry Pi Lesson 1. Preparing an SD Card for your Raspberry Pi

Arduino 05: Digital I/O. Jeffrey A. Meunier University of Connecticut

Freeduino USB 1.0. Arduino Compatible Development Board Starter Guide. 1. Overview

22080 IoT2 Appendix B: Get Started with Arduino IDE & ExpLoRer

Adafruit 1-Wire GPIO Breakout - DS2413

Getting Started in C Programming with Keil MDK-ARM Version 5

Adafruit Powerboost 1000 Basic

ITM-MKR680. User s Guide. Document ITM-MKR680 User s Guide 02/11/2018

Adafruit Terminal Block Breakout FeatherWing

TSL2561 Luminosity Sensor

Adafruit HTU21D-F Temperature & Humidity Sensor

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

Build your own NeXT with a virtual machine Created by Matthew Goodrich. Last updated on :10:02 PM UTC

UM QN908x Quick Start. Document information. QN908x, Quick Start, Development Kit, QN9080 DK, QN9080 Development Kit

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

Project Debugging with MDK-ARM

Introducing Pro Trinket

Atmega Fuse Repair Programmer Schematic

Introducing Pro Trinket

Adafruit PowerBoost Charger

The board contains the connector for SWD bus to implement SWD method of programming. Fig. K190 VDD 2 GND 4

Cygnos360 V2 Installation Manual

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Adafruit Mini TFT " 160x80

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Adafruit MAX31865 RTD PT100 or PT1000 Amplifier

Microcontroller Compatible Audio File Conversion

About SunFounder Preface SunFounder is a technology company focused on Raspberry Pi and Arduino open source community development. Committed to the pr

These instructions were adapted from Arduino: Installing Standard Firmata which is licensed under Attribution- NonCommercial-ShareAlike 2.

Get Your Game On. Getting and Installing PCSX. Getting Plugins and BIOS. Installing the "Easy Stuff" Playing PlayStation Games in Linux

ARDUINO MEGA 2560 REV3 Code: A000067

How to Use an Arduino

Adafruit PowerBoost Charger

Adafruit BME280 Humidity + Barometric Pressure + Temperature Sensor Breakout

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer

Touch Board User Guide. Introduction

Megamark Processing 3.0 Setup Guide. Downloading and Installing Processing 3.0

Getting Started in C Programming with Keil MDK-ARM Version 5

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Adafruit BMP280 Barometric Pressure + Temperature Sensor Breakout

Transcription:

Proper Debugging of ATSAMD21 Processors Created by lady ada Last updated on 2017-06-08 06:47:17 PM UTC

Guide Contents Guide Contents Overview Install Software Arduino IDE J-Link Software Atmel Studio 7 Let's go! Load an Arduino Sketch in Atmel Studio 7 Set Up and Check Interface Arduino Zero Debug port J-Link to SWD Identify Interface Build & Start Debugging Paths and Optimizations Correcting Paths to Necessary Files Fixing Some Core Files Restoring Bootloader Arduino Zero Feather M0 or Others 2 3 6 6 6 7 8 8 11 11 12 15 16 25 28 31 33 33 34 Page 2 of 37

Overview Chances are if you're programming firmware on a microcontroller you've had to do some 'fun' debugging. Button presses, interrupts, small memory spaces...it can make debugging quite a challenge! A lot of beginners lean on tried-and-true (if a little frustrating) printf statments or toggling GPIO's with LEDs on them. And don't get me wrong, those techniques work pretty well. But if you come from a software background you're probably used to really nice debugging setups, often built into the IDE Of course its a ton easier to debug software when the computer is running both software and development platform. It's a lot tougher when the processor is physically separated, with its own memory, clocks, peripherals, and its not even of the same processor family! No worries though, there's a full industry set up to create programming/debug dongles and adapters! One of our favorites is SEGGER's J-Link family(http://adafru.it/ldd). They're not cheap but they do support a vast number of chips. Page 3 of 37

Atmel also has it's own debugger chip, the EDBG (http://adafru.it/lde) (apparently its a AT32UC3A4256 programmed with Atmels proprietary firmware) This chip comes on every Arduino Zero and is used to both program and debug firmware Page 4 of 37

You may be wondering "OK so how do I actually do said debugging?" Well you've come to the right place because we're gonna show you how. In this guide we'll show how to debug the ATSAMD21 family (specifically the ATSAMD21G18) which is in the Arduino Zero (http://adafru.it/2843) and Feather M0 (http://adafru.it/wre) family, by using the EDBG or J-Link. Page 5 of 37

Install Software Before you begin you will need some software. Here's what we're using: Arduino IDE As of this writing, 1.6.7 is the latest (http://adafru.it/ldg) so we're using that. We also installed the Arduino SAMD support (http://adafru.it/ldh) and/or Adafruit SAMD support (for Feather M0) (http://adafru.it/ldf) Make sure you also have drivers set up for the board you're using, and get a sketch working and uploaded to the board. That means you have the IDE and package set up, which is something you want done before you continue J-Link Software If you're using a J-Link, install all software and drivers for it (http://adafru.it/ldi) and run the Page 6 of 37

J-Link commander to make sure you update the firmware, new firmware is constantly being released so best to update your 'Link! Atmel Studio 7 Here's where the Mac and Linux people will be sad. This is the IDE software that can do step&memory debugging and its only for Windows. Also you have to make an account on Atmel's site, download it from here (http://adafru.it/cfj) Make sure you have the latest version, we used build 790 Page 7 of 37

Let's go! 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 Page 8 of 37

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 Page 9 of 37

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. Page 10 of 37

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 Page 11 of 37

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 (http://adafru.it/2094) Page 12 of 37

To get the large J-Link cable do the 'classic' 2x5 SWD cable connector (http://adafru.it/1675) Page 13 of 37

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 Page 14 of 37

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 Page 15 of 37

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 Page 16 of 37

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

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 Page 18 of 37

Go thru what you did before, selecting the programmer and processor Once done go back and re-run Start Debugging Page 19 of 37

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 Page 20 of 37

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 Page 21 of 37

You can also dig deeper into a function with Step Into Page 22 of 37

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) Page 23 of 37

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(http://adafru.it/ldj) Page 24 of 37

Paths and Optimizations C and C++ compilers make your code better when they compile it! This is great, but when we are trying to debug our code we don't want anything to change it. If you try to use the debugger and you see that it doesn't move from one line to the next as you would expect, this is because you have compiler optimizations turned on. to turn them off, right click on the ArduinoCore project in the Solution Explorer pane, and click properties. Page 25 of 37

Page 26 of 37

Then under Toolchain, go to the ARM/GNU C Compiler heading and click Optimization. Set Optimization Level to None (-O0). Then do the same thing under the ARM/GNU C++ Compiler heading. Page 27 of 37

Then save your project. Now, repeat the above steps to turn off compiler optimizations for the other project (whatever you have named your sketch) in the solution explorer. There should be two projects in the Solution Explorer pane. ArduinoCore, and whatever you have named your sketch. Make sure you have done the above steps to turn off compiler optimizations on both projects in the solution explorer pane. Correcting Paths to Necessary Files Current versions of Arduino have changed the location of the CMSIS core files that are necessary to compile projects. We can fix these paths by going back to the Properties pane (by right clicking on the project in Solution Explorer and selecting Properties as we did before) and under ARM/GNU C Compiler select Directories and add the new path to the CMSIS core files to the Include Paths section. This can be done by clicking the green plus button, and then finding the folder by clicking the... button in the window that pops up. Leave the Relative Path box checked. Page 28 of 37

The current location of the CMSIS core as of the writing of this guide is: C:\Users\YourNameHere\AppData\Local\Arduino15\packages\arduino\tools\CMSIS- Atmel\1.1.0\CMSIS\Device\ATMEL Then select the path you just added in the list and click the yellow up arrow icon to move it to the top of the list. Page 29 of 37

Now repeat those same steps in the Directories pane under the ARM/GNU C++ Compiler section. Do these steps for both projects in the Solution Explorer pane. Make sure you have done the steps under the "Correcting Paths To Necessary Files" heading for both projects in the Solution Explorer pane. Page 30 of 37

Fixing Some Core Files If you try to debug your sketch now, it may warn of an "undefined referenced to `vtable for HardwareSerial'" To fix this, open the includes/core/hardwareserial.h file under the ArduinoCore project. Scroll down to the class definition around line 67 and replace the class declaration with the following code: class HardwareSerial : public Stream { public: HardwareSerial() {}; virtual ~HardwareSerial() {}; }; virtual void begin(unsigned long) {}; virtual void begin(unsigned long baudrate, uint16_t config) {}; virtual void end() {}; virtual int available(void) = 0; virtual int peek(void) = 0; virtual int read(void) = 0; virtual void flush(void) = 0; virtual size_t write(uint8_t) = 0; using Print::write; // pull in write(str) and write(buf, size) from Print virtual operator bool() = 0; Your file should look like this: Once this is done, you should be able to compile and debug your sketch! Page 31 of 37

Page 32 of 37

Restoring Bootloader When you program in for debugging you are writing direct to the chip, this deletes the bootloader! You'll want to restore it if you ever want to go back to using the Arduino IDE. Arduino Zero This is pretty easy. Launch the IDE, select Arduino Zero (programming port) from the Tools->Board menu, and Atmel EDBG as the Tools->Programmer Then select Burn Bootloader It only takes a few seconds to burn in the bootloader: Page 33 of 37

Feather M0 or Others For this, you'll need to use the Atmel Studio setup, since you're using a J-Link. Download the bootloader hex file featherm0bootloader_160305.zip http://adafru.it/mbg Wire it up correctly and select Device Programming Page 34 of 37

Select J-Link and the ATSMD21G18A with SWD. Verify you can read the Device Signature Next click on Memories in the left hand side Page 35 of 37

Next to the Flash (256 KB) section, click the triple-dots and select the bootloader file. Then click Program to program it in Page 36 of 37

Adafruit Industries Last Updated: 2017-06-08 06:47:16 PM UTC Page 37 of 37