Section 1 Introduction to the AT91SAMD20 and the Development Environment



Similar documents
How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Introducing a platform to facilitate reliable and highly productive embedded developments

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

USER GUIDE EDBG. Description

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

Atmel AT32UC3A3256 microcontroller 64MBit SDRAM Analog input (to ADC) Temperature sensor RC filter

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AT91SAM ARM-based Flash MCU. Application Note

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Software Prerequisites Linux Ubuntu LTS. Estimated completion time: 15min. The goal of this hands-on is to:

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

AT88CK490 Evaluation Kit

USER GUIDE. ZigBit USB Stick User Guide. Introduction

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

Atmel AVR ATxmega384C3 microcontroller OLED display with pixels resolution Analog sensors. Ambient light sensor Temperature sensor

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

CryptoAuth Xplained Pro

UM1680 User manual. Getting started with STM32F429 Discovery software development tools. Introduction

Atmel AVR4029: Atmel Software Framework User Guide. Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

UM0985 User manual. Developing your STM32VLDISCOVERY application using the IAR Embedded Workbench software. Introduction

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

How To Design An Ism Band Antenna For 915Mhz/2.4Ghz Ism Bands On A Pbbb (Bcm) Board

Two mechanical buttons Two user LEDs Four expansion headers. Board controller with USB interface. One power LED and one status LED

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

General Porting Considerations. Memory EEPROM XRAM

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

APPLICATION NOTE. Atmel AT01180: Barcode and QR code scanner User Guide. Atmel 32-bit Microcontroller. Features. Introduction

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

3. Programming the STM32F4-Discovery

UM1790 User manual. Getting started with STM32L053 discovery kit software development tools. Introduction

UM0834 User manual. Developing and debugging your STM8S-DISCOVERY application code. Introduction. Reference documents

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

APPLICATION NOTE. Atmel AVR600: STK600 Expansion, Routing and Socket Boards. Atmel Microcontrollers. Introduction

APPLICATION NOTE. AT17284: Proximetry Cloud Based Smart Plug User Guide. SMART ARM-based Microcontrollers. Introduction. Features

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

UM1727 User manual. Getting started with STM32 Nucleo board software development tools. Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AVR2033: SAM-ICE Adapter Hardware User Manual. 8-bit Atmel Microcontrollers. Features. Introduction

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Atmel ATSAM3X8E microcontroller Atmel AT86RF GHz radio transceiver Atmel proprietary Lightweight Mesh software stack 10/100Mbps Ethernet

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

Getting started with software and firmware environments for the STM32F0DISCOVERY kit

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

CodeWarrior Development Studio for Freescale S12(X) Microcontrollers Quick Start

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

TWR-KV31F120M Sample Code Guide for IAR Board configuration, software, and development tools Rev.0

AN3354 Application note

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AT89C5131A Starter Kit... Software User Guide

Atmel Power Line Communications. Solutions for the Smart Grid

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AN10866 LPC1700 secondary USB bootloader

Lab 1 Course Guideline and Review

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AN3265 Application note

APPLICATION NOTE. AT03155: Real-Time-Clock Calibration and Compensation. SAM3 / SAM4 Series. Scope

Zynq-7000 Platform Software Development Using the ARM DS-5 Toolchain Authors: Simon George and Prushothaman Palanichamy

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

UM1969 User manual. Getting started with STM32F746G discovery software development tools. Introduction

Dell Statistica Statistica Enterprise Installation Instructions

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Ride7 for ARM. RAISONANCE Tools for the STRx and STM32 families. Overview and Getting Started

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Building an Embedded Processor System on a Xilinx Zync FPGA (Profiling): A Tutorial

SAM D21 Xplained Pro. Preface. SMART ARM-based Microcontrollers USER GUIDE

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AVR911: AVR Open Source Programmer. 8-bit Atmel Microcontrollers. Features. Introduction

Transcription:

Section 1 Introduction to the AT91SAMD20 and the Development Environment Tasks In this section you will learn: The basics of the core you will be working on AT91SAMD20 and its features The basics of the development environment Atmel Studio 6 How to connect to the target via Studio 6.1 and load the binary to the target 12/02/13

