Installing the Development Environment
(distilled from
http://six.media.mit.edu:8080/6/direction/install-software-environment)
There are three software tools you need to begin programming your microprocessor. First you need the
AVR libc tools: avr-binutils, avr-gcc, and avr-lib. These are the tools necessary to actually compile your C code and turn it into machine code for the processor. Second, you want the package of beginner code, sixcode, from the computing culture group. And third you need a terminal program.
The follow instructions guide you through installing these software packages for OS X and Windows. The OS X install seems to be particularly tough (it didn't work for me the first time through), but it is possible. The windows install is much easier. Do not worry if you are unable to complete this on your own, we will go over it in class, but I would like you to try. Please e-mail me with questions.
On OS X:
1. Install
Xcode from
here. Version 2.5 works on both Tiger or Leopard. That's what I installed. If you don't install this you may have errors when you get try the install commands in step 3.
2. Install MacPorts from here. Get whichever version matches your OS. (Tiger or Leopard, etc) MacPorts is a way of downloading, compiling, and managing software tools for OS X. If it works, this is the simples way to install our three AVR Libc tools.
3. Use macports to install avr-binutils.
Open up a terminal window, and type:
sudo port install avr-binutils
sudo port install avr-gccsudo port install avr-libc Each of these 'sudo port' commands that follows is a macport package install. They take a long time to run, and don't give you much feedback. Let them run for a while. They will quit if they have an error.
4. Install
Subversion for Mac.
5. Use Subversion to get the #6 code from googlecode repository. In a terminal window, change to the directory you would like to keep your programming files in (for instance your home directory, and type:
svn checkout http://sixcode.googlecode.com/svn/trunk/ sixcode
This will fetch the package of code, sixcode, from the google svn repository, and copy it to your current directory. You will then have a complete copy of the avrlib procedures and samples. If the svn command is not recognized by the terminal, then you probably need to add /usr/local/bin to your PATH variable. Find out where subversion was installed, then type:
sudo pico /etc/profile
to edit your profile file. It should look like this:
System-wide .profile for sh(1)PATH="/bin:/sbin:/usr/bin:/usr/sbin"export PATHif [ "${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrcfi
Add /usr/local/bin to the PATH line so that it reads:
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
Now when you type the svn checkout .... command, it should run.
6. Make a new environment variable pointing at the code you just downloaded. This is necessary so that the compiler, avr-gcc, knows where to find some of the basic library files it is needs to compile your code. In a terminal window, type:
cd /etc
sudo pico profile
Password: (enter your password)
This launches the pico text editor, in which, towards the bottom, you will add the line:
export AVRLIB=~/sixcode
Now you should be able to compile code for the microprocessor. Skip to section two and see if it works.
If you are having problems. I extracted these instructions from
Setting up the toolchain for a Mac using MacPorts (which I found rather confusing, and did not entirely work for me). They may work for you. If the MacPorts installation does not work out for you, you may need to download and build parts of the software by hand. Initially,
avr-binutils would not build for me. I downloaded and installed the newest Xcode (step 1) and this fixed that problem. However, when I got to
avr-libc it would not install, so I had to build it from source.
Instructions for downloading and building from source are here
Install the #6 Toolchain on Mac OS X.
Make sure to install all packages to the same directory—for instance the macports commands install the software to
/opt/local/, so if you need to build avr-libc from scrath, you need to specify that path for the install. To do this, you change
--prefix=/usr/local/avr to
--prefix=/opt/local in the instructions. See below:
$ bunzip2 -c avr-libc-1.4.4.tar.bz2 | tar xvf -
$ cd avr-libc-1.4.4
$ ./configure --host=avr --prefix=/opt/local
$ make
$ sudo make install
It is challenging to install these software tools, and may be a type of software work that is unfamiliar to you. If you do not find my instructions particularly helpful, please try the instructions available on the mit website, install software environment, they may work better for you. Or do some google searching. We will go over this in class, so do not worry(!), and feel free to contact me with any questions if you are stuck.
--------
On Windows:
1. Install WinAVR, downloaded from here. This has the compiler and whatnot you need to turn C code into machine code for the processor. It includes avr-gcc, avr-libc, and the various binutils you need to make the code.
Installing this package should also install Programmer's Notepad, a really handy program for editing and compiling your programs. And a few other extras, such as SimulAVR (a AVR simulator, I believe)—complete info is available through the WinAVR website.
2. Install Subversion for windows. This looks like a good version: svn-1.4.5-setup.
3. Use Subversion to check out the #6 code from the googlecode repository. Open a DOS command window (Start -> Run: cmd), and change to a directory you want to install the sixcode into, for instance
cd c:
and type:
c:svn checkout http://sixcode.googlecode.com/svn/trunk/ sixcode
This will fetch the package of code, sixcode, from the google svn repository, and copy it to the directory C:sixcode. You will then have a complete copy of the avrlib procedures and samples. Go to the appendix and try to compile some code.
I based my instructions on what I found on the mit website overview for installing the software environment, under the 'Win' section. It did not look as though theirs were entirely accurate, but that reference may be useful if you are stuck. I know we can make this work as I have done it before—so send me e-mail with any questions, and we will also go over all of this in class.
--------
Appendix: Test Your Installation.
You can verify that your installation was a success by trying to comiple one of the examples from the sixcode package. This is done differently on each operating systems.
On OS X:
1. In a terminal window, change to your sixcode directory, and the subdirectories examples/cmdline. For example:
cd ~/code/sixcode/examples/cmdline
If you type ls, you should see the contents of the directory:
littlemac:~/code/sixcode/examples/cmdline rtwomey$ ls
cmdlineconf.h cmdlinetest.c global.h makefile
2. Run make to compile the program. Type
make
If everything is configured properly, this will compile and make the program cmdlinetest.c. It will produce a whole load of output, as it is running, but if was successful, then towards the end you will see:
Errors: none
And typing ls now will show you the results of your compile:
littlemac:~/code/sixcode/examples/cmdline rtwomey$ ls
cmdlineconf.h cmdlinetest.eep cmdlinetest.lst global.h
cmdlinetest.bin cmdlinetest.elf cmdlinetest.map makefile
cmdlinetest.c cmdlinetest.hex cmdlinetest.o
Congratulations, you successfully installed the software tools!
--------
On Windows:
1. Run Programmers Notepad. (installed with WinAVR)
2. Select File-->Open
select the directory c:sixcodeexamplescmdline,
and open cmdlinetest.c
You should see the source code for the program cmdlinetest.c open in the editor window.
3. Select Tools-->[WinAVR] Make all
Your computer will compile the source code, and display its results in the Output window.
If, at the end of the output, you see
> Process Exit Code: 0, then you will know the program compiled correctly.
Congratulations, you are ready to start programming!