MEAM.Design - MAEVARM - Getting Started in OS X

Install Xcode

Download and install the latest Xcode Tools from the Apple Developer Connection (note - you will need to register for a free ADC account). You could also install these from the DVD that came with your machine, if you have it.

Note: If you install Xcode 4.3 or above, you will also need to do the following:
1. Start XCode, and open "Preferences..." from the "XCode" menu.
2. Switch the "Downloads" tab, then click the "Install" button on the "Command Line Tools" row.
If you have Xcode 5.1: 1. Go to Xcode -> Open Developer Tools -> More Developer Tools... 2. Download and Install "Command Line Tools"

Install CrossPack

Download and install the latest AVR CrossPack from

Install DFU Programmer

1. Download this zip file, and unzip the folder.

2. Open terminal and change into the dfu_programmer_install folder. Most likely accomplished with:

cd ~/Downloads/dfu_programmer_install

3. In terminal, type the following:


4. Enter your password, and watch for a successful installation. If you run into trouble, blame Uriah. If you don't run into trouble, thank Uriah.

Compile some sample code

Option 1

1. Download the default Makefile (right-click, save as...), then remove the .txt extension

2. Download this starter program mainc

3. Place the Makefile and main.c file in a folder, and navigate terminal to that folder

4. In terminal, execute:


5. you should see a line that looks something like

avr-gcc -Wall -0s - DF_CPU_16000000 -mmcu-atmega32u4 -c main.c -o main.o

Option 2

1. Download the template code

2. Place your source files (*.c) in atmega/src folder

3. Place your header files (*.h) in atmega/inc folder

4. Navigate terminal to atmega folder and execute:


5. You should see some information about your compiled files and memory usage and the last line should be

[>-----Build Successfully-----<]

Upload your code

1. Connect the microcontroller to the computer, hold the onboard button until the green LED is on (about two seconds), then release, leaving the orange LED illuminated.

2. Execute the following in terminal

make flash

3. You should see a number of messages that indicate that this works. If it does not work, check the connection, and check to make sure the switch is in load and press the reset button.

SAAST CAN STOP HERE. See Andrew or Adrian with questions

Upload pre-compiled code to your M1

If you have a pre-compiled .hex file that you want to load onto your M1, you will need to run dfu-programmer manually, like this:

dfu-programmer atmega32u4 erase
dfu-programmer atmega32u4 flash file.hex

where file should be replaced with the name of the pre-compiled code that you wish to upload.

Running your code

1. Tap the onboard button for less than two seconds, the orange LED should turn off, and your code should run.

But wait, there's more (NOTE THAT THIS IS OPTIONAL)

You can configure Xcode such that you'll never need to use terminal again! It won't be easy but the setup involves pointing Xcode to an outside compiler (in this case, Cross-Pack) and an outside programmer (in this case dfu-programmer) via the custom makefile. Here is the basic (but incomplete) outline for how to do it:

1. Create an Xcode project, and import your main.c file, m_general.h, and the makefile mentioned above.

2. In Xcode, right-click on "Targets" in the list on the left side, and select Add -> New Target... Click on "Other" and create an External Target.

3. Name it "build" and make sure to add it to your current project.

4. In the target settings,

a) for "Build Tool:" enter "/usr/bin/make"
b) for "Arguments:" enter "all"
c) for "Directory:" enter the name of the folder where your makefile resides, if this is a subfolder of your project folder. Otherwise, leave this blank.
d) Under "Build Settings", click the plus sign to add. Enter "PATH" before the equals sign (=), and "$(PATH):/usr/local/CrossPack-AVR/bin" after.

5. Repeat steps 2-4, only this time call the target "flash", and for "Arguments:" enter "flash". Under "Build Settings", add and set PATH = $(PATH):/usr/local/bin.

6. To test this out, right-click on your build target, and select "Build 'build'". Then do the same for the flash target (for this, make sure your M2 board is in programming mode!).

7. It is additionally possible to utilize the "clean" function supported in the above makefile, which 'cleans up' after the compiler by deleting the various files generated during compilation. I leave this as an exercise.

8. For a little extra challenge, see if you can set up a custom template for future M2 projects. (Hint: take a look in your "Developer" folder, under the "/Library/Xcode/" directory.

Setting Up X-Code 4.5.X

Step 1: Create a new project

a) File -> Project

b) Under the OS X heading, select “Other”

c) From the available options select “Empty” and click next

d) Choose a project name and location

Step 2: Creating Targets

	(Targets call Build, Flash, and Clean)

Creating Target “Build”

a )At the bottom of the project window there should is a “+ add target” button

b) From the new window, go to the OS X heading and select “Other”

c) From the available option select “External Build System”

d ) Product name should be “Build” or anything you'd like to represents this. All other fields are unimportant for now. Fill in whatever you like and click Next

e)In the “info” section of the target you just created, fill in the following:

  • Note* tabs for info/build_setting/build_phase are located just under the status bar at the top middle of the page*
    Build Tool: /usr/bin/make
    Arguments: all
    Directory: Folder path to current project. *Example*: “/Users/tylerbarkin/Documents/M2/Test

f) Go to “build settings” for the current Target you are working with.

g) At the bottom of the page, there should be a “+ Add Build Setting” button. Click it and select add user defined definition

h) Where it says new setting type “PATH” and across from that fill in:


Build should be done now.

Step 3: Setting up flash and clean

Setting up flash and clean These targets are done in the exact same way as the “Build” Target. The only thing that should be different are the parameters under “Info” and “Build Settings”. Refer to the follow.

Build :
Info : Build Tools : /usr/bin/make
Info : Arguments : all
Info : Directory : Project Folder Path
Build_Settings : PATH : "$(PATH):/usr/local/CrossPack-AVR/bin"

Flash :
Info : Build Tools : /usr/bin/make
Info : Arguments : flash
Info : Directory : Project Folder Path
Build_Settings : PATH : “$(PATH):/usr/local/bin”

Clean :
Info : Build Tools : /usr/bin/make
Info : Arguments : clean
Info : Directory : Project Folder Path
Build_Settings : PATH : “$(PATH):/usr/local/bin”

Last, make sure that all files are in the project folder you are working with. Files that should be included are “main.c, main.hex, MakeFile, m_general, and m_(any other file you are useing such as bus, usb, imu, ect)”.

To run a target, look to the top left side of the Xcode window. There will be a “Run” and “Stop” Button there. Next to it will be a pull down window with the targets you created. Select the target you wish to run and then click “Run” to execute the target. Build will compile your current main.c file.


I haven't figured out a great way to do this yet. The new XCode made creating templates one of the most unintuitive thing in the world. Currently I find that copying your previous project folder into a new location is the easiest way to keep all your settings. When you do this you will need to change the file name within XCode as well as update the file paths to the new folder you just created.