ARM 베어 메탈 프로그램 - GPIO 실험 LED(1)
4385 단어 arm-누드 실험
코드 목록은 다음과 같다.Makefile
CROSS = arm-linux-
CFLAGS = -nostdlib -c -Wall -g
TARGET = leds
OBJS := start.o $(TARGET).o
LDFILE = $(TARGET).lds
$(TARGET).bin:$(OBJS)
$(CROSS)ld -T$(LDFILE) -o $(TARGET)_elf $^
$(CROSS)objcopy -O binary -S $(TARGET)_elf $@
$(CROSS)objdump -D -m arm $(TARGET)_elf > $(TARGET).dis
%.o: %.c
$(CROSS)gcc $(CFLAGS) -o $@ $<
%.o: %.s
$(CROSS)gcc $(CFLAGS) -o $@ $<
clean:
rm -f *.bin *elf *.dis *.o
2 . start.s
.text
.global _start
_start:
@ disable watchdog
ldr r3, =0x53000000
mov r4, #0x0
str r4, [r3]
@ setup stack
ldr sp, =1024*4
bl _main
halt_loop:
b halt_loop
3 . leds.s
.equ GDBCON, 0x56000010
.equ GDBDAT, 0x56000014
.equ LOOPTIME, 0x00010000
.global _main
_main:
ldr r0, =GDBCON @ set GDB5-8 output
mov r1, #(0x55<<10)
str r1, [r0]
mov r1, #0
ldr r0, =GDBDAT
loop:
mvn r2, r1, lsl #5
str r2, [r0]
add r1, r1, #1
cmp r1, #16
moveq r1, #0
bl delay
b loop
delay:
ldr r3, =LOOPTIME
delay1:
sub r3, r3, #1
cmp r3, #0x0
bne delay1
mov pc,lr
.end
4 . leds.lds
SECTIONS{
. = 0x00000000;
.text : {
*(.text);
*(.rodata);
}
.data ALIGN(4): {
*(.data);
}
.bss ALIGN(4): {
*(.bss);
}
}