LPC2103 >> Assembly

LED


參考資料:
1. pdf

暫存器


main.s

  .equ IODIR, 0xe0028008
  .equ IOCLR, 0xe002800c
  .equ IOSET, 0xe0028004

  .text
  .align 2
  .global _start
_start:    b reset
_undef:    b .
_swi:      b .
_pabort:   b .
_dabort:   b .
_reserved: b .
_irq:      b .
_fiq:      b .
 
reset:
  ldr r0, =IODIR
  ldr r1, =(1 << 22)
  str r1, [r0]
loop:
  ldr r0, =IOCLR
  ldr r1, =(1 << 22)
  str r1, [r0]
  ldr r4, =50000
1:
  nop
  subs r4, r4, #1
  bne 1b
  ldr r0, =IOSET
  ldr r1, =(1 << 22)
  str r1, [r0]
  ldr r4, =50000
1:
  nop
  subs r4, r4, #1
  bne 1b
  b loop
  .end

main.ld

MEMORY {
  flash : ORIGIN = 0, LENGTH = 32K
  ram : ORIGIN = 0x40000000, LENGTH = 8K
}

__stack_end__ = 0x40000000 + 8K - 4;
SECTIONS {
  . = 0;
  startup : { *(.startup)} >flash
  prog : {
    *(.text)
    *(.rodata)
    *(.rodata*)
    *(.glue_7)
    *(.glue_7t)
  } >flash
  __end_of_text__ = .;
  .data : {
    __data_beg__ = .;
    __data_beg_src__ = __end_of_text__;
    *(.data)
    __data_end__ = .;
  } >ram AT>flash
  .bss : {
    __bss_beg__ = .;
    *(.bss)
  } >ram
  . = ALIGN(32 / 8);
}
. = ALIGN(32 / 8);
_end = .;
_bss_end__ = . ; __bss_end__ = . ; __end__ = . ;

Makefile

all:
	arm-none-eabi-as -ggdb -mcpu=arm7 -o main.o main.s
	arm-none-eabi-ld -T main.ld -o main.elf main.o
	arm-none-eabi-objcopy -O ihex main.elf main.ihx
	packihx main.ihx > main.hex

flash:
	sudo lpc21isp -wipe -control  -verify -debug2 ./main.hex /dev/ttyUSB0 9600 12000

clean:
	rm -rf main.ihx main.hex main.o main.elf

編譯、燒錄

$ make
  arm-none-eabi-as -ggdb -mcpu=arm7 -o main.o main.s
  arm-none-eabi-ld -T main.ld -o main.elf main.o
  arm-none-eabi-objcopy -O ihex main.elf main.ihx
  packihx main.ihx > main.hex
  packihx: read 10 lines, wrote 10: OK.

$ make flash
  sudo lpc21isp -wipe -control  -verify -debug2 ./main.hex /dev/ttyUSB0 9600 12000
  Verify after copy RAM to Flash.
  lpc21isp version 1.97
  File ./main.hex:
    loaded...
    converted to binary format...
    image size : 136
  Image size : 136
  Synchronizing (ESC to abort). OK
  Read bootcode version: 21
  2
  Read part ID: LPC2103, 32 kiB FLASH / 8 kiB SRAM (0x0004FF11)
  Will start programming at Sector 1 if possible, and conclude with Sector 0 to ensure that checksum is written last.
  Wiping Device. OK
  Sector 0: ......
  Download Finished and Verified correct... taking 1 seconds
  Now launching the brand new code

完成


返回上一頁