Table of Contents 1. Introduction to the Core...1 2. The Evaluation Kit...2 2.1 Power Considerations... 3 2.1.1 Power Consumption Measurements... 3 3. Atmel Studio 6.1...3 3.1 Installing Atmel Studio 6.1... 4 3.2 Working with a Studio 6.1 Project... 6 3.2.1 Launching an Example Project... 6 3.2.2 Studio 6.1 IDE Components... 7 3.2.2.1 Project Folder/File Structure... 8 3.2.2.2 Menus... 11 3.2.2.3 Device Programming Tool... 12 3.2.2.4 Debugging Windows... 13 3.2.2.5 Project Properties... 14 3.2.2.6 Makefile... 17 3.2.2.7 Extension Manager... 18 3.2.3 Creating a New Studio 6 Project... 19 3.3 ASF Wizard... 19 4. Programming and Debugging the SAMD20 with Studio 6.1... 20 4.1 Connecting the Board... 20 4.2 Compiling and downloading... 21 4.3 Debugging Your Code... 22 5. Conclusion... 24 ii

1. Introduction to the Core The Atmel SAM D20 family of microcontroller is based on the ARM Cortex -M0+ 32-bit processor. It has the following salient features: CPU running at up to 48 MHz In-system, self-programming flash ranging from 16-256 KB and SRAM ranging from 2 to 32 KB Internal and external clock options with 48 MHz Digital Frequency Locked Loop SWD programming interface Peripherals such as Timers, ADC, DAC, Analog Comparators and Watchdog Timers Up to six Serial Communication Interfaces (SERCOM), individually configurable to operate as either SPI, TWI or USART Up to 52 programmable I/O lines Operating Voltage of 1.62 V to 3.63 V 64, 48, or 32 pin in TQFP or QFN package Figure 1 shows the block diagram of the microcontroller. Figure 1. Block diagram For detailed information on the microcontroller, please refer to the datasheet. Page 1 of 24

2. The Evaluation Kit The Atmel SAM D20 Xplained Pro evaluation kit houses the ATSAMD20J18 microcontroller and includes an on-board embedded debugger. Therefore, no external tools are necessary for programming or debugging. Some of its salient features are: 32 khz on-board crystal Micro-USB interface Virtual COM-port interface to target via UART Two mechanical buttons (user and reset button) One user LED 3 extension headers Two possible power sources Debug USB or External power source through the 4-pin power header marked PWR The SAM D20 Xplained Pro kit is fully supported by Atmel Studio 6.1 IDE. Several example applications for the kit are available as a starting point to develop user application. The IDE provides an easy platform to develop, program, and debug code for the SAMD20 target. More information on this is provided in Section 4. Figure 2. SAMD20 Xplained PRO Evaluation Kit Page 2 of 24

2.1 Power Considerations The power supply sources for SAMD20 Xplained Pro kit are shown in Table 1. Depending on availability, the kit will automatically make the necessary adaptation. Table 1. Power sources for SAMD20 kit Power input Voltage requirements Current requirements Connector marking External power 4.3 V to 5.5 V Recommended minimum is 500 ma to be able to provide enough current for extensions and the board itself. Recommended maximum is 2A due to the input protection maximum current specification. Embedded debugger USB 4.4 V to 5.25 V (according to USB spec) 500 ma (according to USB spec) PWR DEBUG USB 2.1.1 Power Consumption Measurements To measure current consumed by the SAMD20 microcontroller, replace the jumper on the current measurement header with an ammeter. This is shown in Figure 3. Figure 3. Current Measurement Header For detailed information on the evaluation kit, please refer to the User Guide. 3. Atmel Studio 6.1 Atmel Studio 6 is the integrated development environment (IDE) for developing and debugging Atmel ARM Cortex -M and Atmel AVR microcontroller (MCU) based applications. The Atmel Studio 6 IDE gives you a seamless and easy-to-use environment to write, build, and debug your applications written in C/C++ or assembly code. Atmel Studio 6 is free of charge and comes with a large library of 1600+ example projects. Page 3 of 24

