Using ASF and Atmel Start in IAR

  • Tutorial


ASF and IAR


The Atmel ASF product library has two versions: the built-in Atmel Studio and the so-called stand-alone. Stand-alone version can be used, for example, in the IAR. Since the IAR itself is somewhat ascetic in terms of various chips such as autocomplete, using ASF as an external library is not as interactive and convenient as in Atmel Studio, but nevertheless, you can configure everything once and use the new Atmel Start - WEB code configurator for convenience and speed up development.

Configuring IAR + ASF


First you need to download the stand-alone version of ASF and unzip it.
Then create a new project in the IAR with the necessary options. Suppose we have a board of our own production with a microcontroller SAMD20G16.
In the project options, select:
General -Options-Target-Device - Atmel ATSAMD20G16
General -Options-Library Configuration-Use CMSIS
C / C ++ Compiler -Preprocessor: here you need to specify the paths to the ASF files that will be used in the project.
If you are not going to use Atmel Start (for example, there is no Internet connection)
Folders in ASF itself that store peripheral drivers, as well as configuration files, must be copied to the project folder. System files, such as for working with interrupts, can be left in a folder with ASF (if you are not going to change them).
In order not to overload the preprocessor field, and for convenience, in principle, you can use the PROJ_DIR system variable to specify the path to the files in the folder of the working project and create your own for the path to the ASF folder.
To do this: Tools -Configure Custom Argument Variables-Global-New Group (specify the group name) –Add Variable (specify the variable name and path).
Then the Preprocessor might look something like this (depending on the necessary peripherals):
$ PROJ_DIR $ / drivers / port
$ PROJ_DIR $ / drivers / system / interrupt / system_interrupt_samd20
$ PROJ_DIR $ / drivers / system / interrupt
$ PROJ_DIR $ / drivers / system / pinmux
$ PROJ_DIR $ / drivers / system
$ PROJ_DIR $ / drivers / nvm
$ PROJ_DIR $ / drivers / extint
$ PROJ_DIR $ / drivers / system / clock
$ PROJ_DIR $ /.
$ PROJ_DIR $ / drivers / sercom
$ PROJ_DIR $ / drivers / sercom / usart
$ PROJ_DIR $ / drivers / rtc
$ PROJ_DIR $ / drivers / sercom / spi
$ PROJ_DIR $ / drivers / sercom / spi / module_config
$ PROJ_DIR $ / drivers / sercom / i2c
$ PROJ_DIR $ / drivers / tc
$ PROJ_DIR $ / drivers / system / clock / clock_samd20
$ ASF_DIR $ / utils
$ ASF_DIR $ / utils / preprocessor
$ ASF_DIR $ / utils / cmsis / samd20 / source
$ ASF_DIR $ / utils / cmsis / samd20 / include / pio
$ ASF_DIR $ / utils / cmsis / samd20 / include
$ ASF_DIR $ / utils / header_files
$ ASF_DIR $ / boards
$ ASF_DIR $ / boards / samd20_xplained_pro
$ ASF_DIR $ / .. / common / utils
$ ASF_DIR $ / .. / common / boards
$ ASF_DIR $ / utils / header_files
More in this section you must specify the defines for the project. In our case:
Defined symbols: (one per line)
ARM_MATH_CM0 = true
EXTINT_CALLBACK_MODE = true
__SAMD20G16__
BOARD = USER_BOARD
TC_ASYNC = true
USART_CALLBACK_MODE = true
RTC_COUNT_ASYNC = true
SPI_CALLBALL
false

If you intend to use Atmel Start, the preprocessor settings are automatically generated when the project is loaded.
Assembler-Preprocessor
Output Converter -Output-Generate additional output, Output format: Intel Extended, Output file: Override default: file name.hex
Linker -Config-Linker configuration file: Override default: $ PROJ_DIR $ \ samd20g16_flash.icf
Debugger -Setup- Driver: J-Link / J-Trace
All settings are made.
To write the initialization functions of the controller and peripherals, we will use Atmel Start.
As an alternative, you can see examples of both the IAR and Atmel Studio, or the documentation.

Using AtmelStart


Atmel Start is an online code generator.
Choose a board and controller and create a project: Custom Board, ATSAMD20G16 - Create new project
Let's start by setting the clock. Suppose that our controller is clocked from an external generator with a frequency of 7.37 MHz and we want to have a system frequency of 48 MHz (for how to do this in Atmel Studio see here ).
Open the Go to clock configurator :



Everything is very clear, click on the modules, enter the necessary settings, and it should turn out like this: You


also need to configure the input / output ports of the microcontroller, for this there is a Pin / Mux Configurator . In this section, everything is intuitive.
Of course, you need to add the necessary peripherals - Add Software Component. For the convenience of the search, we leave only the search for drivers. We find the desired one, for example, SPI, select the quantity and add. You can also do this on the main page by clicking on the “+” next to Drivers.


Now go to its settings.
We indicate all the parameters we need. It turns out something like this:


We do all the other settings of the periphery and everything that we need. When everything is ready, we export the project to the format we need.
To do this: Export Project: - Include IAR (.ipcf) file - Download Pack


Change the archive extension to a simple zip and unpack it into the project folder. In IAR: Tools -Options-Project-Enable Project Connections.
Next Project-Add Project Connection - IAR Project Connection- Ok, select the file: iar-project-connection.ipcf. Further, all the settings and the files themselves in the folders will appear in the project.


You can compile and enjoy!

Also popular now: