0

HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by extremis on Sat Nov 08, 2008 12:02 am

Many thanks to SolidSilver and his post on getting the 328p working in Linux.

http://ladyada.net/forums/viewtopic.php?f=25&t=7605&p=37855#p37855

I followed his guide in OSX with a few modifications. First, I started by getting all the necessary packages.

binutils 2.19: http://ftp.gnu.org/gnu/binutils/binutils-2.19.tar.bz2
gmp 4.2.4: ftp://ftp.gnu.org/gnu/gmp/gmp-4.2.4.tar.bz2
mpfr 2.3.2: http://www.mpfr.org/mpfr-current/mpfr-2.3.2.tar.bz2
gcc 4.3.2: http://gcc.releasenotes.org/releases/gc ... .2.tar.bz2
avr-libc 1.6.4: http://download.savannah.gnu.org/releas ... .4.tar.bz2
avrdude 5.6cvs: http://download.savannah.gnu.org/releas ... cvs.tar.gz
gdb 6.8: http://ftp.gnu.org/gnu/gdb/gdb-6.8.tar.bz2
simulavr 0.1.2.5: http://download.savannah.gnu.org/releas ... 2.5.tar.gz

After downloading the tools, I extracted them all into a temporary location:

Code: Select all | TOGGLE FULL SIZE
# mkdir -p ~/arduino/avr
# cd ~/arduino/avr
# curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.19.tar.bz2
# curl -O ftp://ftp.gnu.org/gnu/gmp/gmp-4.2.4.tar.bz2
# curl -O http://www.mpfr.org/mpfr-current/mpfr-2.3.2.tar.bz2
# curl -O http://gcc.releasenotes.org/releases/gcc-4.3.2/gcc-4.3.2.tar.bz2
# curl -O http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.6.4.tar.bz2
# curl -O http://download.savannah.gnu.org/releases/avrdude/avrdude-5.6cvs.tar.gz
# curl -O http://ftp.gnu.org/gnu/gdb/gdb-6.8.tar.bz2
# curl -O http://download.savannah.gnu.org/releases/simulavr/simulavr-0.1.2.5.tar.gz
# tar -jxvpf binutils-2.19.tar.bz2
# tar -jxvpf gmp-4.2.4.tar.bz2
# tar -jxvpf mpfr-2.3.2.tar.bz2
# tar -jxvpf gcc-4.3.2.tar.bz2
# tar -jxvpf avr-libc-1.6.4.tar.bz2
# tar -zxvpf avrdude-5.6cvs.tar.gz
# tar -jxvpf gdb-6.8.tar.bz2
# tar -zxvpf simulavr-0.1.2.5.tar.gz


It is likely cleaner to download, extract, compile, install, and then remove each package individually. I organized the steps here to make it easier to explain. Please remember to think about each action and it's impact.

After extracting each package, you have to compile and install them in a specific order, as indicated by the suggested page:

http://www.nongnu.org/avr-libc/user-man ... tools.html

First thing you need to do is decide where you would like to store the installed packages. Since I will be moving them, I used a temporary location of /usr/local/avr.

Code: Select all | TOGGLE FULL SIZE
# sudo mkdir /usr/local/avr
# sudo chown extremis /usr/local/avr
# export $PREFIX=/usr/local/avr
# export PATH=$PATH:$PREFIX/bin
# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PREFIX/lib


After exporting this environment variable, I was ready to compile and install each package.

binutils:
Code: Select all | TOGGLE FULL SIZE
# cd binutils-2.19
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX --target=avr --disable-nls
# make
# make install
# cd ..
# rm -rf binutils*


GCC needs libgmp and libmpfr. To allow me to move /usr/local/avr into the arduino-0012 environment, I compile the gmp and mpfr libraries as static only. If you choose to, you can install them as shared libraries, however you must ensure that you point to the installation directory with --with-gmp= and --with-mpfr= when compiling gcc.

gmp:
Code: Select all | TOGGLE FULL SIZE
# cd gmp-4.2.4
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX --build=avr --disable-shared
# make
# make install
# cd ..


mpfr:
Code: Select all | TOGGLE FULL SIZE
# cd mpfr-2.3.2
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX --target=avr --disable-shared --with-gmp-build=../../gmp-4.2.4 --with-gmp-lib=/usr/local/avr/lib --with-gmp-include=/usr/local/avr/include/
# make
# make install
# cd ..
# rm -rf mpfr* gmp*


gcc:
Code: Select all | TOGGLE FULL SIZE
# cd gcc-4.3.2
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX --target=avr --enable-languages=c --enable-languages=c++ --disable-nls --disable-libssp --with-dwarf2 --with-mpfr=/usr/local/avr --with-gmp=/usr/local/avr
# make
# make install
# cd ..
# rm -rf gcc*


If you run into iconv errors, then you need to replace the Apple provided /usr/include/iconv.h with one from fink or darwinports.

Code: Select all | TOGGLE FULL SIZE
# sudo mv /usr/include/iconv.h /usr/include/iconv.h.apple
# sudo ln -s /opt/local/include/iconv.h /usr/include/iconv.h


