@ File:head.S
@ 功能:設(shè)置SDRAM,將程序復(fù)制到SDRAM,然后跳到SDRAM繼續(xù)執(zhí)行
@*************************************************************************
本文引用地址:
http://m.butianyuan.cn/article/201611/319115.htm.equ MEM_CTL_BASE, 0x48000000
.equ SDRAM_BASE, 0x30000000
.text
.global _start
_start:
bl disable_watch_dog @ 關(guān)閉WATCHDOG,否則CPU會不斷重啟
bl memsetup @ 設(shè)置存儲控制器
bl copy_steppingstone_to_sdram @ 復(fù)制代碼到SDRAM中
ldr pc, =on_sdram @ 跳到SDRAM中繼續(xù)執(zhí)行
on_sdram:
ldr sp, =0x34000000 @ 設(shè)置堆棧
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數(shù)據(jù)全部復(fù)制到SDRAM中去
@ Steppingstone起始地址為0x00000000,SDRAM中起始地址為0x30000000
mov r1, #0
ldr r2, =SDRAM_BASE
mov r3, #4*1024
1:
ldr r4, [r1],#4 @ 從Steppingstone讀取4字節(jié)的數(shù)據(jù),并讓源地址加4
str r4, [r2],#4 @ 將此4字節(jié)的數(shù)據(jù)復(fù)制到SDRAM中,并讓目地地址加4
cmp r1, r3 @ 判斷是否完成:源地址等于Steppingstone的未地址?
bne 1b @ 若沒有復(fù)制完,繼續(xù)
mov pc, lr @ 返回
memsetup:
@ 設(shè)置存儲控制器以便使用SDRAM等外設(shè)
mov r1, #MEM_CTL_BASE @ 存儲控制器的13個(gè)寄存器的開始地址
adrl r2, mem_cfg_val @ 這13個(gè)值的起始存儲地址
add r3, r1, #52 @ 13*4 = 54
1:
ldr r4, [r2], #4 @ 讀取設(shè)置值,并讓r2加4
str r4, [r1], #4 @ 將此值寫入寄存器,并讓r1加4
cmp r1, r3 @ 判斷是否設(shè)置完所有13個(gè)寄存器
bne 1b @ 若沒有寫成,繼續(xù)
mov pc, lr @ 返回
.align 4
mem_cfg_val:
@ 存儲控制器13個(gè)寄存器的設(shè)置值
.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對應(yīng)的GPB5/6/7/8四個(gè)引腳設(shè)為輸出
while(1){
wait(30000);
GPBDAT = (~(i<<5)); // 根據(jù)i的值,點(diǎn)亮LED1-4
if(++i == 16)
i = 0;
}
return 0;
}
評論