Programming ATMEL microprocessors on a Mac

6 février 2006 | Research
Tags: | | | |

detail de circuit
How we finally managed to get the AVR toolchain working on the Macintosh…

  1. Introduction
  2. Setup
  3. Installing the toolchain
  4. Pitfalls
  5. Resources

UPDATE 2007-10-01: Life just got a lot simpler:

I’ve prepared an installer package that lets you skip most of the steps outlined below.
See this post

Introduction

For some years now, we have been developing our projects around the BasicStamp microprocessor from Parallax -
mainly because of its simplicity, because of Murat n Konar’s exellent BasicStamp programming app for the Macintosh
- it simply worked…

But the BasicStamp is quite slow and limited, has very little RAM, … we wanted to

And we wanted to do all this from a Macintosh.

it is possible, and there are some resources on the net, but we just spent 3 days getting all up and running so we’d like to share our experiences to get you started a little bit more painlessly

Here’s how it worked (at least for us)

Setup

We’re using the following Hardware

Installing the toolchain

To be able to program AVR microprocessors on your Macintosh you need to download and install the AVR Toolchain - a whole set of open source tools. Mike Seeman has a downloadable archive of all the tools on his
website “AVR Microcontroller Programming on a Mac” but, at the time of this writing, it was a bit outdated.
There are fink-packages available, but they weren’t up to date either. As we wanted to be able to program more recent AVRs (atMega88, or the atTiny2313) we decided to get the latest sources and build all from scratch. It took about three hours to be up and running - here’s how we did it (using the bash terminal) :

Step 1: Developer Tools

In order to be able to compile the sources, you need gcc for PowerPC - install the Apple Developer Tools from the original Tiger installation DVD. (XCode is very nice to write your AVR code in, later, anyway)

Step 2: GNU binutils

the GNU binutils are some tools to manipulate binary data, there can be different versions of binutils for different targets installed on the same system. We’ll compile binutils for the AVR target and put them into a dedicated directiory: /usr/local/avr.

Next, we have to add our new avr directory to the PATH variable, for gcc to find the avr-binutils

Step 3: avr-gcc

We’ll need another version of the gcc-compiler, itself compiled for the avr target. It will get the prefix “avr-” and will go into it’s own directory, so it shouldn’t interfere with the already installed gcc

gcc wants to be compiled in a fresh, empty (temporary) directory. Make a new folder outside the unzipped archive - we’ll refer to it as [objdir], as opposed to the archive, which we’ll call [srcdir]…

Step 4: avr-libc

As we want to code the AVR in C, we’ll need the avr-libc library, which contains basic C routines and data structures for the AVR.

Step 5: uisp

Once our future AVR C code compiled, we’ll need a way to download the binary files into the AVRs flash memory. uisp does just that, and does it great!

Step 6: avrlib

Here, the complete AVR toolchain is installed, and we would be ready to code, compile and flash. But Pascal Stang has written an exellent open source library that does some common and less common tasks, and as we don’t want to reinvent the weel every time, we want that library, too…

(Note: avrlib sounds a lot like avr-libc, but it really is another thing…)

You can unzip and use the library anywhere you’d like (for example in ~/code/avr/) - just add the correct AVRLIB environment variable that points to your avrlib directory to your ~/.profile

Step 7. VT100 Terminal emulation

we use minicom to be able to listen to the avr, see:
How to install minicom on Mac OS X with Darwinports

That’s it - we can start to code, almost…

Pitfalls

Although we installed everything like we were told, we ran into some problems:

First, we weren’t able to compile any of the examples in Pascal Stangs avrlib. There seems to be a problem in his global makefile with our configuration. We found the following solution:

Then, the Keyspan serial adaptor changes its name every time you plug it into another USB port - this can get very annoying with uisp, so we use the -dserial option in uisp like this:

-dserial=`echo /dev/tty.UP*` for the USB-Parallel/Serial adaptor, and
-dserial=`echo /dev/tty.US*` for the USB-Serial adaptor, like in

And finally we’d get only garbage when we wanted to get data back through the serial port to a VT100 terminal. We spent 2 days testing, trying every possible combination of baud-rates and parity and stopbits, worrying, analysing the signal with an oscilloscope, abandoning, double-checking makefiles and global.h…
Just to find out, that, even if uisp tells us the programmer runs the target AVR at an oscillator frequency of 3686400 hz, an out of the box atMega8 runs on an internal RC-Oscillator at quite unstable 1 Mhz, unless you set the fuse bits to use an external oscillator…

CHECK THE FUSE BITS!!

uisp -dprog=stk500 -dserial=`echo /dev/tty.UP*` -dpart=atmega8 --rd_fuses

ATTENTION: if you’re using a crystal above 8 MHZ, you’ll have to set the high fuse byte FIRST, otherwise you can lock youself out of the avr…

uisp -dprog=stk500 -dserial=`echo /dev/tty.UP*` -dpart=atmega8 --wr_fuse_h=0xc9

…sets atmega 8 to prepare for crystal > 8Mhz (CKOPT set to 0), then do:

uisp -dprog=stk500 -dserial=`echo /dev/tty.UP*` -dpart=atmega8 --wr_fuse_l=0xef

which actually turns on the external crystal…

check your processors datasheet for more details on the fuse bits…

Resources



last update: 2006-02-18

Comments

Leave a comment | RSS | TrackBack

  1. […] To compile the firmware you’ll need avr-libc (see here how to do this on a macintosh) To compile the Max external you’ll need the MAX/MSP Software Development Kit and both the Max external and the commandline tool depend on libusb - open source usb library. […]

    Pingback par [ a n y m a ] - uDMX - version 0.9 released — 2006-06-12 @ 10.16 pm

  2. […] We built a custom programming adaptor from an old PCB Card connector. Be sure to program the fuses! It’s a good idea to test the unit before continuing. We soldered the USB cable directly to the pins/resistors for testing, because we needed to desolder them to cut the board in half, and our self-etched board doesn’t like too much soldering/desoldering… […]

    Pingback par [ a n y m a ] - uDMX - version 1.0 released — 2006-06-12 @ 10.20 pm

  3. […] As outlined in the article Programming ATMEL microprocessors on a Mac, installing the AVR toolchain on the Mac can be a long and tedious procedure. Downloading, compiling and installing all the stuff can take up to 6 hours! […]

    Pingback par [ a n y m a ] - AVR-Toolchain Installer Package for MacOSX — 2007-10-01 @ 3.17 pm

Leave a comment

appenzell art avr awards basel basicstamp beautiful leopard belluard berlin bern blog classic concert danse development do-it documentary documentation editing emission ethnology film fribourg geneve hid improvisation india installation interactive i^n kids live making of marseille max/msp medicine midi mobile multimedia music nature paris performance photos poland programming project prévention racisme reportage russia santé schaffhausen science softVNS software streetv synkie theatre tibet trogen tv udmx video videobass visuals wattwil workshop zürich
Creative Commons License
All content - unless otherwise noted - is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Powered by WordPress