按以往的惯例,先贴代码再总结.
start.s
- .globl _start
-
-
_start:
-
b _reset
-
ldr pc,=_undefined
-
ldr pc,=_swi
-
ldr pc,=_prefetch_abort
-
ldr pc,=_data_abort
-
nop
-
adr pc,_irq
-
ldr pc,=_fiq
-
-
_reset:
-
/* set cpu is svc mode,arm state and close the irq,fiq */
-
msr cpsr_c,#211
-
-
/* close the dog */
-
ldr r0,=0x53000000
-
mov r1,#0
-
str r1,[r0]
-
-
/* icache */
-
mrc p15,0,r2,c1,c0,0
-
orr r2,r2,#(1<<12)
-
mcr p15,0,r2,c1,c0,0
-
-
/* set the close 202MHz */
-
ldr r0,=0x4C000014 /* CLKDIVN */
-
ldr r1,=1
-
str r1,[r0]
-
ldr r0,=0x4C000004 /* SET MLL 202MHz */
-
ldr r1,=0x0A1031
-
str r1,[r0]
-
-
/* init menory controller */
-
ldr r0,=0x48000000
-
ldr r3,=0x48000034
-
adr r1,memini_data
-
i_m_c_loop:
-
ldr r2,[r1],#4
-
str r2,[r0],#4
-
cmp r0,r3
-
bne i_m_c_loop
-
-
/* init nand flash */
-
ldr r0,=0x4E000000
-
ldr r1,=0x00009852
-
str r1,[r0]
-
ldr r1,[r0] /* select chip */
-
bic r1,r1,#0x00000800
-
str r1,[r0]
-
ldr r1,=0x4E000004 /* send the reset cmd */
-
ldrb r2,=0x000000FF
-
strb r2,[r1]
-
ldr r1,=0x4E000010 /* check nand conf stat */
-
_stat_check:
-
ldr r2,[r1]
-
ands r2,r2,#1
-
beq _stat_check
-
ldr r1,[r0] /* unselect chip */
-
orr r1,r1,#0x00000800
-
str r1,[r0]
-
-
/* -------------- test key int -------------- */
-
ldr r1,=0x22222222
-
ldr r0,=0x5600008C /* EXTINT1 */
-
str r1,[r0]
-
ldr r0,=0x56000090 /* EXTINT2 */
-
str r1,[r0]
-
-
ldr r1,=0x0
-
ldr r0,=0x4A000008 /* INTMASK */
-
str r1,[r0]
-
-
ldr r0,=0x560000A4 /* EINTMASK */
-
str r1,[r0]
-
-
ldr r0,=0x56000060 /* GPGCON_EINT11_EINT19 */
-
ldr r1,=0x800080
-
str r1,[r0]
-
-
ldr r0,=0x56000040 /* GPECON_KSCAN0 */
-
ldr r1,[r0]
-
ldr r2,=0xC00000
-
bic r1,r1,r2
-
orr r1,r1,#0x400000
-
str r1,[r0]
-
ldr r0,=0x56000044 /* GPEDATA */
-
ldr r1,[r0]
-
bic r1,r1,#0x800
-
str r1,[r0]
-
-
ldr r0,=0x56000060 /* GPGCON_KSCAN1 */
-
ldr r1,[r0]
-
ldr r2,=0x3000
-
bic r1,r1,r2
-
orr r1,r1,#0x1000
-
str r1,[r0]
-
ldr r0,=0x56000064 /* GPGDATA */
-
ldr r1,[r0]
-
bic r1,r1,#0x40
-
str r1,[r0]
-
-
/* open the irq */
-
msr cpsr_c,#83
-
-
/* -----------------light flash----------------- */
-
_loop_led:
-
/* show the led light */
-
ldr r0,=0x56000050
-
ldr r1,=0x5500
-
str r1,[r0] /* SET LED GPIO IS OUTPUT */
-
ldr r0,=0x56000054 ;/* BEGIN CLOSE LED */
-
ldr r1,=0xF0
-
str r1,[r0]
-
ldr r0,=0xFFFFFF ;/* delay... */
-
bl _delay
-
ldr r0,=0x56000054 ;/* SET LIGHT LED */
-
ldr r1,=0
-
str r1,[r0]
-
ldr r0,=0xFFFFFF
-
bl _delay
-
b _loop_led
-
-
_bleak:
-
b _bleak
-
-
_delay:
-
subs r0,r0,#1
-
bne _delay
-
mov pc,lr
-
-
/* exception jump */
-
_undefined:
-
b _undefined
-
_swi:
-
b _swi
-
_prefetch_abort:
-
b _prefetch_abort
-
_data_abort:
-
b _data_abort
-
_irq:
-
ldr r0,=0x56000054 ;/* CLOSE LED */
-
ldr r1,=0xF0
-
str r1,[r0]
-
_irq_loop:
-
b _irq_loop
-
_fiq:
-
b _fiq
-
-
memini_data:
-
.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 0x008C01D1 /* REFRESH */
-
.long 0x000000B1 /* BANKSIZE */
-
.long 0x00000030 /* MRSRB6 */
-
.long 0x00000030 /* MRSRB7 */
start.lds
- ENTRY(_start)
-
SECTIONS
-
{
-
. = 0x03FC0000;
-
_code_start = .;
-
.text :
-
{
-
* (.text)
-
}
-
-
. = ALIGN(4);
-
.rodata :
-
{
-
* (.rodata)
-
}
-
-
. = ALIGN(4);
-
.data :
-
{
-
* (.data)
-
}
-
-
_bss_start = .;
-
. = ALIGN(4);
-
.bss :
-
{
-
* (.bss)
-
}
-
_bss_end = .;
-
}
Makefile
- boot.bin:start.o
-
arm-none-eabi-ld -T start.lds -o boot.elf $^
-
arm-none-eabi-objcopy -O binary boot.elf boot.bin
-
-
%.o:%.s
-
arm-none-eabi-gcc -fno-builtin -c -o $@ $<
-
-
%.o:%.c
-
arm-none-eabi-gcc -fno-builtin -c -o $@ $<
-
-
clean:
-
rm *.o boot.elf boot.bin boot.dis
上面的代码中,前面一部分都是在初始化一些外设,后面我是把GPG3和GPG11设为中断输入,再配置VIC,这里为了简单测试,我全开了.打开IRQ后便进入无限循环,让4个LED灯闪烁.我的逻辑是,进入循环后,按理说如果我按下按键,便触发IRQ中断,使PC跳到0x18处,如此一来,就算我的中断例程什么事也不做,一直无限循环,那么实现的效果是LDE灯不会再闪烁.
但一开始,我遇到的问题是,无论我怎样按按键都没反应.这话我不是随便说的,VIC的设置和按键的设置我都是细心地按着手册说明来做.各种试验,各种猜想,还是无果....但是,我锁定的问题范围就是VIC或外设引脚设置那一块,因为只要中断一触发,导致PC改变,我板子的灯就不会闪烁.后来经过一老师的帮助下,终于发现了问题所在.是按键对应的KSCAN没设置...(我设置的中断是按下降沿触发的,一上电按键电路连接的是高电平,如果一开始不把对应的KSCAN的电平拉低的话,当按键按下,GPG引脚依然是高电平.这就是为什么一直无法触发中断的原因)
我看着设备的电路图,完全看不出来.我承认自己对电子那一块几乎是零...
阅读(2118) | 评论(1) | 转发(0) |