How we finally managed to get the AVR toolchain working on the Macintosh…
I’ve prepared an installer package that lets you skip most of the steps outlined below.
See this post
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)
We’re using the following Hardware
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) :
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)
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.
cd
into the unzipped folder, and type, one by one:./configure --target=avr --prefix=/usr/local/avr
make
sudo make install
Next, we have to add our new avr directory to the PATH variable, for gcc to find the avr-binutils
export PATH=$PATH:/usr/local/avr/bin
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]…
cd [objdir]
[srcdir]/configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-languages=c
make
sudo make install
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.
cd
into the expanded archive./configure --host=avr --prefix=/usr/local/avr
make
sudo make install
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!
cd
into the expanded archive./configure
make
sudo make install
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
AVRLIB=[dir]
(where [dir] is the path to your avrlib directory)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…
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:
%.cof: %.elf $(BIN) -O ihex --change-section-address .data-0x800000 --change-section-address .bss-0x800000 --change-section-address .noinit-0x800000 --change-section-address .eeprom-0x810000 $< $@
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
uisp -dprog=stk500 -dserial=`echo /dev/tty.UP*` -dpart=atmega8 --erase --upload --verify if=rprintftest.hex
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…
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…
Leave a comment | RSS | TrackBack
[…] 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
[…] 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
[…] 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