本文纯属原创,为arm子程序模块,包含了汇编和C语言两种写法,后续将陆续完善。
ON1、关闭WATCHDOG,否则CPU会不断重启:
汇编:
disable_watch_dog:
@往WATCHDOG寄存器写0
mov r1,#0x53000000
mov r2,#0x0
str r2,[r1]
mov pc,lr //返回
C语言:
#define WTCON (*(volatile unsigned long *)0x53000000)
void disable_watch_dog(void)
{
WTCON=0;
}
ON2、存储控制器的使用
汇编:
.equ MEM_CTL_BASE,0x48000000
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
C语言:
#define MEM_CTL_BASE 0X48000000
//设置存储控制器以使用SDRAM
void memsetup(void)
{
unsigned long const mem_cfg_val[]={ 0x22011110, //BWSCON
0x00000700, //BANKCON0
0x00000700, //BANKCON1
0x00000700, //BANKCON2
0x00000700, //BANKCON3
0x00000700, //BANKCON4
0x00000700, //BANKCON5
0x00018005, //BANKCON6
0x00018005, //BANKCON7
0x008C07A3, //REFRESH
0x000000B1, //BANKSIZE
0x00000030, //MRSRB6
0x00000030, //MRSRB7
};
int i = 0;
volatile unsigned long *p = (volatile unsigned long *)MEM_CTL_BASE;
for(; i < 13; i++)
p[i] = mem_cfg_val[i];
}
分享:
上一篇:ARM笔记: 裸机实验之存储控制器
下一篇:stm32学习之复位和时钟
推荐阅读最新更新时间:2024-03-16 15:44