# Building Atmel Studio ASF Project using External Makefile

February 2, 2015

The Atmel Studio IDE is a useful tool thanks to the comprehensive debugging support and management of project drivers via the Atmel Software Framework (ASF) – coming from a hardcore Vim advocate. One thing I dislike about IDEs is the fact they hide the make process from the user making it difficult to break a project away from the software. On wishing to develop code on different operating systems (being Visual Studio based, Atmel Studio is limited to Windows), and outside the IDE, I set about creating a Makefile for an Atmel Studio project built around the ASF.

# Makefile

Atmel Studio provides a command line tool for building projects but unfortunately it still relies on the project file and isn’t completely makefile based. Digging into the ASF, I found a Makefiles for AVR and SAM systems in ‘common/util/make’ and ‘sam/util/make’ respectively. It’s a project independant Makefile for each processor type, requiring an include ‘config.mk’ that defines the project specific name, source, includes etc.

Copy this file (either AVR or SAM depending on what you’re using) to the to root directory of the project you want to build.

# Configure

Template ‘config.mk’ files can be found in the various demo projects within the ASF folder. Just do a find . -name config.mk | grep sam3 in the ASF root to find one for the board used in your project. They are well commented so fairly self explanatory. The main changes required are ‘PRJ_PATH’, ‘TARGET_FLASH’ and the source/includes.

# Path to top level ASF directory relative to this project directory.
PRJ_PATH = src/ASF
BUILD_DIR = build

# Target CPU architecture: cortex-m3, cortex-m4
ARCH = cortex-m3

# Target part: none, sam3n4 or sam4l4aa
PART = sam3s2a

# Application target name. Given with suffix .a for library and .elf for a
# standalone application.
TARGET_FLASH = build.elf
TARGET_SRAM = build.elf


Defining the source and includes required for a large project would be a timely and frustrating process – it’s one of the main attractions of the IDE. Thankfully, the build folder contains (‘Debug’ by default) a Makefile that has done this for us (it doesn’t build on its own though). Just copy ‘C_SRCS’ to ‘CSRCS’ and ‘SUBDIR’ tp ‘INC_PATH’ – NOTE the includes in the config.mk are appended with the ASF dir ‘PRJ_PATH’ whereas the ‘CSRCS’ are not.

Finally, check the ‘CPPFLAGS’ defines are the same as those in the IDE. Generally you’ll need to define the MCU in the format ‘MCU‘. Check also that the linker scripts are correct for the board (relative to ‘PRJ_PATH’ again).

# Build

Once configured, simply make at the command line will build the project – completely non-reliant on the Atmel Project. The Makefile and config.mk can also be used for general Atmel projects without the ASF. The files below are examples for a simple GCC application:

Atmel Make SAM Template