With Studio 6, you can now enjoy Atmel Gallery and Atmel Spaces. Atmel Gallery is an online apps store for development tools and embedded software. Atmel Spaces is a cloud-based collaborative development workspace allowing you to host software and hardware projects targeting Atmel MCUs. Figure 4. Atmel Studio 6.1 3.1 Installing Atmel Studio 6.1 Studio 6.1 can be downloaded from the following site: http://www.atmel.com/tools/atmelstudio.aspx Click on the link as shown in Figure 5. You can choose the complete installer to install on a computer with no access to the internet. You will then be asked to fill a form as shown in Figure 6. You may choose to log in as a guest or create an Atmel account, if you don t already have one, and sign in as an Atmel user. Upon submitting the form, an email will be sent to the email address you provided with a link to the installer as shown in Figure 7. Run this installer. Page 4 of 24

Figure 5. Link to download Studio 6 The installer version at this time is 2730. This could be different during the time you attempt to download the installer. You may also have to download and install a patch to support newer hardware kits which is not required for the SAMD20 Xplained PRO kit. Figure 6. Download form Please provide a valid email address. A link to the installer will be emailed to this email address. Page 5 of 24

Figure 7. Installer link from email Installing Studio 6.1 may take several minutes depending on the speed of your computer. 3.2 Working with a Studio 6.1 Project In this section, we will learn the following: 1. How to launch an example project. 2. How to work with the IDE. 3. How to create a new project. 3.2.1 Launching an Example Project You can launch a new ASF example project from either the Start Page as shown in Figure 8 or the File Menu Option. The Start Page is available when Studio 6 is launched. It can also be accessed from View menu option. To open an example project, follow the steps below: 1. Click File > New > Example Project. 2. Select SAM D 32-BIT under Device Family as shown in Figure 9. 3. Select the required example project from one of the ASF versions. You may want to choose the most recent ASF version. 4. Provide the project name and location, then select OK. 5. Accept the software license agreement(s). The new example project will then be loaded. Figure 8. New example project Page 6 of 24

Loading the example projects may take several minutes the first time. Figure 9. Device family list Figure 10. Example project list 3.2.2 Studio 6.1 IDE Components The Studio development environment is broadly split into three areas as shown in Figure 11: 1. Atmel Studio Editor: Allows you to edit the source files 2. Solution Explorer: Allows you to explore the project source files 3. Output Window: Displays messages from the GCC compiler Page 7 of 24

Figure 11. Atmel Studio 6.1 IDE 3.2.2.1 Project Folder/File Structure An Atmel Studio Project folder will have the following file and 2 folders as shown in Figure 12: src folder: This folder contains all the project related source and header files. Debug/Release (or any other configuration the user sets up) folder: Upon compilation, this folder contains the map file, executables (.bin,.hex,.elf), binaries, a portion of the makefile, and all the object files..cproj file: The.CPROJ file, saved in XML format, stores all the references for your project including your compilation options. (There is also a.atsln file which stores information about projects that make up your solution.) Figure 12. Studio 6 project root folder in File Explorer Page 8 of 24

src folder: As already mentioned, all the source and header files of the project reside in the src/ folder. This folder will typically have the following items: main.c file (or the application specific file(s)) asf.h header file: This file includes all the API header files required by ASF for the modules you use in your project. It is automatically updated every time you add or remove drivers from your project using ASF wizard (ASF wizard is explained later). You should not manually edit asf.h asf folder: ASF folder: This folder contains the bulk of your project if you depend on ASF to generate code. All driver code imported to your project by ASF resides in this folder. config folder: This folder contains important configuration files such as conf_board.h and conf_clock.h o conf_board.h: This file is mainly used for specific board configuration. The conf_board.h file will allow the developer to define a conditional flag that enables or disables the GPIO to perform the required function in the project. o conf_clock.h: This file includes the definitions of the different clock configurations for the device (clock sources, prescalers, etc.). This is the entry point to configure the clocks used in the application. It is up to the user to change it based on need. The ASF folder contains a folder common to all projects, a folder for each family of microcontrollers, and a third-party folder for all ARM microcontroller projects. A description of each is given below: common folder: This folder contains a board.h header file that defines all the evaluation kits supported by Atmel Studio. It also contains a services and utils folder common to all projects. microcontroller specific folder: This folder contains the following: o boards folder: This folder contains a header file listing definitions specific to the target of the current project. For example, the samd20_xplained_pro.h header file. There is also a board_init.c file that contains a function called board_init that configures the GPIO pins for the different hardware peripherals. o drivers folder: This contains low level driver code to directly access the device registers. o utils folder: This contains utilities such as linker scripts, system calls, and preprocessor definitions. Another important folder inside the utils folder is the cmsis folder. This folder includes: Source file that contains the interrupt vector table definition and the startup code (for example, startup_samd20.c). Source file that contains the clock initialization code (e.g., system_samd20.c) include folder that contains system level header files pertaining to the microcontroller. For example, the top-level header file samd20.h which picks the header file of the microcontroller on the target board, e.g., samd20j18.h for the SAMD20Xplained PRO board. This header file contains the base Page 9 of 24

