@ File:head.S
@ 功用:设置SDRAM,将程序仿制到SDRAM,然后跳到SDRAM持续履行
@*************************************************************************
.equ MEM_CTL_BASE, 0x48000000
.equ SDRAM_BASE, 0x30000000
.text
.global _start
_start:
bl disable_watch_dog @ 封闭WATCHDOG,不然CPU会不断重启
bl memsetup @ 设置存储控制器
bl copy_steppingstone_to_sdram @ 仿制代码到SDRAM中
ldr pc, =on_sdram @ 跳到SDRAM中持续履行
on_sdram:
ldr sp, =0x34000000 @ 设置仓库
bl main
halt_loop:
b halt_loop
disable_watch_dog:
@ 往WATCHDOG寄存器写0即可
mov r1, #0x53000000
mov r2, #0x0
str r2, [r1]
mov pc, lr @ 回来
copy_steppingstone_to_sdram:
@ 将Steppingstone的4K数据悉数仿制到SDRAM中去
@ Steppingstone开端地址为0x00000000,SDRAM中开端地址为0x30000000
mov r1, #0
ldr r2, =SDRAM_BASE
mov r3, #4*1024
1:
ldr r4, [r1],#4 @ 从Steppingstone读取4字节的数据,并让源地址加4
str r4, [r2],#4 @ 将此4字节的数据仿制到SDRAM中,并让目地地址加4
cmp r1, r3 @ 判别是否完结:源地址等于Steppingstone的未地址?
bne 1b @ 若没有仿制完,持续
mov pc, lr @ 回来
memsetup:
@ 设置存储控制器以便运用SDRAM等外设
mov r1, #MEM_CTL_BASE @ 存储控制器的13个寄存器的开端地址
adrl r2, mem_cfg_val @ 这13个值的开端存储地址
add r3, r1, #52 @ 13*4 = 54
1:
ldr r4, [r2], #4 @ 读取设置值,并让r2加4
str r4, [r1], #4 @ 将此值写入寄存器,并让r1加4
cmp r1, r3 @ 判别是否设置完一切13个寄存器
bne 1b @ 若没有写成,持续
mov pc, lr @ 回来
.align 4
mem_cfg_val:
@ 存储控制器13个寄存器的设置值
.long 0x22011110 @ BWSCON
.long 0x00000700 @ BANKCON0
.long 0x00000700 @ BANKCON1
.long 0x00000700 @ BANKCON2
.long 0x00000700 @ BANKCON3
.long 0x00000700 @ BANKCON4
.long 0x00000700 @ BANKCON5
.long 0x00018005 @ BANKCON6
.long 0x00018005 @ BANKCON7
.long 0x008C07A3 @ REFRESH
.long 0x000000B1 @ BANKSIZE
.long 0x00000030 @ MRSRB6
.long 0x00000030 @ MRSRB7
#defineGPBCON(*(volatile unsigned long *)0x56000010)
#defineGPBDAT(*(volatile unsigned long *)0x56000014)
#defineGPB5_out(1<<(5*2))
#defineGPB6_out(1<<(6*2))
#defineGPB7_out(1<<(7*2))
#defineGPB8_out(1<<(8*2))
void wait(unsigned long dly)
{
for(; dly > 0; dly–);
}
int main(void)
{
unsigned long i = 0;
GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out;// 将LED1-4对应的GPB5/6/7/8四个引脚设为输出
while(1){
wait(30000);
GPBDAT = (~(i<<5)); // 依据i的值,点亮LED1-4
if(++i == 16)
i = 0;
}
return 0;
}