Section 1 - Introduction To The AT91SAMD20 and The Development Environment
Section 1 - Introduction To The AT91SAMD20 and The Development Environment
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.
2.
3.
3.2
3.2.2
3.2.3
3.3
4.
5.
3.2.2.1
3.2.2.2
Menus .............................................................................. 11
3.2.2.3
3.2.2.4
3.2.2.5
3.2.2.6
Makefile ............................................................................ 17
3.2.2.7
4.2
4.3
Conclusion ........................................................................................24
ii
1.
2.
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
3.
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.
3.1
Page 4 of 24
Page 5 of 24
3.2
3.2.1
Loading the example projects may take several minutes the first time.
3.2.2
Page 7 of 24
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.)
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:
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:
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:
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.
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:
instance folder:
pio folder:
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)
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.
Function
Launch a New Example Project
Keyboard Shortcut
Ctrl+Shift+E
Ctrl+Alt+L
Ctrl+Shift+P
Ctrl+Alt+A
Page 11 of 24
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.
Page 12 of 24
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.
Page 13 of 24
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
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
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)
Page 15 of 24
Page 16 of 24
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.
Page 17 of 24
Page 18 of 24
3.2.3
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
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.
4.
4.1
Page 20 of 24
4.2
Page 21 of 24
4.3
Many of the debugging features in Atmel Studio are commonly found in Visual Studio. Table 3 shows a list of
functions from the toolbar.
Function
Shortcut
Start Debugging
F5
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
Business Campus
Parkring 4
USA
Tokyo 141-0032
GERMANY
JAPAN
HONG KONG
www.atmel.com
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.