address definition for all the peripherals such as ADC, Timer Counter, etc. The include folder has sub-folders such as component, instance, and pio. component folder: This contains header files for each peripheral. Each header file defines a structure listing all the registers belonging to the corresponding peripheral. instance folder: This contains header files for each peripheral that lists the memory mapping for each register belonging to the corresponding peripheral. pio folder: This contains header files for each variant of the SAM microcontroller family, for example pio_samd20j18.h. These header files define the hardware pins and port definitions for each peripheral. thirdparty folder: This folder contains software with licenses other than Atmel license. For example CMSIS folder contains CMSIS library and header file with an ARM license. Figure 13 shows the ASF folder structure for a typical SAMD20 project. For more detailed information on ASF please refer to the following application notes: Atmel Software Framework Reference Manual (AVR4030) Atmel Software Framework Getting Started (AVR4029) Figure 13. ASF Folder Structure Page 10 of 24

3.2.2.2 Menus Studio 6 has a rich set of menu options as shown in Figure 14. The look and feel of the IDE is similar to Visual Studio. Therefore, most of the icons are standard options that are also found in Visual Studio, such as SAVE, SAVE ALL. The START DEBUGGING AND BREAK and START WITHOUT DEBUGGING icons are easily accessible. The current target and the debugger are displayed on the menu bar. Other important icons are shown in Table 2. Figure 14. Menu options Table 2. Studio shortcuts Icon Function Keyboard Shortcut Launch a New Example Project Ctrl+Shift+E Launch ASF Wizard Launch Solution Explorer Ctrl+Alt+L Launch Start Page Launch Extension Manager Launch Device Programming Window Ctrl+Shift+P Launch Command Window Ctrl+Alt+A Launch I/O View Window for Debugging Page 11 of 24

3.2.2.3 Device Programming Tool The Device Programming tool can be launched from the tools menu option. Figure 15 displays the device programming tool window. The different parts of the tool are explained below: A. Dropdown option to select the debugger such as SAM ICE debugger or on-board debugger. B. Dropdown option to select the device variant. C. Type of interface such as JTAG or SWD. D. Once the proper debugger, device variant, and interface are selected, clicking READ will display a unique device signature. E. The title bar displays the chosen debugger. F. Other options to the left of the tool are as follows: Memories: Allows you to erase the chip, select a pre-built.elf or.hex file and program it to the target. It also allows you to verify the flash after programming. Interface settings: It allows you to change the clock frequency of the debugger. Tool Information: Displays the debugger information such as firmware version, hardware version, etc. Device Information: Displays information of the device variant such as flash size, SRAM size, type of processor, etc. Security: This will allow you to set a security bit so as to disallow access through all external programming and debugging interfaces. Figure 15. Device programming tool Page 12 of 24

3.2.2.4 Debugging Windows Atmel Studio provides various debugging windows that are extremely useful. They can be accessed during debugging from the Debug menu option: Debug > Windows. Some important debug windows are: Breakpoints: This lists all the breakpoints that have been applied. They can be disabled while debugging as well. I/O View: This is an extremely important tool for debugging, shown in Figure 16. It shows the values of registers, including the value of each bit in the register and the memory location of the register. Processor View: This displays the value of some important register such as Program Counter, Stack Pointer, etc., as shown in Figure 17. Memory: Displays the contents of different parts of the memory such as Flash memory while debugging the flash. Figure 16. I/O View Page 13 of 24

