Romilly,
After compiling LedBlinky, I rolled up all the drivers plus the startup and system code in one library, copied the library, headers and linker script to /usr/local/lpc1768, so basically the library has this:
debug_frmwrk.o
lpc17xx_dac.o
lpc17xx_gpio.o
lpc17xx_mcpwm.o
lpc17xx_qei.o
lpc17xx_ssp.o
lpc17xx_wdt.o
lpc17xx_adc.o
lpc17xx_emac.o
lpc17xx_i2c.o
lpc17xx_nvic.o
lpc17xx_rit.o
lpc17xx_systick.o
lpc17xx_can.o
lpc17xx_exti.o
lpc17xx_i2s.o
lpc17xx_pinsel.o
lpc17xx_rtc.o
lpc17xx_timer.o
lpc17xx_clkpwr.o
lpc17xx_gpdma.o
lpc17xx_pwm.o
lpc17xx_spi.o
lpc17xx_uart.o
lpc17xx_libcfg_default.o
system_LPC17xx.o
startup_LPC17xx.o
Then I copied LedBlinky.c to a new dir and used this makefile:
PATH:=$(PATH):/usr/local/arm-cortex-codesourcery/bin
BIN=blink
OBJECTS=blink.o
LIBS=-lgcc -lc -lcs3 -lcs3unhosted -lcs3arm -llpc1768
GCFLAGS = -mcpu=cortex-m3 -mthumb -msoft-float -O0 -Wall -I. -I./include/ -I/usr/local/lpc1768/include
LDFLAGS = -mcpu=cortex-m3 -mthumb -msoft-float -O0 -Wl,-Map=$(BIN).map -T /usr/local/lpc1768/lpc1768.ld -L/usr/local/lpc1768/ $(LIBS)
GCC = arm-none-eabi-gcc
AS = arm-none-eabi-as
LD = arm-none-eabi-ld
STRIP = arm-none-eabi-strip -s
OBJCOPY = arm-none-eabi-objcopy
REMOVE = rm -f
INSTALL= cp $(BIN).bin /media/MBED/ && sync
SIZE = arm-none-eabi-size
all:: $(BIN).hex $(BIN).bin
$(BIN).bin: $(BIN).elf
$(STRIP) $(BIN).elf
$(OBJCOPY) -O binary -j .text -j .data $(BIN).elf $(BIN).bin
$(BIN).hex: $(BIN).elf
$(OBJCOPY) -R .stack -O ihex $(BIN).elf $(BIN).hex
$(BIN).elf: $(OBJECTS)
$(GCC) $(OBJECTS) $(LDFLAGS) -o $(BIN).elf
stats: $(BIN).elf
$(SIZE) $(BIN).elf
clean:
$(REMOVE) $(OBJECTS)
$(REMOVE) $(BIN).hex
$(REMOVE) $(BIN).elf
$(REMOVE) $(BIN).map
$(REMOVE) $(BIN).bin
install:
$(INSTALL)
.c.o :
$(GCC) $(GCFLAGS) -c $<
Now I just type make && make install and that's it :D also the blink.bin is just 4.3k compared to the fat HelloWorld.bin (22.9k !!) this is great :)
Next, I tried compiling my own toolchain, the end result didn't go very well, but here are the details anyway maybe you could see something I'm missing, I found a script floating around and I modified it after reading the elua tutorial but I also made some mods on my own don't know if maybe I missed up something:
#!/bin/sh
# Written by Uwe Hermann , released as public domain.
TARGET=arm-none-eabi # Or: TARGET=arm-none-eabi
PREFIX=/usr/local/arm-cortex # Install location of your final toolchain
PARALLEL="-j 2" # Or: PARALLEL=""
BINUTILS=binutils-2.20.1
GCC=gcc-4.4.1
NEWLIB=newlib-1.17.0
export PATH="$PATH:$PREFIX/bin"
mkdir build
tar xfvj $BINUTILS.tar.bz2
cd build
../$BINUTILS/configure --target=$TARGET --prefix=$PREFIX --with-gnu-as --with-gnu-ld --disable-nls
make $PARALLEL
make install
cd ..
rm -rf build/* $BINUTILS
tar xfvj $GCC.tar.bz2
cd build
../$GCC/configure --target=$TARGET --prefix=$PREFIX --enable-languages="c" --with-newlib --without-headers --disable-shared --with-gnu-ld --with-gnu-as --disable-nls --with-cpu=cortex-m3 --with-mode=thumb --disable-multilib
make $PARALLEL all-gcc
make install-gcc
cd ..
rm -rf build/*
tar xfvz $NEWLIB.tar.gz
cd build
../$NEWLIB/configure --target=$TARGET --prefix=$PREFIX --disable-nls --with-gnu-ld --with-gnu-as --disable-newlib-supplied-syscall --disable-shared
make $PARALLEL CFLAGS_FOR_TARGET="-mcpu=cortex-m3 -mthumb -D__thumb2__" CCASFLAGS="-mcpu=cortex-m3 -mthumb -D__thumb2__"
make install
cd ..
rm -rf build/* $NEWLIB
# Yes, you need to build gcc again!
cd build
../$GCC/configure --target=$TARGET --prefix=$PREFIX --enable-languages="c" --with-newlib --disable-shared --with-gnu-ld --with-gnu-as --disable-nls --with-cpu=cortex-m3 --with-mode=thumb --disable-multilib
make $PARALLEL
make install
cd ..
rm -rf build/* $GCC
I used it to build the toolchain successfully, but I kept getting this warning when building the nxp library, note that march=<NULL>
warning: switch -mcpu=cortex-m3 conflicts with -march= switch
Anyway, moving on, when it tried to link I got an undefined reference to 'end' in _sbrk, after some research it seems that this symbol should point to the start of the first free word in ram after all the global variables so that sbrk in newlib can use it to allocate dynamic memory, so I added this symbol to the linker script, the _end and __end sort of gave me a hint to where I needed to add end :D
145 .bss :
146 {
147 . = ALIGN (8);
148 __bss_start__ = .;
149 *(.shbss)
150 *(.bss .bss.* .gnu.linkonce.b.*)
151 *(COMMON)
152 __bss_end__ = .;
153 *(.ram.b)
154 . = ALIGN (8);
155 end = .;
156 _end = .;
157 __end = .;
158 } >ram AT>rom
Finally it compiled and I copied the binary but it doesn't blink :( ...
Well at least I have the CodeSourcery toolchain, I think something's wrong with newlib, it should call main eventually maybe it doesn't ? do I need to implement sbrk or change something ? anyway, I will keep the toolchain around, maybe I will give it another shot later when I know better.
P.S. If you want the library, headers and example just let me know how to share them.
Hello,
Any one tried NXP's driver library ? I havn't seen much posts about this library I wonder why no one is using it ? it looks really good and heavily documentd with examples too, anyway, I downloaded the library and I managed to finally run the LedBlinky example after minor modifications, I compiled with codesourcery toolchain, the binary runs fine and the led actually blinks :) however, the Delay function blocks for ever, I tried to set the led in the handler but that didn't work so it seems that the SysTick_Handler is not being called, any help please ? this is my code