Thursday, January 17, 2008

Installing the Development Environment


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-gcc
sudo 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 PATH

if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi

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!




6 comments:

Terry said...

I might have figured out how to get libc working with macports... See below


Here

To find the portfile, go to

/opt/local/var/macports/sources/rsync.macports.org/release/ports/cross/avr-libc/

edit the "profile" file in pico or vi or something (TextEdit is fine too, but you have to save it somewhere else, then drag and drop it back to its original location)


This should work... though I'm having trouble compiling. Might be because I fucked with so much stuff trying to get it to work tho

micah said...
This comment has been removed by the author.
micah said...

installing software on a mac :) I had tried to help some people in class install the software, but had forgot one step that may have caused the software to not install. To make sure things worked I went home and uninstalled all the software and then reinstalled it to make sure the directions below work. I have now installed this software twice with no problems on my machine and hope that it installs fine on yours. Good luck.


website with helpful info and links:
http://www.nongnu.org/avr-libc/user-manual/install_tools.html#install_avr_gcc

Actual location and package I downloaded are:
LOCATION = http://ftp.gnu.org/gnu/binutils/ FIEL = binutils-2.18.tar.gz
LOCATION = http://gcc-uk.internet.bs/releases/gcc-4.2.2/ FILE = gcc-core-4.2.2.tar.gz
LOCATION = http://download.savannah.gnu.org/releases/avr-libc/ FILE = avr-libc-1.6.1.tar.bz2

NOTE: the money sign "$" indicates the terminal command prompt.

FIRST: we need to remove the link to the "cc" command. From the terminal

$ sudo rm /usr/bin/cc
$ password: mysecretepassword (of course that will be your password)

SECOND: make sure you are in your home directory and make a directory to install the software to.

$ cd
$ mkdir -p local/avr

THIRD: insure that you have downloaded and unarchived all of the needed software. You can get the software by following links from the web page I provided above. I downloaded binutils-2.18, gcc-4.2.2 (the core-version) and avr-libc-1.6.1. You can down load either the "filename".tar.bz2 or "filename".tar.gz file types, don't download the "filename".tar.bz2/gz.sig files.

I will assume you download these to your desktop. Once the files are downloaded you can double click on them to extract the files, after the extraction there will be a folder on the Desktop named, example binutils-2.18 (where as the file you downloaded was named binutils-2.18.tar.gz)

FORTH: move these folders to your home directory, again I assume you have downloaded them to your Desktop. Do the following.

$ cd
$ mv ../Desktop/"folder name" . <---(notice the space dot "." and folder name would be binutils-2.18 etc. )

do this for all unarchived files that you downloaded.
example
$ mv ../Desktop/binutils-2.18 .

FITH: we need to set up your environment to know where to install and where to find the software once it is installed. The direction I am giving you will set up a user specific system environmental file for use with the bash shell.

$ cd (make sure you are in your home directory)
$ vi .bash_profile (this will open a text editor and we will create a new file named ".bash_profile)
(Inside the "vi" application type the following lines)

export PATH=$PATH:~/local/avr/bin
export PREFIX=~/local/avr
export AVRLIB=~/sixcode

(now hit the following key sequence)
Esc (this is the "Esc" key not the letter Esc)
colon (this is the colon character ":" not the word colon)
(at this point you should see the curser at the bottom of the window next to a colon)
wq (this are the letters "wq")
enter (this is the enter/return key)

(ok great, you can check your work by typing "cat .bash_profile" you should see the export stuff you typed will in "vi")
(now type the following at the shell command prompt)

% source .bash_profile

SIXTH: now that the system is set up lets install the software. For those that I had tried to help in class, make sure you set up the .bash_profile file and I am going to have you remove the this you installed in class, it is easy.

$ cd
$ cd binutils-2.18
$ mkdir obj-avr
$ cd obj-avr
$ make clean (only do this line if you installed this component in class with me, though it wont hurt anything if you do it even if you did not install anything)
$ ../configure --prefix=$PREFIX --target=avr --disable-nls
$ make
$ sudo make install
$ password: mysecretepassword (of course that will be your password)

(ok binutils should now be installed, if there was no errors)

$ cd
$ cd gcc-4.2.2
$ mkdir obj-avr
$ make clean
$ ../configure --prefix=$PREFIX --target=avr --enable-languages=c --disable-nls --disable-libssp --with-dwarf2
(NOTE that last on is all one line)
$ make
$ sudo make install
$ password: mysecretepassword (of course that will be your password)

(ok, the avr-gcc compiler should be installed)

$ cd
$ cd avr-libc-1.6.1
$ make clean
$ ./configure --prefix=$PREFIX --build=`./config.guess` --host=avr
$ make
$ sudo make install
$ password: mysecretepassword (of course that will be your password)

(great, given no errors everything is set up and ready to run. Go try and compile the example code)

Terry said...

OK. I can confirm that the procedure I posted earlier, aka adding

"configure.cc avr-gcc"

to the last line of the portfile located at

"/opt/local/var/macports
/sources/rsync.macports.org
/release/ports
/cross/avr-libc/Portfile"

(its all one line, but I had to split it for formatting issues)

WILL fix the problem with installing avr-libc with macports.

You might have a little trouble if you've been tinkering around with things to get it to work, so if that doesn't work, just delete the "/opt" directory and start again from a clean slate.

Thanks to Micah for all your help. Though I didn't end up getting it to work the normal way (sans macports), I really appreciate all your help.


Also, I don't know if I should really throw this out there, as installing the software is a good way to introduce people to the command line, but for macs, there is a utility called "Porticus" (a gui for macports) that can help with the installation. You still need to do the portfile fix though.
But really, learn to love the command line! I know personally I wanna touch base with Micah sometime to learn me some Bash scripting basics...

Anonymous said...

can someone help me out with hooking up the microchip to a computer? the GREAT instructions robert gives us says some nonsense about changing the port options or some shit under system preferences (for macs). and i can't seem to follow nor achieve anything that seems familiar to what is to be done. can anyone help me out?

robert said...

Hi John,
Are you posting about difficulties installing the compiler and other software tools, or difficulties actually communicating with the chip?
You are using OS X, correct?
To communicate with the chip:

(1) install the driver for the usb adapter: http://www.ftdichip.com/Drivers/VCP.htm

(2) install zterm http://homepage.mac.com/dalverson/zterm/
Simply double-click the install icon and follow the on screen instructions.

(3) Once installed, set up Z-Term with the following parameters:

In connection settings:
Turn off flow control
Set Data Rate to 57600
Parity: None

In Text Pacing:
0 delay between characters
1/60th seconds delay between lines

You will want to save these settings, otherwise it is tedious to enter them every time you launch Z-Term. Upon quitting, it will ask you if you want to save.

Make sure you are sending text (text from the *.hex files) to the Number 6, and not files. (Sending the actual file uses a different protocol than we want.)