start.S源码:
.globl _start
_start:
// 硬件相关的设置
// Peri port setup
ldr r0, =0x70000000
orr r0, r0, #0x13
mcr p15,0,r0,c15,c2,4 @ 256M(0x70000000-0x7fffffff)
// 关看门狗
// 往WTCON(0x7E004000)写0
ldr r0, =0x7E004000
mov r1, #0
str r1, [r0]
// 设置栈
ldr sp, =8*1024
// 设置时钟
bl clock_init
bl main
halt:
b halt
===================================================================
clock.c源码:
#define APLL_LOCK (*((volatile unsigned long *)0x7E00F000))
#define MPLL_LOCK (*((volatile unsigned long *)0x7E00F004))
#define EPLL_LOCK (*((volatile unsigned long *)0x7E00F008))
#define OTHERS (*((volatile unsigned long *)0x7e00f900))
#define CLK_DIV0 (*((volatile unsigned long *)0x7E00F020))
#define ARM_RATIO 0 // ARMCLK = DOUTAPLL / (ARM_RATIO + 1)
#define HCLKX2_RATIO 4 // HCLKX2 = HCLKX2IN / (HCLKX2_RATIO + 1) = 100MHz
#define HCLK_RATIO 0 // HCLK = HCLKX2 / (HCLK_RATIO + 1) = 100MHz
#define PCLK_RATIO 1 // PCLK = HCLKX2 / (PCLK_RATIO + 1) = 50MHz
#define MPLL_RATIO 0 // DOUTMPLL = MOUTMPLL / (MPLL_RATIO + 1)
#define APLL_CON (*((volatile unsigned long *)0x7E00F00C))
#define APLL_CON_VAL ((1<<31) | (250 << 16) | (3 << 8) | (1))
#define MPLL_CON (*((volatile unsigned long *)0x7E00F010))
#define MPLL_CON_VAL ((1<<31) | (250 << 16) | (3 << 8) | (1))
#define CLK_SRC (*((volatile unsigned long *)0x7E00F01C))
//MDIV=250 对应: ARMCLK = 500MHz, HCLK = 100MHz, PCLK = 50MHZ
//MDIV=266 对应: ARMCLK = 532MHz, HCLK = 133MHz, PCLK = 66.5MHZ
void clock_init(void)
{
APLL_LOCK = 0xffff;
MPLL_LOCK = 0xffff;
EPLL_LOCK = 0xffff;
// set async mode 当CPU时钟 != HCLK时,要设为异步模式
OTHERS &= ~0xc0;
while ((OTHERS & 0xf00) != 0);
CLK_DIV0 = (ARM_RATIO) | (MPLL_RATIO << 4) | (HCLK_RATIO << 8) | (HCLKX2_RATIO << 9) | (PCLK_RATIO << 12);
APLL_CON = APLL_CON_VAL; // 500MHz
MPLL_CON = MPLL_CON_VAL; // 500MHz
CLK_SRC = 0x03;
}
====================================================================
led.c源码:
void delay()
{
volatile int i = 0x10000;
while (i--);
}
int main()
{
int i = 0;
volatile unsigned long *gpmcon = (volatile unsigned long *)0x7F008820;
volatile unsigned long *gpmdat = (volatile unsigned long *)0x7F008824;
// gpm0,1,2,3设为输出引脚
*gpmcon = 0x1111;
while (1)
{
*gpmdat = i;
i++;
if (i == 16)
i = 0;
delay();
}
return 0;
}
====================================================================
Makefile:
led.bin: start.o clock.o led.o
arm-linux-ld -Ttext 0 -o led.elf start.o clock.o led.o
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led.dis
%.o : %.S
arm-linux-gcc -o $@ $< -c
%.o : %.c
arm-linux-gcc -o $@ $< -c
clean:
rm *.o led.elf led.bin led.dis
上一篇:OK6410裸机学习之串口实验
下一篇:OK6410裸机学习之时钟设置-汇编
推荐阅读最新更新时间:2024-03-16 16:15