Tuesday, September 2, 2008

lpc 2148 blinker 1

Blinking the led on the LPC-H2148 board is actually pretty simple. With this example you will only need to build binutils (dont need gcc).

If you are afraid to write to flash (why?) you can compile this for sram only and load and start it from jtag.

To build for flash, use this linker script and these commands:


arm-thumb-elf-as vectors.s -o vectors.o
arm-thumb-elf-ld vectors.o flashmap -o blink.elf
arm-thumb-elf-objdump -D blink.elf > blink.list


To load using JTAG, power cycle the board, press reset a time or few, then:

openocd -f filename.cfg

In another console:

telnet localhost 4444
reset halt
flash write_image erase blink.elf
reset


If done right then when you power on the board it will start running this program.


/* flashmap */
MEMORY
{
rom(RX) : ORIGIN = 0x00000000, LENGTH = 0x1000
ram(WAIL) : ORIGIN = 0x40000000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > rom
}


To build for sram only, use this linker script and these commands:


arm-thumb-elf-as vectors.s -o vectors.o
arm-thumb-elf-ld vectors.o srammap -o blink.elf
arm-thumb-elf-objdump -D blink.elf > blink.list


To load using JTAG, power cycle the board, press reset a time or few, then:

openocd -f filename.cfg

In another console:

telnet localhost 4444
reset halt
load_image blink.elf
soft_reset_halt
resume 0x40000000


Your program will be lost if you power cycle the board.


/* srammap */
MEMORY
{
rom(RXWAIL) : ORIGIN = 0x40000000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > rom
}


The program itself. Not much to it. Enable pin P1.24 as an output pin. Clearing the pin (setting the output low, ground) will ground the led and turn it on. Setting the pin high will turn off the led. A simple count down from N timing loop is used to delay the state change. Flash does not power up at full speed, and this program does not make any changes to the clock or flash speed.


/* blink.s */

.TEXT

.ALIGN
.CODE 32

b _start /* reset vector */
b .
b .
b .
b .
nop
b . /* IRQ */
b . /* FIQ */

.GLOBAL _start
_start:
ldr r0,=0xE0028018 /* LPC_2148_IO1DIR */
mov r1,#0x01000000 /* P1.24 */
ldr r2,[r0]
orr r2,r2,r1
str r2,[r0]

ldr r0,=0xE002801C /* LPC_2148_IO1CLR */
ldr r1,=0xE0028014 /* LPC_2148_IO1SET */
mov r2,#0x01000000 /* P1.24 */

mainloop:
str r2,[r0]
mov r3,#0x20000
delay1:
subs r3,r3,#1
bne delay1
str r2,[r1]
mov r3,#0x20000
delay2:
subs r3,r3,#1
bne delay2
b mainloop

.END

No comments: