Installation of gcc 4.9.1 for the MSP430

Pre-requisites

Before we can install the actual compiler we need to make sure all software needed for compiling is installed.

Miscellaneous

sudo apt-get install texinfo expect tk-dev

Install GCC 4.9

Compiling a cross compiling gcc 4.9 with a gcc other than gcc 4.9 proved to be a bit problematic. Since Ubuntu 14.04 ships with gcc 4.8 by default you need to install a 4.9 host compiler as well.

Add a repository with the compiler: sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-4.9

We now have the compiler installed, but it is not the default, let's change that. When we are finished we wil change it back so that version 4.8 is the default again.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 40

Run the config utility:

sudo update-alternatives --config gcc

You will get a list of compilers available, enter the number for the correct compiler to set it as default.

Test if it works:

gcc --version

Should give:

gcc (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Ok, it works, now we can install the MSP430 compiler.

Installation steps

We use the github repository located here.

git clone https://github.com/pabigot/msp430-elf

cd msp430-elf

git checkout sources

After git is finished we have a directory called tools. It is not possible to build gcc in-tree so we are going to make a seperate directory to build the compiler.

mkdir build

cd build

Personally I prefer to install everything into a seperate directory which allows me to maintain different versions at one system. Therefore I install the compiler and its tools in /opt/msp430-elf.

../tools/configure --target=msp430-elf --prefix=/opt/msp430-elf --enable-languages=c,c++ --with-multilib

Now compile it all:

make

On a multiprocessor system you could do a parallel build to speed up compilation. If you have a 4-core processor you can invoke make with the -j4 option to have it run 4 compilations at the same time.

Building can take a few minutes up to a few hours depending on you computer, so time enough to fry an egg or cook a nice beef broth...

Finished?

sudo make install

Now your freshly installed compiler should be in /opt/msp430-elf. Test it:

/opt/msp430-elf/bin/msp430-elf-gcc --version

Should print out something like:

msp430-elf-gcc (GCC) 4.9.1 20140707 (prerelease (msp430-14r1-98)) (GNUPro 14r1) (Based on: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

Install header and linker files

Go back to main git checkout directory:

cd ..

rm -rf tools

git checkout gcc_rh

When git is done we have a new directory named include. Copy everything from that directory over to the msp430-elf device include directory:

sudo cp include/* /opt/msp430-elf/msp430-elf/include

Host compiler

The compiler is now installed successfully. We only have to switch back our main compiler back to version 4.8.

sudo update-alternatives --config gcc

Choose the first option and use gcc --version to check if you are back in version 4.8.2.

Update: as per the comments I added tk-dev as a prerequisite before installing GCC. However in my case it seems the installation seems to have built its own version of TCL/TK and installed it alongside the MSPGCC binaries. Add tk-dev should avoid this and let the build process use the system installed versions.

{{cat: programming, projects}} {{tags: programming, msp430, projects, gcc, compiler}}

This article is my oldest. It is 584 words long, and it’s got 2 comments for now.