程序从JZ2440中改的
用的到文件如下:
crt0.S,leds.bin,leds.c,leds.lds,Makefile
crt0.S
@******************************************************************************
@ File:crt0.S
@ 功能:通过它转入C程序
@******************************************************************************
.text
.global _start
_start:
ldr r0, =0x53000000 @ WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启
ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
@ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
bl main @ 调用C程序中的main函数
halt_loop:
b halt_loop
leds.c
//FL2440
#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)
#define GPB5_out (1<<(5*2))//对应原理图的4个led
#define GPB6_out (1<<(6*2))
#define GPB8_out (1<<(8*2))
#define GPB10_out (1<<(10*2))
void wait(volatile unsigned long dly)
{
for(; dly > 0; dly--);
}
int main(void)
{
unsigned long i=0;
// 0010 0000
// 0100 0000
// 1 0000 0000
// 100 0000 0000
unsigned long arr[4]={0x20,0x40,0x100,0x400};
GPBCON = GPB5_out|GPB6_out|GPB8_out|GPB10_out; // 将LED0-3对应的GPB 5/6/8/10 output
while(1)
{
for(i=0;i<4;i++)
{
//GPBDAT=0x7ff;//全灭
//wait(90000);
GPBDAT=~arr[i]; //要注意是高电平灭
wait(90000);
}
}
return 0;
}
leds.lds
SECTIONS {
. = 0x00;
.text : { *(.text) }
.rodata ALIGN(4) : {*(.rodata)}
.data ALIGN(4) : { *(.data) }
.bss ALIGN(4) : { *(.bss) *(COMMON) }
}
Makefile
CFLAGS := -Wall -Wstrict-prototypes -g -fomit-frame-pointer -ffreestanding
all : crt0.S leds.c
arm-linux-gcc $(CFLAGS) -c -o crt0.o crt0.S
arm-linux-gcc $(CFLAGS) -c -o leds.o leds.c
arm-linux-ld -Tleds.lds crt0.o leds.o -o leds_elf
arm-linux-objcopy -O binary -S leds_elf leds.bin
arm-linux-objdump -D -m arm leds_elf > leds.dis
clean:
rm -f leds.dis leds.bin leds_elf *.o
说明:Makefile编译使用警告,优化级别等