初始化系统时钟
1. start.S
-
.text
-
.global _start
-
_start:
-
/*disable watchdog*/
-
ldr r0, =0x53000000
-
mov r1, #0x0
-
str r1, [r0]
-
-
#define COCKTIME 0x4C000000
-
#define MPLLCON 0x4C000004
-
#define UPLLCON 0x4C000008
-
#define CLKCON 0x4C00000C
-
#define CLKSLOW 0x4C000010
-
#define CLKDIVN 0x4C000014
-
#define CAMDIVN 0x4C000018
-
/*FCLK:HCLK:PCLK=1:4:8*/
-
ldr r0, =CLKDIVN
-
mov r1, #0x05
-
str r1, [r0]
-
-
mrc p15, 0, r0, c1, c0, 0
-
orr r0, r0, #0xc0000000
-
mcr p15, 0, r0, c1, c0,0
-
-
/*MPLL=(2*m*Fin)/(P*(1<<S)), m=(MDIV+8), p=PDIV+2 s=SDIV*/
-
ldr r0, =MPLLCON
-
ldr r1, =((0x5C<<12)|(0x01<<4)|(0x01))
-
str r1, [r0]
-
-
ldr r0, =0x10000
-
1:
-
sub r0, r0, #1
-
bne 1b
-
-
/*UPLL=(m*Fin)/(P*(1<<S)), m=(MDIV+8), p=(PDIV+2), s=SDIV*/
-
ldr r0, =UPLLCON
-
ldr r1, =((0x10<<12)|(0x01<<4)|(0x01))
-
str r1, [r0]
-
-
ldr r0, =0x10000
-
1:
-
sub r0, r0, #1
-
bne 1b
-
-
/* set up the stack */
-
ldr sp, =1024*4
-
bl main
-
-
loop:
-
b loop
2. main.c
-
#define GPBCON (*(volatile unsigned int *) 0x56000010)
-
#define GPBDAT (*(volatile unsigned int *) 0x56000014)
-
-
static inline void delay (unsigned long loops)
-
{
-
__asm__ volatile ("1:\n"
-
"subs %0, %1, #1\n"
-
"bne 1b":"=r" (loops):"0" (loops));
-
}
-
-
void main()
-
{
-
int i = 1;
-
GPBCON = 0x15400;
-
while(1)
-
{
-
GPBDAT = 0x7FF&(~i<<5);
-
i *= 2;
-
if(16==i)
-
i = 1;
-
delay(400000);
-
}
-
return ;
-
}
3. Makefile 只需要把原先的OBJS := start.o修改为OBJS := start.o main.o即可
烧到板子上之后流水灯的闪烁的速度明显变快了好多。
二、
2.1 s3c2440有两个PLL(MPLL,UPLL):MPLL用于产生FCLK HCLK PCLK,UPLL用于产生USB时钟(48Mhz)
2.2 FCLK、HCLK、PCLK的关系
FCLK 用于cpu
HCLK 用于AHB总线及其外围设备
PCLK 用于APB总线及其外围设备
2.3
CLKDIVN用于设定FCLK HCLK PCLK三者的比例关系,
当CAMDIVN=0时, CLKDIVN=0x05,则FCLK:HCLK:PCLK=1:4:8,(因为CAMDIVN默认值为0,所以此处不用设定)
即,当FCLK=400M时,HCLK=100M PCLK=50M
2.4 计算公式
Fout=(2 * m * Fin)/(p*2的s次方) m=MDIV+8,p=PDIV+2,s=SDIV
MDIV PDIV SDIV 都是通过MPLLCON设定的,Fin是tq2440的晶振频率12MHZ
例子中: MDIV=0x5C PDIV=0x01 SDIV=0x01
Fout=(2*(0x5c+8)*12MHZ)/((0x01+2)*2)=400MHZ
-
mrc p15, 0, r0, c1, c0, 0
-
orr r0, r0, #0xc0000000
-
mcr p15, 0, r0, c1, c0,0
手册上说"If HDIVN is not 0, the CPU bus mode has to be changed from the fast bus mode to the asynchronous bus mode using following instructions",当HDIVN (CLKDIVN的D1-D2)不为零时,需要通过这三条指令将cpu从fast bus mode 切换到asynchronous mode。
注意:如果在编译时出现
warning: function declaration isn't a prototype时,例如 void main(),修改成void main(void) 即可。
阅读(507) | 评论(0) | 转发(0) |