Figure 17. Processor View 3.2.2.5 Project Properties The Project Properties Window can be accessed from the Project Menu: Project > <Project Name> Properties. From this window, you can set the following: Build: You can set different Build Options from here. You can choose to use an external Makefile or the default Makefile generated by Studio 6. You can create different Configuration such as Debug, Release or custom configurations each having different build options or compile/linker settings. Build Events: This allows you to set pre-build or post-build events such as running specific DOS commands. Toolchain: This is probably the most used feature from Project Properties. Here are all the options that can be set: o ARM/GNU Common Options (Figure 18): o Output file format such as.hex,.bin, etc. Output code format such as Thumb or ARM. ARM/GNU C Compiler Options: Here are a few commonly used settings: Symbols: You can set symbols to be defined and undefined for the current project. The icons on the top right of the defined symbols and undefined symbols window allow you to add new symbols, remove existing symbols, edit existing symbols and move an existing symbol up or down the list. (Figure 19) Directories: You can specify to the compiler the include paths of all the directories in the project. The icons on the top right of the window allow you to add new paths, remove existing paths, edit or move an existing path up or down the list. (Figure 20) Optimization: Allows you to set the optimization level. (Figure 21) Page 14 of 24

o ARM/GNU Linker Options: Here are some commonly used settings: Libraries: You can specify to the Linker all the libraries that need to be linked and also the path to the library. There are icons that allow you to add new library/library path, remove, edit or move an existing library/ library path. (Figure 22) Miscellaneous: You can specify other linker flags and objects such as path to the linker file. (Figure 23) Device: You can change the current device variant. Tool: You can choose a debugging tool that can be used with the target board. Figure 18. OutputFiles setting Figure 19. Symbols definition Page 15 of 24

Figure 20. Directory path setting Figure 21. Optimization level Figure 22. Linker Library settings Page 16 of 24

Figure 23. Miscellaneous Linker settings 3.2.2.6 Makefile Studio 6 generates a Makefile based on the project properties defined. All Studio 6 projects for SAM Microcontrollers contain a Makefile template in the ASF/SAM/utils/Make folder. This template is basically a script with a set of rules that is used to generate the Makefile. Please note that this is NOT the actual Makefile. The actual Makefile generated by Studio 6 using the template and the project properties can be found in the Debug or Release folder (or the custom configuration set) found in the root directory of the project as shown in Figure 24. Figure 24. Makefile generated by Studio 6 Page 17 of 24

3.2.2.7 Extension Manager Many additional extensions including libraries that may be useful are available for download from the extension manager. These provide enhanced features for a variety of projects. Most tools are free products from Atmel and third-party developers. To install an extension, simply choose your product and click Download, shown in Figure 25. You will be asked to log in to your myatmel account, shown in Figure 26. For new users, signing up is quick and easy. Figure 25. Extension Manager Figure 26. myatmel login Page 18 of 24

3.2.3 Creating a New Studio 6 Project We already know how to create a new project from the list of ASF example projects. However, if you want to create a new empty project for an Atmel evaluation kit or a custom board, Studio 6 will create a project template populated with minimal code complete with main.c, asf.h, and other header files. Here is how you create a new project: 1. Click File > New > Project 2. Under C/C++ choose ATMEL-BOARDS 3. Highlight SAM D20 XPLAINED PRO SAMD20J18 4. Give your project a name and then select OK Figure 27. New project setup 3.3 ASF Wizard Atmel Software Framework (ASF) allows easy design, evaluation, and prototyping of projects by providing the user a collection of embedded software, managed by the ASF Wizard. When designing, it is important to add necessary modules from ASF to your project. With your project opened, select ASF > ASF Wizard. The ASF Wizard window should be displayed with the list of the available drivers, services, and components, as shown in Figure 28. On the right side of the window, you can find the list of drivers already added in the project. On the left you can find all the drivers, services, and modules that are available to add. Page 19 of 24