avr-libc:
Code: Select all | TOGGLE FULL SIZE
# cd avr-libc-1.6.4
# ./configure --prefix=$PREFIX --build=`./config.guess` --host=avr
# make
# make install
# cd ..
# rm -rf avr-libc*


avrdude:
Code: Select all | TOGGLE FULL SIZE
# cd avrdude-5.6cvs
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX
# make
# make install
# cd ..
# rm -rf avrdude*


gdb:
Code: Select all | TOGGLE FULL SIZE
# cd gdb-6.8
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX --target=avr
# make
# make install
# cd ..
# rm -rf gdb*


If you see the below error, then you need to modify gdb/Makefile

Code: Select all | TOGGLE FULL SIZE
cc1: warnings being treated as errors
In file included from ../../gdb/inferior.h:34,
                 from ../../gdb/avr-tdep.c:34:
../../gdb/breakpoint.h: In function ‘VEC_breakpoint_p_last’:


Remove the -Werror argument from gdb/Makefile, so that it looks like the following snippet of the line WERROR_CFLAGS.

Code: Select all | TOGGLE FULL SIZE
WARN_CFLAGS =  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wno-switch -Wno-char-subscripts
WERROR_CFLAGS =
GDB_WARN_CFLAGS = $(WARN_CFLAGS)
GDB_WERROR_CFLAGS = $(WERROR_CFLAGS)


simulavr:
Code: Select all | TOGGLE FULL SIZE
# cd simulavr-0.1.2.5
# mkdir obj-avr
# cd obj-avr
# ../configure --prefix=$PREFIX
# make
# make install
# cd ..
# rm -rf simulavr*


I tried installing avarice, but it needs BFD, and I had a helluva time getting it to see the headers. Since it isn't needed, I chose not to install it. simulavr and avarice both support gdb. If you have either one, you are fine. Now that everything should have gotten installed into /usr/local/avr, it is time to clean up your arduino-0012 directory and install the new version.

Code: Select all | TOGGLE FULL SIZE
# rm -rf ~/arduino/arduino-0012/hardware/tools/avr
# mv /usr/local/avr ~/arduino/arduino-0012/hardware/tools/avr


... or you can move it out of the way.
Code: Select all | TOGGLE FULL SIZE
# mv ~/arduino/arduino-0012/hardware/tools/avr ~/arduino/arduino-0012/hardware/tools/avr.pre328


Now that the new avr system is in place, it is safe to patch the arduino-0012 environment with the Arduino-0012 328P patch. This patch was inspired by SolidSilver's.

http://www.alluvium.com/~extremis/Arduino328osx.diff

.. and apply it
Code: Select all | TOGGLE FULL SIZE
# cd ~/arduino/arduino-0012
# curl -O http://www.alluvium.com/~extremis/Arduino328osx.diff
# patch -p1 < Arduino328osx.diff


Now that you have installed the new versions of the avr environment, and patched the Arduino tree, you should be ready to compile and install 328P specific code. I'm pretty sure you don't need all of these packages, or need to remove the old environment. However, I just wanted to share how I did it. If you want to avoid all of this, you can grab my prepackaged Arduino 0012 MacOSX package from the following URL.

http://www.alluvium.com/~extremis/arduino12.328p.osx.tbz

I also created a heavilly modified Arduino-0012 environment with support for the Sanguino, TouchShield, ATmega328P, 3pi Robot, and with a few other interesting preferences.

http://www.alluvium.com/~extremis/arduino12.osx.tbz

Finally, I have created an avr specific archive. This archive includes all the files in arduino-0012/hardware/tools/avr. If you like, you can extract this into the tools directory and then apply the .diff from above. Note: if using the avr.osx.tbz archive with the diff, you will encounter a failed patch [hardware/tools/avr/etc/avrdude.conf] but ignore it since the file is already modified in the avr.osx.tbz

http://www.alluvium.com/~extremis/avr.osx.tbz
extremis
 
Posts: 25
Joined: Wed Oct 08, 2008 1:13 pm

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by robotgrrl on Thu Dec 04, 2008 1:40 pm

Just so that you are forewarned- there are a few bugs/gotchas with this
I've been sending lots of the bugs to extremis and he will be working them all out :lol: (it seems to be avr-gcc that's the problem)

robotgrrl
 
Posts: 33
Joined: Sat Apr 05, 2008 5:28 pm

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by fortconsulting on Thu Jan 15, 2009 3:36 am

there is no need to build eveything from scratch - here's the quick and dirty way that worked for me:


