Monday, June 7, 2010

AVR development on Mac OS X with XCODE


Are you an AVR fan who has recently migrated to Mac and disappointed by the lack of AVR support for Mac users? Specially if you have been working on CVAVR and AVRStudio for development, and now you realise that there is no such GUI available for Mac.
A closer look at the situation reveals that there is ample support and resources available for here which I will list one by one.

Alternative 1 :
Install VMware on Mac and run all your old windows programs without a glitch. The disadvantage is that running another OS like XP, more so if its Windows 7, consumes a lot of resources and your system performance goes down. Nevertheless, you can give it a try if you have a free/ trial copy of VMware, and of course XP.

Alternative 2 :
As we all know avr-gcc compilers are available for linux and Mac as well. So you can download and install them and start writing programs and burning them from Terminal command line. This might turn out to be a tedious task if you are new to command line. You are bound to falter once while changing fuse bits through command line and this results in killing your poor Atmel chip.

To burn fuses without burning the chip, there is a nice application available for Mac called the AVR Fuses . This application provides the same interface as your AVRStudio for changing fuses and programming your chip.





This GUI uses avrdude to program the fuses as well as the program memory. (I will explain installing that later). Just go to the preferences and set the right path to avrdude and the programmer port and it begins to work.

Note : If you plan to use a USB to serial converter like the one from prolific you need to install a PL2303 prolific mac driver which is readily available on the web.

Alternative 3 :
A similar but more useful app called the AVR Tools also has a built in serial terminal. So this eliminates the need for XTerm etc. The environment is slowly building up to give you a good experience. This app has a whole list of programmer support ranging form USBasp to the simple sercon mini programmers. Select the port form the dropdown list which is automatically populated depending on the available serial ports (USB to serial adapters, bluetooth serial ports etc.). This as well requires installing avr-gcc and avrdude. I would recommend AVR-Crosspack for installing the avr-gcc toolchains etc. To configure it rightly, please follow Lady Ada's tutorial . Please follow it step by step.



Alternative 4 :
Till now we haven't come across a native IDE for AVR development on Mac. We haven't yet explored the beauty of development on Mac. If you are not familiar with Xcode, its the native development environment for Mac. It has an amazing GUI. Yes, you are thinking in the right direction. We are about to use Xcode for AVR development. Please install and test AVR-CrossPack and configure it correctly before you proceed.
Xcode provides you option for creating project templates. A great person has created a nice AVR template for us. Download the template folder from the following link:

and copy the folder into the directory:

/Developer/Library/Xcode/Project Templates/Others/
or,

/Library/Application Support/Developer/Shared/Xcode/Project Templates/

Now run the Xcode and click open a new project. A template chooser like one of the following will appear depending on where you had copied the folder in the previous step.



Select the AVR project or the Atmega project. On the left pane you see firmware folder. Expand it and you will see 2-3 files including main.c and makefile. main.c is the file you need to edit and write your project in. After writing the code click on build and a hex file will be created in the project folder. From the Release dropdown list on top left, you can choose to flash the microcontroller if the write programmer and options are set in the makefile.

You can also edit this template to include some default things by opening the project file from the directory you copied in the first step. For example, I edited the template so as
1. to use particular serial port by default by editing the make file
AVRDUDE_PORT = /dev/cu.STK500-1-GenericSerial
2. to use a particular programmer type by editing the make file

AVRDUDE_PROGRAMMERID = stk500v2

3. I often use delay functions. So I made a delay.h header file and included it in main.


I made some more changes in the make file to write all the build files in a subdirectory of the project file to prevent it from unnecessary cluttering.

Later, I connected a bluetooth serial module to the programming port of my STK500 board and began flashing it wirelessly from my Mac. So now when I press the build button, it automatically compiles the code and burns it on the microcontroller wirelessly :P . Details about it in the next blog.


Hope you have a good AVR+Mac experience.

2 comments:

Anonymous said...

hi, when i load the template project in xcode, the build the button is not clickable. how can you make xcode see avr-gcc? thanks for your help. it's a great tutorial.

Anonymous said...

The link to download the Xcode project template does not work.