开发板有两个可控制的LED灯:分别接到引脚:KP_COL0和VDD50_EN
由原理图可知这两个引脚分别输出高电平之后LED就会亮。
KP_COL0就是GPL2_0
VDD50_EN就是GPK1_1
配置GPX_CON对应位为输出功能,设置GPX_DAT相应管脚输出为1,就可以点亮LED灯了。
程序实现如下:
start.S:
.global _start
#include "s3c4412_gpio.h"
.word 0x2000
.word 0x0
.word 0x0
.word 0x0
_start:
ldr r0, =0x1002330C
ldr r1, [r0]
orr r1, r1, #0x300
str r1, [r0]
ldr r0, =0x11000C08
ldr r1, =0x0
str r1, [r0]
ldr r0, =GPL2CON
mov r1, #(0x01 << 0)
str r1, [r0]
ldr r0, =GPK1CON
mov r1, #(0x01 << 4)
str r1, [r0]
ldr r0, =GPK1DAT
mov r1, #0x2
str r1, [r0]
ldr r0, =GPL2DAT
mov r1, #0x1
str r1, [r0]
halt:
b halt
s3c4412_gpio.h:
#ifndef S3C4412_GPIO_H
#define S3C4412_GPIO_H
#define GPX1CON (0x11000000 + 0x0C20)
#define GPX1DAT (0x11000000 + 0x0C24)
#define GPX1PUD (0x11000000 + 0x0C28)
#define GPX1DRV (0x11000000 + 0x0C2C)
#define GPK1CON (0x11000000 + 0x0060)
#define GPK1DAT (0x11000000 + 0x0064)
#define GPK1PUD (0x11000000 + 0x0068)
#define GPK1DRV (0x11000000 + 0x006C)
#define GPL2CON (0x11000000 + 0x0100)
#define GPL2DAT (0x11000000 + 0x0104)
#define GPL2PUD (0x11000000 + 0x0108)
#define GPL2DRV (0x11000000 + 0x010C)
#endif
link.lds:
SECTIONS {
. = 0x0;
.text : {
*(.text)
}
.rodata ALIGN(4) : {
*(.rodata*)
}
.data ALIGN(4) : {
*(.data*)
}
.bss ALIGN(4) : {
*(.bss)
*(COMMON)
}
}
Makefile:
CFLAGS := -nostdlib -O0
TARGET := led.bin
$(TARGET) : start.o
$(CROSS_COMPILE)ld -T link.lds -o led.elf $^
$(CROSS_COMPILE)objcopy -O binary led.elf $@
$(CROSS_COMPILE)objdump -D led.elf > led.dis
%.o : %.S
$(CROSS_COMPILE)gcc -o $@ $< -c
%.o : %.c
$(CROSS_COMPILE)gcc $(CFLAGS) -o $@ $< -c
.PHONY:clean flash
clean:
rm -rf *.o *.elf *.bin *.dis mk4412
flash:
gcc ../tools/mk4412.c -static -o mk4412
./mk4412 $(TARGET)
@if [ -b /dev/sdb ]; then \
sudo mkfs.vfat -F 32 -I /dev/sdb; \
sudo dd if=/dev/zero of=/dev/sdb bs=512 seek=1 iflag=dsync oflag=dsync count=2048; \
sudo dd if=./$(TARGET) of=/dev/sdb bs=512 seek=1 iflag=dsync oflag=dsync; \
fi
完整的代码详见我的GitHub地址:https://github.com/675816156/iTop4412_bare_machine/tree/master/1_led_s
因为这个裸机是s3c4412datasheet中所描述的bl1, 所以编译出的led.bin头16个字节需要处理下,才能正常运行
mk4412工具源码详见:mk4412.c
执行如下:mk4412 led.bin
编译好的镜像制作工具mk4412从这里下载:http://download.csdn.net/detail/cj675816156/9101607
然后烧写处理好的led.bin到sd卡里头:make flash
最后就能看到开发板上led2和led3被点亮了。