From 49ff81fa70b40b1763da0ed2936f64879f91b812 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 31 Dec 2012 03:19:59 -0300 Subject: [PATCH] lpc111x-isp/test/: proof of concept LED-blinking code --- lpc111x-isp/test/Makefile | 26 +++++++++++ lpc111x-isp/test/lpc1112fxx2xx.lds | 45 +++++++++++++++++++ lpc111x-isp/test/test.c | 69 ++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 lpc111x-isp/test/Makefile create mode 100644 lpc111x-isp/test/lpc1112fxx2xx.lds create mode 100644 lpc111x-isp/test/test.c diff --git a/lpc111x-isp/test/Makefile b/lpc111x-isp/test/Makefile new file mode 100644 index 0000000..ea6e921 --- /dev/null +++ b/lpc111x-isp/test/Makefile @@ -0,0 +1,26 @@ +PREFIX = arm-linux-gnueabi- + +CC = $(PREFIX)gcc +OBJCOPY = $(PREFIX)objcopy +OBJDUMP = $(PREFIX)objdump + +CFLAGS = -Wall -mcpu=cortex-m0 -march=armv6-m -mthumb \ + -nostdlib +LDFLAGS = -Tlpc1112fxx2xx.lds + +OBJS = test.o + +.PHONY: dump clean + +test.bin: test.elf + $(OBJCOPY) -j .text -j .data -O binary $< $@ || \ + { rm -f $@; exit 1; } + +test.elf: $(OBJS) + $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) + +dump: test.elf + $(OBJDUMP) -d test.elf + +clean: + rm -f $(OBJS) test.elf test.bin diff --git a/lpc111x-isp/test/lpc1112fxx2xx.lds b/lpc111x-isp/test/lpc1112fxx2xx.lds new file mode 100644 index 0000000..529e3b8 --- /dev/null +++ b/lpc111x-isp/test/lpc1112fxx2xx.lds @@ -0,0 +1,45 @@ +/* http://www.embedds.com/programming-stm32-discovery-using-gnu-tools-linker-script/ */ + +ENTRY(__init) + +MEMORY { + RAM(rwx): ORIGIN = 0x10000000, LENGTH = 4K + FLASH(rx): ORIGIN = 0x0, LENGTH = 16K +} + +SECTIONS { + .text : { + . = ALIGN(4); + KEEP(*(.vectors)) + *(.init) + *(.text) + *(.text*) + *(.rodata) + *(.rodata*) + . = ALIGN(4); + } >FLASH + + _data_flash = .; + .data : AT(_data_flash) { + . = ALIGN(4); + _data_begin = .; + *(.data) + *(.data*) + . = ALIGN(4); + _data_end = .; + } >RAM + + .bss : { + _bss_begin = .; + __bss_start__ = _bss_begin; + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(4); + _bss_end = .; + __bss_end__ = _bss_end; + } >RAM + + _stack_end = ORIGIN(RAM)+LENGTH(RAM); + _neg_stack_end = -_stack_end; +} diff --git a/lpc111x-isp/test/test.c b/lpc111x-isp/test/test.c new file mode 100644 index 0000000..0f01fb7 --- /dev/null +++ b/lpc111x-isp/test/test.c @@ -0,0 +1,69 @@ +/* + * Test code for the Tornado CPU board + */ + +#include +#include + + +extern uint32_t _data_flash; +extern uint32_t _data_begin; +extern uint32_t _data_end; +extern uint32_t _bss_end; +extern uint32_t _stack_end; +extern uint32_t _neg_stack_end; + + +#define IOCONFIG 0x40044000 +#define GPIO_BASE_0 0x50000000 +#define GPIO0DATA (GPIO_BASE_0+0x3ffc) +#define GPIO0DIR (GPIO_BASE_0+0x8000) + +/* LED is on PIO0_5 */ + + +int main(int argc, char **argv) +{ + volatile uint32_t *data = (void *) GPIO0DATA; + volatile uint32_t *dir = (void *) GPIO0DIR; + uint32_t mask = 0; + uint32_t loop; + + *dir = 1 << 5; + + while (1) { + *data = mask; + mask ^= 1 << 5; + for (loop = 100000; loop; loop--); + } +} + + +void __attribute__((naked, section(".init"))) __init(void) +{ + register uint32_t *t = &_data_begin; + register uint32_t *s = &_data_flash; + + while (t != &_data_end) + *t++ = *s++; + while (t != &_bss_end) + *t++ = 0; + main(0, NULL); +} + + +#define INITIAL_SP ((uint32_t) &_stack_end) +#define NEG_INITIAL_SP ((uint32_t) &_neg_stack_end) +#define VECTORS 8 + + +uint32_t __vectors[VECTORS] __attribute__((section(".vectors"))) = { + INITIAL_SP, /* initial SP value @@@ */ + VECTORS*4+1, /* reset */ + 0, /* NMI */ + 0, /* HardFault */ + 0, /* reserved */ + 0, /* reserved */ + 0, /* reserved */ + NEG_INITIAL_SP-(VECTORS*4+1),/* checksum */ +};