X-AVR is an XCode template for generating
AVR C projects.
Now the meta version: X-AVR is a python script which uses the installed
avrdude to generate and install an XCode
TemplateInfo.plist file. This template can be used to create
AVR C XCode projects with a
Makefile to build and upload the program to an
Notice: This template does not generate projects in the arduino language. The generated project uses the
C language and the
For example, activating pin 13 on an arduino looks like this:
DDRB |= _BV(PB5) PORTB |= _BV(PB5)
pinMode(13, OUTPUT) digitalWrite(13, HIGH)
There are literally dozens of articles and blog posts showing a very basic setup to use XCode for
AVR C programming: a C project with an external build system based on a
The problem is that with such a basic setup you might as well use a simple text editor instead of XCode. Indeed, you don't get much besides a rudimentary syntax coloring (no autocomplete for example).
To fix this, the
X-AVR project template setus up a fake build target (called
index) which uses clang to enable XCode to parse and index your project code.
X-AVR also cnfigures the following variables for your build:
HEADER_SEARCH_PATHS: So that XCode can index the
avr-libcheaders and include their definitions (port and register names, functions, etc.) in the autocomplete suggestions
GCC_PREPROCESSOR_DEFINITIONS: The selected MCU macro is set (e.g.
__AVR_ATmega328__) to get accurate autocomplete over the port and register names.
F_CPUmacro is also set (otherwise the indexing would encouter errors)
X-AVR, and unlike many other
Makefiles and templates, automatically picks up all the
.h files in your project.
Clone this repository or download the source zip somewhere in your mac and run
python setup.py to generate and install the XCode project template.
The previous step need only be run once (or whenever you install a new
Once the template is installed, you should see an
xavr entry in the new project wizard in XCode.
The wizard page lets you select the target MCU, its frequency and the programmer to be used to upload the program.
After the wizard is done, hit
Cmd+B to build the project.
The project is created with the following targets:
All: performs a clean build and uploads the generated hex to the target MCU
Build: performs a clean build
Upload: uploads the generated hex to the target MCU
Clean: deletes the build artifcats
Index: a trick target to get XCode autocompletion to work. You're not supposed to interact with this target
Also check Using XCode for AVR C developement for more detailed instructions and screenshots.
avr-gccmust be installed and in the
PATHvariable (detectable via a
avrdudemust be installed and in the
PATHvariable (detectable via a
Simply install AVR Crosspack to satisfy these prequisites.
Another option is to use
brew install avrdude brew tap larsimmisch/avr brew install avr-libc
The template icon was created using GIMP and includes a mictochip icon designed by Lutz Schubert from the Noun Project and published under the Creative Commons – Attribution (CC BY 3.0) license.
Makefile is based on the one written by Eric B. Weddington, Jörg Wunsch, et al.
This template was inspired by the embedXcode XCode template.
LICENSE for details (hint: it's MIT).