分类: 嵌入式
2011-04-09 11:29:10
今天继续调试mx51板子,观察得到片内rom代码执行时未初始化内存sdram模块,故我在jlink里面初始化sdram模块,具体实现是。
根据data sheet给出的实例代码:
setmem ESDCTL0 = 0x83220000 // ESDCTL0: Enable controller
// Init DRAM on CS0
setmem ESDSCR = 0x04008008 // ESDSCR: Precharge command
setmem ESDSCR= 0x00008010 // ESDSCR: Refresh command
setmem ESDSCR= 0x00008010 // ESDSCR: Refresh command
setmem ESDSCR= 0x00338018 // ESDSCR: LMR with CAS=3 and BL=3 (Burst Length = 8)
setmem ESDSCR= 0x0020801a // ESDSCR: EMR with half Drive strength
setmem ESDCTL0 = 0xC3220000 // ESDCTL0: 14 ROW, 10 COL, 32Bit, SREF=8
// ESDCFG0: tRFC:22clks, tXSR:28clks, tXP:2clks, tWTR:2clk, tRP:3clks, tMRD:2clks
// tRAS:8clks, tRRD:2clks, tWR:3clks, tRCD:3clks, tRC:11clks
setmem ESDCFG0 = 0xC33574AA
setmem ESDMISC = 0x000a1700 // ESDMISC: AP=10, Bank interleaving on, MIF3 en, RALAT=2
setmem ESDCTL1 = 0x83220000 // ESDCTL1: Enable controller
//// Init DRAM on CS1
setmem ESDSCR = 0x0400800c // ESDSCR: Precharge command
setmem ESDSCR= 0x00008014 // ESDSCR: Refresh command
setmem ESDSCR = 0x00008014 // ESDSCR: Refresh command
setmem ESDSCR = 0x0033801c // ESDSCR: LMR with CAS=3 and BL=3 (Burst Length = 8)
setmem ESDSCR = 0x0020801e // ESDSCR: EMR with half Drive strength
setmem ESDCTL1= 0xC3220000 // ESDCTL1: 14 ROW, 10 COL, 32Bit, SREF=8
//// ESDCFG1: tRFC:21clks, tXSR:28clks, tXP:2clks, tWTR:2clk, tRP:3clks, tMRD:2clks
//// tRAS:8clks, tRRD:2clks, tWR:3clks, tRCD:3clks, tRC:11clks
setmem ESDCFG1 = 0xC33574AA
setmem ESDSCR = 0x00000000 // ESDSCR - clear "configuration request" bit
在jlink里面实现上面的操作命令如下:
w4 0x83fd9000,0x83220000
w4 0x83fd9014,0x04008008
w4 0x83fd9014,0x00008010
w4 0x83fd9014,0x00008010
w4 0x83fd9014,0x00338018
w4 0x83fd9014,0x0020801a
w4 0x83fd9000,0xc3230000
w4 0x83fd9004,0xc33574aa
w4 0x83fd9010,0x000a1700
w4 0x83fd9014,0x0
在linux下的汇编代码为:
#sdram_init.S
.global _start
_start:
ldr r0,=0x83fd9000 //ESDCTL0: Enable controller
ldr r1,=0x83220000
str r0,[r1]
ldr r0,=0x83fd9014 //ESDSCR: Precharge command
ldr r1,=0x04008008
str r0,[r1]
ldr r0,=0x83fd9014 //ESDSCR: Refresh command
ldr r1,=0x00008010
str r0,[r1]
ldr r0,=0x83fd9014 // ESDSCR: Refresh command
ldr r1,=0x00008010
str r0,[r1]
ldr r0,=0x83fd9014 //ESDSCR: LMR with CAS=3 and BL=3 (Burst Length = 8)
ldr r1,=0x00338018
str r0,[r1]
ldr r0,=0x83fd9014 //ESDSCR: EMR with half Drive strength
ldr r1,=0x0020801a
str r0,[r1]
ldr r0,=0x83fd9000 // ESDCTL0: 14 ROW, 10 COL, 32Bit, SREF=8 ESDCFG0: tRFC:22clks, tXSR:28clks, tXP:2clks, tWTR:2clk, tRP:3clks, tMRD:2clks tRAS:8clks, tRRD:2clks, tWR:3clks, tRCD:3clks, tRC:11clks
ldr r1,=0xc3230000
str r0,[r1]
ldr r0,=0x83fd9004
ldr r1,=0xc33574aa
str r0,[r1]
ldr r0,=0x83fd9010 // ESDMISC: AP=10, Bank interleaving on, MIF3 en, RALAT=2
ldr r1,=0x000a1700
str r0,[r1]
ldr r0,=0x83fd9014
ldr r1,=0x0
str r0,[r1]
编译成boot.bin文件,命令:
arm-linux-gcc -c sdram_init.S
arm-linux-ld -Ttext 0x90000000 sdram_init.o -Map boot.map -o boot.elf
arm-linux-objcopy -O binary boot.elf boot.bin
此后,sdram可以读写了。然后通过loadbin命令加载可执行的bin文件到sdram空间执行即可:loadbin u-boot.bin,0x90000000(sdram的起始地址是0x90000000),然后用g命令跳到地址处执行。
下面我要观察串口是否初始化,是否有数据输出,继续看data sheet串口uart部分,写一段小代码,测试吧。。。。。