Monday, August 31, 2009

binutils for msp430

binutils currently supports the msp430 family of microcontrollers, it is quite simple to build your own cross binutils from sources.

Start by downloading the binutils sources
http://ftp.gnu.org/gnu/binutils/

As of this writing 2.19.1 is the current release, for a direct link
http://ftp.gnu.org/gnu/binutils/binutils-2.19.1.tar.gz

Navigate to a place where you want to perform the build, this does not need to be the final destination you can remove the source directory after you finish the build and install.

The --prefix=/msp430 configuration option specifies the path where I want the binaries installed once compiled. You do not need to prepare this path ahead of time, the make install step will do this, it does need to be a place where you have file permissions to create and write files.

These steps normall work with mingw32 and msys on windows, at this time I have only tried it on Linux (32 and 64 bit ubuntu 8.04 through 9.10beta)


tar -xzvf binutils-2.19.1.tar.gz
cd binutils-2.19.1
./configure --target=msp430 --prefix=/msp430
make
make install


For ubuntu you may need packages like build-essential, bison, flex and possibly others.

To test your install, create a simple program like this one:


outer:
mov #1234,r15
inner:
dec r15
jnz inner

jmp outer


I named mine test.s


PATH=/msp430/bin:$PATH
msp430-as test.s -o test.o
msp430-ld test.o -o test.elf
msp430-objdump -D test.elf

test.elf: file format elf32-msp430


Disassembly of section .text:

0000fc00 <__ctors_end>:
fc00: 3f 40 d2 04 mov #1234, r15 ;#0x04d2

0000fc04 :
fc04: 1f 83 dec r15 ;
fc06: fe 23 jnz $-2 ;abs 0xfc04
fc08: fb 3f jmp $-8 ;abs 0xfc00



Looks like it is working. The device I am using, the 2012, a starting address of 0xFC00 is fine, you can change this by adding -Ttext 0xFD00 to the msp430-ld command (0xFD00 or whatever address).
My loader writes the reset address in the vector table to match the starting address in the binary (.elf) so I dont worry about making binutils do that. Your program will not run though unless address 0xFFFE in flash contains the entry point address of your program.

No comments:

Post a Comment