(I'm on a g4 running 10.4 -f you are on an intel mac just fetch the archive at http://www.alluvium.com/~extremis/ardui ... 8p.osx.tbz as mentioned elsewhere in this thread and use it directly)

#mkdir ~/arduino
# mkdir ~/arduino/tmp
#cd ~/arduino
#curl http://www.arduino.cc/files/arduino-0012-mac.zip
#unzip ./arduino-0012-mac.zip
# cd ~/arduino/arduino-0012
# curl -O http://www.alluvium.com/~extremis/Arduino328osx.diff
# patch -p1 < Arduino328osx.diff

patch will fail (I don't know why) with the following output:

patching file hardware/boards.txt
patching file hardware/cores/arduino/WInterrupts.c
patching file hardware/cores/arduino/pins_arduino.c
patching file hardware/cores/arduino/wiring.c
patching file hardware/cores/arduino/wiring_analog.c
patching file hardware/cores/arduino/wiring_digital.c
patching file hardware/cores/arduino/wiring_serial.c
patching file hardware/libraries/Servo/Servo.cpp
patching file hardware/tools/avr/avr/include/avr/iom328p.h
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file hardware/tools/avr/avr/include/avr/iom328p.h.rej
patching file hardware/tools/avr/etc/avrdude.conf
Hunk #1 succeeded at 11531 with fuzz 2 (offset -933 lines).

(seems it patched everything except the needed header file changes)

so to fix that grab the osx intel version and use the iom386p.h file from it:

#cd ~/arduino/tmp
#curl http://www.alluvium.com/~extremis/ardui ... 8p.osx.tbz
# tar -jxvf arduino12.328p.osx.tbz
#cp ~/arduino/tmp/arduino-0012/hardware/tools/avr/avr/include/avr/iom328.h ~/arduino/arduino-0012/hardware/tools/avr/avr/include/avr/iom328.h

verify you have a working instalation with the 328p installed on a board and selected in the arduino ide by compiling and uploading a sketch (I used blink from the examples)

you should be good to go

(as long as everything is working you may optionally execute the following to free up disc space:)

#rm -rf ~/arduino/tmp

and also optionally:

#mv ~/arduino /Applications/

to place it in your systemwide Applications folder

hope this helps. if these directions don't work for you please contribute by helping to fix them. I hacked the above first then wrote this from notes and memory afterward, so there may be errors. if there are please point them out and help fix them or ask for help fixing them. I'll be happy to respond to questions.
fortconsulting
 

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by adafruit on Thu Jan 15, 2009 1:16 pm

btw, arduino 13 is coming out -real soon now- and has 328p support

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by silkox on Sun Jan 25, 2009 2:07 pm

It's too soon to tell for sure, but I think all this is over my head. :?

When arduino-13 comes out, will it work with OS 10.3.9? How soon is "-real soon now-" -- days, weeks, months?

Still wondering how to say it: ard-u-ee-no or ard-wee-no?

silkox
 
Posts: 27
Joined: Wed Jan 14, 2009 1:17 am

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by mtbf0 on Sun Jan 25, 2009 6:03 pm

Still wondering how to say it: ard-u-ee-no or ard-wee-no?

think arduous, but don't pronouce to 'u' as 'you', (as i would), but as 'ooh'. or listen to this. the name is, surprisingly, (to me), of german origin and has nothing to do with ardor or arduousness, but means staunch friend.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by silkox on Sun Jan 25, 2009 6:18 pm

Thanks for the pronunciation help. I used to say ard-you-ee-no, but my 8th grade daughter explained about diphthongs and won the bet. Kids these days!

BTW, I got the boarduino so my daughter and I could play with it together, and we're both looking forward to getting it working again. Of course, I'm the one who broke it in the first place.

silkox
 
Posts: 27
Joined: Wed Jan 14, 2009 1:17 am

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by silkox on Mon Jan 26, 2009 10:50 pm

Actually, following fortconsulting's suggestions wasn't that hard, and I think I had already fixed iom328p.h using spiffie's instructions.

However, compiling still isn't working. I do have a new and even shorter set of error messages, pasted below. Thanks in advance for any suggestions.

Code: Select all | TOGGLE FULL SIZE
hardware/tools/avr/bin/avr-gcc: line 2: readlink: command not found

In file included from /Users/user/Documents/electronica/arduino-0012/hardware/tools/avr/bin/../lib/gcc/avr/4.3.0/../../../../avr/include/avr/io.h:319,

                 from /Users/user/Documents/electronica/arduino-0012/hardware/cores/arduino/pins_arduino.c:25:

/Users/user/Documents/electronica/arduino-0012/hardware/tools/avr/bin/../lib/gcc/avr/4.3.0/../../../../avr/include/avr/common.h:83:7: error: missing binary operator before token "0"

Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/tmp/build21744.tmp/Blink.hex': No such file

silkox
 
Posts: 27
Joined: Wed Jan 14, 2009 1:17 am

Re: HOWTO: Get Arduino 12 working with an ATmega328P in MacOSX

by msproul on Sat Feb 07, 2009 12:29 am

I am very disappointed with the 328, I am using version 0012 on MacOSX and CANNOT switch to version 13 because of issues with the liquidware slide and low level problems in the AVR support that are fixed in the Liquidware version of 12. I compile the GPS sample code supplied and get this error


/Arduino/arduino-0012LW/hardware/cores/arduino/WInterrupts.c:55: error: 'GICR' undeclared (first use in this function)

I do not have the time to even read through the long description above and will NOT go to that length to fix it.


Mark
msproul
 
Posts: 1
Joined: Thu Jan 01, 2009 9:56 pm

Please be positive and constructive with your questions and comments.