The following are instructions for building a GCC cross-compiler for the MSP430. They are based in part on Peter Bigot's post to mspgcc-users and the gist this was forked from.
export PREFIX=/usr/local/msp430
export PATH="${PREFIX}/bin:${PATH}"
Make sure $PREFIX
exists, is empty, and is writable by you. You can use any directory, it doesn't have to be /usr/local/msp430/
.
Get the latest binutils (currently 2.30) and extract it.
tar xf binutils-2.30.tar.bz2
cd binutils-2.30
./configure --prefix="${PREFIX}" --target=msp430-elf
make
make install
cd ..
The latest gcc release as of this writing is 7.3.0. In order to build GCC you'll also need GMP, MPC, and MPFR libs installed with their header files. Install all these and build GCC for the host.
GCC 7 needs a little patching to fix up some internal compiler errors related to MSP430, use the below patch as directed.
sudo apt install libgmp-dev libmpc-dev libmpfr-dev
tar xf gcc-7.3.0.tar.xz
cd gcc-7.3.0
patch -Np1 -i gcc7-implement-complex-partial-integers.patch
mkdir gcc-build
cd gcc-build
../configure --prefix="${PREFIX}" --target=msp430-elf \
--with-newlib --enable-languages=c,c++
make all-host
make install-host
cd ..
Get the latest newlib (currently 3.0.0) and extract it. Or just grab the git repo.
cd newlib-cygwin
./configure --prefix="${PREFIX}" --target=msp430-elf
make
make install
cd ..
cd gcc-7.3.0/gcc-build
make all-target
make install-target
cd ../..
TI provides the "support files" necessary for building code for the MSP430: headers and linker scripts.
These are distributed as part of MSP430-GCC-OPENSOURCE and can be found on the download page (at least for version 3_02_03_00
) as msp430-gcc-support-files.zip
.
cd msp430-gcc-support-files
cp *.h "${PREFIX}/msp430-elf/include"
cp *.ld "${PREFIX}/msp430-elf/lib"
cd ..
Now let's make sure it works with the customary blinkenlights. We assume that mspdebug is already installed. You may need to tweak the details for your specific chip model.
Put the following in test.c
:
#include <msp430.h>
void __attribute__((interrupt(TIMERA1_VECTOR))) blink(void) {
TACCTL1 &= ~CCIFG;
P1OUT ^= BIT0 | BIT6;
}
void main(void) {
WDTCTL = WDTPW | WDTHOLD;
P1DIR |= BIT0 | BIT6;
P1OUT ^= BIT0;
BCSCTL3 |= LFXT1S_2;
BCSCTL1 |= DIVA_1;
TACCR0 = 1200;
TACTL = TASSEL_1 | MC_1;
TACCTL1 = CCIE | OUTMOD_3;
__bis_SR_register(LPM3_bits | GIE);
}
Build and run it with:
msp430-elf-gcc -mmcu=msp430g2211 -specs=nosys.specs -o test.elf test.c
mspdebug rf2500 'prog test.elf'
Get the latest gdb (currently 7.9) and extract it.
cd gdb-7.9
./configure --prefix="${PREFIX}" --target=msp430-elf
make
make install
cd ..
In mspdebug
, run gdb 1234
.
In msp430-elf-gdb
, run target remote :1234
.
So in TI's official GCC 6 releases, they patch GCC to go find out information about each different MSP430 part in a CSV file instead of having GCC know how to deal with things compiled into itself. This CSV file has information like CPU_TYPE and MPY_TYPE and errata (CPU_Bugs in the code). How should this be handled? Putting it in a file outside of GCC itself seems somewhat reasonable but that's hard to deal with, too...