ARM系统时钟初始化

Posted 三石居士

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ARM系统时钟初始化相关的知识,希望对你有一定的参考价值。

2440时钟体系,12MHz的晶振

 

6410时钟体系,12MHz的晶振

 

210时钟体系,24MHz晶振

 

 

时钟初始化:1、设置locktime  2、设置分频系数  4、设置CPU到异步工作模式  3、设置fclk

.text
.global _start
_start:
    b reset
    ldr pc, _undefined_instruction
    ldr pc, _software_interrupt
    ldr pc, _prefetch_abort
    ldr pc, _data_abort
    ldr pc, _not_used
    ldr pc, _irq
    ldr pc, _fiq

_undefined_instruction: .word undefined_instruction
_software_interrupt:.word software_interrupt
_prefetch_abort:.word prefetch_abort
_data_abort:.word data_abort
_not_used:.word not_used
_irq:.word irq
_fiq:.word reset

undefined_instruction:
    nop
    
software_interrupt:
    nop

prefetch_abort:
    nop
    
data_abort:
    nop
    
not_used:
    nop
    
irq:
    nop
    
fiq:
    nop

reset:
    bl set_svc
    bl disable_watchdog    
    bl disable_interrupt
    bl disable_mmu
    bl clock_init
    bl light_led
        
set_svc:
    mrs r0, cpsr
    bic r0, r0, #0x1f
    orr r0, r0, #0xd3
    msr cpsr, r0
    mov pc, lr

#define pwTCON 0x53000000
disable_watchdog:
    ldr r0, =pwTCON
    mov r1, #0x0
    str r1, [r0]
    mov pc, lr

disable_interrupt:
    mvn r1, #0x0
    ldr r0, =0x4a000008
    str r1,[r0]
    mov pc, lr    

disable_mmu:
    mcr p15,0,r0,c7,c7,0
    mrc p15,0,r0,c1,c0,0
    bic r0,r0,#0x00000007
    mcr p15,0,r0,c1,c0,0
    mov pc, lr

#define GPBCON 0x56000010
#define GPBDAT 0x56000014
light_led:
    ldr r0, =GPBCON
    ldr r1, =0x15400
    str r1,[r0]
    
    ldr r0, =GPBDAT
    ldr r1, =0x6bf
    str r1, [r0]
    mov pc, lr
    
#define CLKDIVN 0x4c000014
#define MPLLCON 0x4c000008 
#define MPLL_405MHZ ((127<<12)|(2<<4)|(1<<0))
clock_init:
    ldr r0, =CLKDIVN
    mov r1, #0x5
str r1, [r0]
 
    mrc p15,0,r0,c1,c0,0
    orr r0,r0,#0xc0000000
    mcr p15,0,r0,c1,c0,0
    
    ldr r0, =MPLLCON
    ldr r1, =MPLL_405MHZ
    str r1, [r0]
 
    mov pc, lr

黄色部分就是时钟初始化,中间一段绿色的是HDIVN不是0的时候,CPU要设置成异步模式,看下面这个

但是在6410里面,设置成异步模式看这个寄存器

第7位设置是否为异步模式,所谓代码里要用bic来清除。第六位是设置是否用PLL之后产生的时钟来提供时钟源

就这图中的这个

 

代码如下

.text
.global _start
_start:
    b reset
    ldr pc, _undefined_instruction
    ldr pc, _software_interrupt
    ldr pc, _prefetch_abort
    ldr pc, _data_abort
    ldr pc, _not_used
    ldr pc, _irq
    ldr pc, _fiq

_undefined_instruction: .word undefined_instruction
_software_interrupt:.word software_interrupt
_prefetch_abort:.word prefetch_abort
_data_abort:.word data_abort
_not_used:.word not_used
_irq:.word irq
_fiq:.word reset

undefined_instruction:
    nop
    
software_interrupt:
    nop

prefetch_abort:
    nop
    
data_abort:
    nop
    
not_used:
    nop
    
irq:
    nop
    
fiq:
    nop

reset:
    bl set_svc
    bl set_peri_port
    bl disable_watchdog    
    bl disable_interrupt
    bl disable_mmu
    bl clock_init
    bl light_led
        
set_svc:
    mrs r0, cpsr
    bic r0, r0, #0x1f
    orr r0, r0, #0xd3
    msr cpsr, r0
    mov pc, lr

set_peri_port:
    ldr r0,=0x70000000
    orr r0,r0,#0x13
    mcr p15,0,r0,c15,c2,4
    mov pc,lr    

#define pwTCON 0x7e004000
disable_watchdog:
    ldr r0, =pwTCON
    mov r1, #0x0
    str r1, [r0]
    mov pc, lr

disable_interrupt:
    mvn r1, #0x0
    ldr r0, =0x71200014
    str r1,[r0]
    mov pc, lr
    
    ldr r0, =0x71300014
    str r1, [r0]
    mov pc, lr    

disable_mmu:
    mcr p15,0,r0,c7,c7,0
    mrc p15,0,r0,c1,c0,0
    bic r0,r0,#0x00000007
    mcr p15,0,r0,c1,c0,0
    mov pc, lr

#define CLK_DIV0 0X7e00f020
#define OTHERS     0x7e00f900
#define MPLLCON  0x7e00f010
#define APLLCON  0x7e00f0c0
#define CLK_SRC     0x7e00f01c
#define PLL_VAL  ((1<<31)|(266<<16)|(3<<8)|(1<<0))
#define DIV_VAL     ((0x0<<0)|(0x1<<9)|(0x1<<8)|(0x3<<12))
clock_init:
    ldr r0, =CLK_DIV0
    ldr r1, =DIV_VAL
    str r1, [r0]

    ldr r0, = OTHERS
    ldr r1, [r0]
    bic r1, r1, #0xc0
    str r1, [r0]

    ldr r0, =MPLLCON
    ldr r1, =PLL_VAL
    str r1,[r0]
    
    ldr r0, =CLK_SRC
    mov r1, #0x3
    str r1, [r0]
    mov pc, lr
    
#define GPBCON 0x7f008820
#define GPBDAT 0x7f008804
light_led:
    ldr r0, =GPBCON
    ldr r1, =0x1111
    str r1,[r0]
    
    ldr r0, =GPBDAT
    ldr r1, =0xe
    str r1, [r0]
    mov pc, lr
    

黄色部分就是设置时钟的,能看懂手册,就能写代码。

以上是关于ARM系统时钟初始化的主要内容,如果未能解决你的问题,请参考以下文章

时钟初始化

28.时钟初始化

ARM Linux系统的时钟机制

ARM芯片的时钟系统详解(S5PV210芯片)

ARM(IMX6U)裸机主频和时钟配置

S3C2440 ARM芯片时钟