bengreen.eu Circle Device

 

Techie Stuff

Projects

Quick Reference

Will be moved to Quick Reference soon

Building MSP430 Cross Compile Toolchain

Building MSP430 Cross Compile Toolchain

These instructions work on Gentoo Linux, a Linux source distribution.

GNU assembler (Gentoo 2.30 p5) 2.30.0
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or later.
This program has absolutely no warranty.
This assembler was configured for a target of `x86_64-pc-linux-gnu'.

gcc (Gentoo 7.3.0-r3 p1.4) 7.3.0
Copyright (C) 2017 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.

Getting Sources

Getting the source of all the tools.

  • binutils-2.31.tar.xz
  • gcc-7.4.0.tar.xz
  • newlib-3.1.0-20181231.tar.gz
  • msp430-gcc-support-files-1.206.zip

Building binutils

Assuming that you have a directory now with the above extracted tarballs

mkdir binutils-2.31-msp430
cd binutils-2.31-msp430
../binutils-2.31/configure --prefix=/opt/msp430-elf-7.4.0 \
--disable-nls --target=msp430-elf
make

Play the waiting game and once finished install it.

sudo make install

Update PATH so the shell can find msp430-elf-as etc.

export PATH=$PATH:/opt/msp430-elf-7.4.0/bin

Testing binutils

TODO: write a really minimal assembly programme for the MSP430G2553

Building gcc

After extracting newlib rename to remove the date stamp... as you can see, that is what I did.

mkdir gcc-7.4.0-msp430
cd gcc-7.4.0-msp430
../gcc-7.4.0/configure --prefix=/opt/msp430-elf-7.4.0 \
    --target=msp430-elf \
    --disable-nls --disable-libssp \
    --enable-languages="c" --with-gnu-as --with-gnu-ld \
    --with-newlib \
    --with-headers=../newlib-3.1.0/newlib/libc/include
make all-gcc

sudo su
make install-gcc

mkdir newlib-3.1.0-msp430
cd newlib-3.1.0-msp430
../newlib-3.1.0/configure --prefix=/opt/msp430-elf-7.4.0 --target=msp430-elf \
--disable-nls --disable-libssp --with-gnu-as --with-gnu-ld \
--disable-newlib-supplied-syscalls
make
sudo su
export PATH=$PATH:/opt/msp430-elf-7.4.0/bin
make install

Once newlib is all built ans installed, make the libgcc.a library from gcc.

cd gcc-7.4.0-msp430
make all
sudo su
export PATH=$PATH:/opt/msp430-elf-7.4.0/bin
make install

Compile Something... the (very) long way

Write a simple main.c file include only a little loop to do nothing and disable the watchdog timer. To compile stuff we need the TI support files which I talk about installing in the next section... to do this part without installing the files they can just be extracted (replace ../msp430-gcc-support-files/include/ with whatever location you extracted them to):

#include <msp430.h>
int main() __attribute__ ((naked));
int main() {
    WDTCTL = WDTPW + WDTHOLD;
    while(1) { }
}

Besides main.c we also need something to setup the stack for the micro... this is probably available in the toolchain somewhere but here we just write it in startup.S:

    .file "startup.S"

#include <msp430.h>

    .section .text,"ax",@progbits

_start:
    mov.w   #(__stack-16), SP
    mov.w   #main, r15
    mov.w   r15, PC

    .section "__reset_vector","ax",@progbits
    .word _start            ;0xfffe (RESET_VECTOR)

    .end

Now... compile, assemble and link all that stuff together:

msp430-elf-gcc -I ../msp430-gcc-support-files/include/ \
    -D__LINUX_MSP430_GCC__ -mmcu=msp430g2553 -c -S main.c -o main.s
msp430-elf-as -mmcu=msp430g2553 -c -o main.o main.s
msp430-elf-as -mmcu=msp430g2553 -gstabs -o startup.o -c startup.S
msp430-elf-ld startup.o main.o -Map=main.map \
    -L ../msp430-gcc-support-files/include \
    -T msp430g2553.ld -o main.elf

Excellent, we have just created a useless programme using MSP430 symbols provided by the linker, WDTCTL, and #defines from msp430g2553.h (msp430.h and -mmcu=msp430g2553 conspire to find that file during compilation).

Alright, maybe you don't believe me... fine, set the LED on the launchpad to turn on then:

int main() {
    WDTCTL = WDTPW + WDTHOLD;
    P1DIR |= 1;
    P1OUT |= 1;
    while (1) { }
}

If you do all that the light should turn on, I promise!

TI Support Files

The compiler and linker just created will now create msp430 object code but does not know anything about memory locations or defined symbols. For all this to work properly the toolchain relies on Linker Scripts and header files. TI supplies these in msp430-gcc-support-files-1.206.zip.

unzip msp430-gcc-support-files-1.206.zip
cd msp430-gcc-support-files
cp include/*.ld /opt/msp430-elf-7.4.0/msp430-elf/lib/430/
cp include/*.h /opt/msp430-elf-7.4.0/msp430-elf/include/

Quick Links: Techie Stuff | General | Personal | Quick Reference