1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-04 23:08:07 +02:00

lpc111x-isp/test/: proof of concept LED-blinking code

This commit is contained in:
Werner Almesberger 2012-12-31 03:19:59 -03:00
parent c7a7d358bb
commit 49ff81fa70
3 changed files with 140 additions and 0 deletions

26
lpc111x-isp/test/Makefile Normal file
View File

@ -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

View File

@ -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;
}

69
lpc111x-isp/test/test.c Normal file
View File

@ -0,0 +1,69 @@
/*
* Test code for the Tornado CPU board
*/
#include <stddef.h>
#include <stdint.h>
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 */
};