Figure 28. ASF Wizard Window Modules can be found by either manually scrolling down the list or by using the search box. As an example, we will add a delay module to our project by typing the word delay in the search box, as shown in Figure 29. The Delay routines module appears as the result and we add this by highlighting the name of the module and then clicking ADD. The addition is not finalized until we select APPLY, after which a summary of changes is available for viewing. Figure 29. Adding modules in ASF Wizard 4. Programming and Debugging the SAMD20 with Studio 6.1 Once your project is ready, it is time to connect Studio 6.0 to the target, compile and debug. 4.1 Connecting the Board Connect the SAMD20 microcontroller to the PC via the mico-usb port as shown in Figure 30. Consider the power requirements as previously mentioned in Section 2.1. Page 20 of 24

Figure 30. Connecting the board 4.2 Compiling and downloading With our project ready for device programming, we can compile and download the firmware to the target using the following steps: 1. Click Build > Build Solution (or use shortcut F7) 2. Click Tools > Device Programming 3. Select the ATSAMD20J18 device and XPRO-EDBG tool, then click APPLY, as shown in Figure 32. 4. Under MEMORIES, the.elf file should be already selected for programming. Now click PROGRAM, as shown in Figure 33. Figure 31. Build solution Page 21 of 24

Figure 32. Set up device for programming Figure 33. Program device 4.3 Debugging Your Code To start debugging your code, you will need to first choose a debugger. With a project open, click No Tool and select XPRO-EDBG ATML1873040200003972 (These numbers will not be the same as they are the serial number found on your board) as shown in Figure 27. (Note that the interface will automatically select SWD.) Figure 34. Choosing the debugger Page 22 of 24

Many of the debugging features in Atmel Studio are commonly found in Visual Studio. Table 3 shows a list of functions from the toolbar. Table 3. Debug toolbar options Icon Function Shortcut Start Debugging F5 Start Debugging and Break Alt + F5 Stop Debugging Ctrl + Shift + F5 QuickWatch Shift + F9 Step Into F11 Step Over F10 Step Out Shift + F11 Run to Cursor Ctrl + F10 Reset Shift + F5 Disassembly Alt + 8 Registers Alt + 5 Memory 1 Alt + 6 Processor View I/O View Placing breakpoints in the code allows the program to run and pause while the user checks to see if the program is functioning correctly at any point. The process in Atmel Studio is exactly the same as it is for Visual Studio. Clicking on the left margin of the code places a breakpoint at that line. There is also the option of right clicking on any line of code and choosing Breakpoint > Insert Breakpoint. Page 23 of 24

5. Conclusion In this section we have covered a basic introduction to the SAMD20 core and the Atmel SAM D20 Xplained Pro evaluation kit. We have gone through the Atmel Studio 6 IDE in quite a detail. We are now familiar with the following: 1. How to launch example Studio 6 project and how to create a blank project. 2. The project folder/file structure 3. How to import code with ASF Wizard 4. The different components and features of the Studio 6 IDE and working with the IDE 5. How to compile and debug the project on the target In the next few chapters, we are going to learn the different peripherals available on the SAMD20 and we are going to write code to access and control these peripherals via Studio 6 projects. Page 24 of 24

Atmel Corporation 1600 Technology Drive San Jose, CA 95110 USA Tel: (+1)(408) 441-0311 Fax: (+1)(408) 487-2600 www.atmel.com Atmel Asia Limited Unit 01-5 & 16, 19F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon HONG KONG Tel: (+852) 2245-6100 Fax: (+852) 2722-1369 Atmel Munich GmbH Business Campus Parkring 4 D-85748 Garching b. Munich GERMANY Tel: (+49) 89-31970-0 Fax: (+49) 89-3194621 Atmel Japan G.K. 16F Shin-Osaki Kangyo Bldg. 1-6-4 Osaki, Shinagawa-ku Tokyo 141-0032 JAPAN Tel: (+81)(3) 6417-0300 Fax: (+81)(3) 6417-0370 2013 Atmel Corporation. All rights reserved. / Rev.: Error! Reference source not found. Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.