AVR builder utility

Atmel Studio and avr builder

Atmel Studio

Atmel Studio is available only for Windows users. Alternatively, you can use any liked text editor with some utility to build the project. Atmel Studio uses the make utility to build the project and generate makefile file for this. In general, the makefile can be written by hand, but it seems to me very uncomfortable and unwieldy. I also tried to use other build systems (cmake, scons etc.) but the results I also didn’t like. I wanted to have a very simple, user-friendly and flexible tool for building projects. As a basis I took the Python language, because it is easy to use, not only for writing the build system, but also as a convenient language for describing the configuration of the project.

AVR builder utility

Description of the compilation scripts should be as simple as possible. To build the project is enough to specify a list of source files, the microcontroller model, and its clock frequency (optionally). In addition, I wanted to be able to make an unlimited set of different firmware (eg, debug, release, firmware for different CPU frequencies, etc.) with a single command.

The minimal configuration file looks like this:

name = 'my_project'
src = ['src/*.c']
mcu = 'atmega8'
frequency = 16*1000000

This file should be saved as make.builder in the project root. The build utility reads this file, creates a build directory and starts the compilation and linking process. If successful, the firmware file with the name build/my_project.hex will be created.

Additionally, in the project configuration file file, you can specify the parameters of the avrdude programmer, a set of preprocessor definitions and various compiler/linker options.

name = 'my_project'
src = ['src/*.c', 'src/lib/*.c', 'src/*.s']
mcu = 'atmega8'
frequency = 16*1000000

# avrdude parameters
port = 'com1'
baudrate = 1200
programmer = 'usbasp'

# defines

# compiler and linker options
compiler_options = ['-Os']
linker_options = ['-Wl,--relax']

configurations = {
	"debug": {
		"name": "my_project_debug",
		"defines": ['DEBUG=1']
	"release": {
		"name": "my_project_release",
		"defines": ['DEBUG=0', 'NDEBUG']
	“demo”: {
		"name": "my_project_demo",
		"defines": ['DEBUG=0', 'NDEBUG', 'DEMO_MODE']

Compiled firmware can be downloaded to the device with the command

builder upload

Additionally, some configurations (ie. sets of preprocessor defines) are defined in this example.

If needed, you can specify the parameters of compiler and linker. Default avr-builder sets the parameters so as to generate the most compact and optimized firmware. In my examples, the size of generated firmware is slightly smaller compared to the size of the firmware builded with the Atmel Studio 7 (for release mode) with the default settings.

Another feature of the utility - support for multiple configurations. They can be determined by using an associative array configurations, as in the example above. Suppose you need to create different versions of firmware for different devices (with different circuitry and/or CPU frequency, with different capabilities, etc.). To do this, add the configuration section that defines the distinctive build options.

Also, this builder can be easily adapted to other microcontrollers and platforms. For example, I build them an application for Mac OS X to quickly debug different algorithms without flashing microcontroller. Now this utility can build projects from sources in C and assembler files (with extension .S). I have tested it on Mac OS X, Windows and Linux.


builder all

build all firmwares, and put them in the build directory


builder release demo

build only firmwares for "release" and "demo" configurations


builder clean debug upload

deletes the contents of the build directory, and then build a firmware with "debug" configuration, and upload it to the device.

If some configuration contains a parameter that is already defined in the general configuration (for example, the parameter "name" in the example above), its value will be taken from the configuration settings if the parameter is not an array. In the case of an array the parameter value will be taken from the combination of general (global) parameter and the configuration parameter.

The builder attempts to automatically determine the location of avr-gcc executable files. You can also manually set their location by defining an environment variable with name AVR_GCC_HOME. This variable should point to the directory containing the executable files avr-gcc, avr-objcopy, avr-objdump, avr-size and avrdude.

Examples of projects that use avr-builder, you can see in many of my AVR-projects on github:
and others.

The choice an alternative IDE

After trying various alternatives of Atmel Studio I stopped on NetBeans. This crossplatform IDE can work with C and assembler files (syntax highlighting, code folding), shows the compiling errors and warnings in the code, support code refactoring.

Netbeans IDE

As Makefile file I use file with this content:

  python ~/bin/avr-builder/builder.py

The avr-builder utility is available on github: https://github.com/trol73/avr-make

No votes yet