Вы находитесь на странице: 1из 27

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

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.3
3.3

4.

5.

Power Consumption Measurements ............................................... 3

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

Creating a New Studio 6 Project ................................................... 19

ASF Wizard ................................................................................................ 19

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

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

2.1.1

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.

PWR

Embedded debugger
USB

4.4 V to 5.25 V
(according to USB spec)

500 mA (according to
USB spec)

DEBUG USB

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 dont 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:

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

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.

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.

asf folder:
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:

microcontroller specific 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.

This folder contains the following:

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.

drivers folder:

This contains low level driver code to directly access the device registers.

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
Launch a New Example Project

Keyboard Shortcut
Ctrl+Shift+E

Launch ASF Wizard

Launch Solution Explorer

Ctrl+Alt+L

Launch Start Page

Launch Extension Manager

Launch Device Programming Window

Launch Command Window

Ctrl+Shift+P

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.
B.
C.
D.

Dropdown option to select the debugger such as SAM ICE debugger or on-board debugger.
Dropdown option to select the device variant.
Type of interface such as JTAG or SWD.
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:

Interface settings:
Tool Information:

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.

It allows you to change the clock frequency of the debugger.


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):

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:

Directories:

Optimization:

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)
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)
Allows you to set the optimization level. (Figure 21)
Page 14 of 24

ARM/GNU Linker Options: Here are some commonly used settings:

Device:
Tool:

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)

You can change the current device variant.


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.
2.
3.
4.

Click File > New > Project


Under C/C++ choose ATMEL-BOARDS
Highlight SAM D20 XPLAINED PRO SAMD20J18
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.
2.
3.
4.

Click Build > Build Solution (or use shortcut F7)


Click Tools > Device Programming
Select the ATSAMD20J18 device and XPRO-EDBG tool, then click APPLY, as shown in Figure 32.
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.
2.
3.
4.
5.

How to launch example Studio 6 project and how to create a blank project.
The project folder/file structure
How to import code with ASF Wizard
The different components and features of the Studio 6 IDE and working with the IDE
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

Atmel Asia Limited

Atmel Munich GmbH

Atmel Japan G.K.

1600 Technology Drive

Unit 01-5 & 16, 19F

Business Campus

16F Shin-Osaki Kangyo Bldg.

San Jose, CA 95110

BEA Tower, Millennium City 5

Parkring 4

1-6-4 Osaki, Shinagawa-ku

USA

418 Kwun Tong Road

D-85748 Garching b. Munich

Tokyo 141-0032

Tel: (+1)(408) 441-0311

Kwun Tong, Kowloon

GERMANY

JAPAN

Fax: (+1)(408) 487-2600

HONG KONG

Tel: (+49) 89-31970-0

Tel: (+81)(3) 6417-0300

www.atmel.com

Tel: (+852) 2245-6100

Fax: (+49) 89-3194621

Fax: (+81)(3) 6417-0370

Fax: (+852) 2722-1369

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.

Вам также может понравиться