Friday, July 5, 2013

How I compile Stellaris projects under OSX

So I don't really know much about the TI Stellaris yet, having mainly used AVR chips to date. But I have a couple of the Stellaris Launchpads, and have managed to get the toolchain working under Mac OS X. I'm not going to repeat all the steps required for that here; you can use this page as a good starting point for that, and noting that you can save yourself a whole bunch of time/hassle by setting up MacPorts and doing this:


sudo port install arm-none-eabi-{gcc,binutils,gdb}


In my $HOME/Code/stellaris directory I have a single Makefile called Makefile.simple, and a separate subdirectory for each project. Its contents look like this:


CC=arm-none-eabi-gcc
LD=arm-none-eabi-ld
OBJCOPY=arm-none-eabi-objcopy
CPU=cortex-m4
STELLARIS_TOP=$(HOME)/build/stellaris/stellaris
CFLAGS_STELLARIS=-mthumb -mcpu=$(CPU) -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -MD -I$(STELLARIS_TOP)
CFLAGS=-std=c99 -Wall -Os $(CFLAGS_STELLARIS)
LDFLAGS_LEFT=-T $(PROG).ld --entry ResetISR 
LDFLAGS_RIGHT=--gc-sections

$(PROG).bin: $(PROG).o startup_gcc.o $(PROG).ld
 $(LD) $(LDFLAGS_LEFT) -o $(PROG).bin $(PROG).o startup_gcc.o $(LDFLAGS_RIGHT)

$(PROG).out: $(PROG).bin
 $(OBJCOPY) -O binary $(PROG).bin $(PROG).out

clean:
 $(RM) $(PROG).bin $(PROG).out $(PROG).[od] startup_gcc.[od]

flash: $(PROG).out
 lm4flash $(PROG).out

You can see in the above that STELLARIS_TOP is set to the location in which I have unpacked (actually git clone...) StellarisWare. This is provided to gcc so that it can find C include files. Adjust as necessary if you are using my Makefile

In each project subdirectory I have a few files:


$ ls
Makefile       blinky.c       blinky.ld      startup_gcc.c

The Makefile merely includes ../Makefile.simple and specifies the name of this project:


PROG=blinky
-include ../Makefile.simple

The other files (blinky.ld and startup_gcc.c), at least at this learning stage, are the same for every project; I just copy them over from project to project.


To build my project, I just type make:


$ make
arm-none-eabi-gcc -std=c99 -Wall -Os -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -MD -I/Users/jslee/build/stellaris/stellaris   -c -o blinky.o blinky.c
arm-none-eabi-gcc -std=c99 -Wall -Os -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -MD -I/Users/jslee/build/stellaris/stellaris   -c -o startup_gcc.o startup_gcc.c
arm-none-eabi-ld -T blinky.ld --entry ResetISR  -o blinky.bin blinky.o startup_gcc.o --gc-sections

My project compiled and linked OK, so it is ready to send to the Launchpad with lm4flash:


$ make flash
arm-none-eabi-objcopy -O binary blinky.bin blinky.out
lm4flash blinky.out
ICDI version: 9270

Please let me know if you found this useful! I also use a similar Makefile structure for building and flashing AVR and MSP430 projects.

No comments:

Post a Comment