我以前的NXP2478外接了一片4*16Mbit的SDRAM,当时主要的设置如下:
EMC_CTRL = 0x00000001; /* Disable Address mirror */
PCONP |= 0x00000800; /* 打开 EMC PCLK */
PINSEL4 = 0x50000000;
PINSEL5 = 0x55050555;
PINSEL6 = 0x55555555;
PINSEL8 = 0x55555555;
PINSEL9 = 0x50555555;
EMC_DYN_RP = 2; /* command period: 3(n+1) clock cycles *///trp
EMC_DYN_RAS = 3; /* RAS command period: 4(n+1) clock cycles *///tras
EMC_DYN_SREX = 7; /* Self-refresh period: 8(n+1) clock cycles *///tsrex、txsr
EMC_DYN_APR = 2; /* Data out to active: 3(n+1) clock cycles *///tapr
EMC_DYN_DAL = 5; /* Data in to active: 5(n+1) clock cycles *///tdal、tapw
EMC_DYN_WR = 1; /* Write recovery: 2(n+1) clock cycles *///twr、tdpl、trwl、trdl
EMC_DYN_RC = 5; /* Active to Active cmd: 6(n+1) clock cycles *///trc
EMC_DYN_RFC = 5; /* Auto-refresh: 6(n+1) clock cycles *///trfc
EMC_DYN_XSR = 7; /* Exit self-refresh: 8(n+1) clock cycles *///txsr
EMC_DYN_RRD = 1; /* Active bank A->B: 2(n+1) clock cycles *///trrd
EMC_DYN_MRD = 2; /* Load Mode to Active cmd: 3(n+1) clock cycles *///tmrd、trsa
EMC_DYN_RD_CFG = 1; /* Command delayed strategy */
/* 默认设置 , RAS latency 3 CCLKs, CAS latenty 3 CCLKs. */
EMC_DYN_RASCAS0 = 0x00000303;
/* 256MB, 16Mx16, 4 banks, row=13, column=9 */
//0000 0000 0000 0000 0000 0110 1000 0000
EMC_DYN_CFG0 = 0x00000280;
delayMs(100);
/* Mem clock enable, CLKOUT runs, send command: NOP */
EMC_DYN_CTRL = 0x00000183;
delayMs(200);
/* 发送指令 : PRECHARGE-ALL, shortest possible refresh period */
EMC_DYN_CTRL = 0x00000103;
/* set 32 CCLKs between SDRAM refresh cycles */
EMC_DYN_RFSH = 0x00000002;
for(i = 0; i < 0x40; i++); /* wait 128 AHB clock cycles */
/* set 28 x 16CCLKs=448CCLK=7us between SDRAM refresh cycles */
EMC_DYN_RFSH = 28;
/* To set mode register in SDRAM, enter mode by issue
MODE command, after finishing, bailout and back to NORMAL mode. */
/* 使能MEM时钟, CLKOUT runs, send command: MODE */
EMC_DYN_CTRL = 0x00000083;
/* 设置SDRAM的模式寄存器 */
/* Mode regitster table for Micron's MT48LCxx */
/* bit 9: Programmed burst length(0)
bit 8~7: Normal mode(0)
bit 6~4: CAS latency 3
bit 3: Sequential(0)
bit 2~0: Burst length is 8
row position is 12 */
dummy = *((volatile INT32U *)(SDRAM_BASE | (0x33 << 11)));
//00110011b<<12 == 0011 0011 0000 0000 0000b
//1010 0000 0000 0011 0011 0000 0000 0000b
//A14(BA1) A13(BA0) A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
//13行,9列,4块
EMC_DYN_CTRL = 0x00000000; /* 发送指令 : NORMAL */
EMC_DYN_CFG0 |= 0x00080000; /* 使能Buffer */
能够正常工作,读写数据都正确,后来需要扩大数据宽度,我就扩了两片SDRAM,都是4*16Mbit。如何设置
EMC_DYN_CFG0寄存器和dummy = *((volatile INT32U *)(SDRAM_BASE | (0x33 << 11)));?个人认为这两处(上面标了红色)需要修改,其他的地方都不需要修改。我设置过EMC_DYN_CFG0为16 BIT 4M*16BIT,也是设置过32BIT 4M*32BIT,也试过dummy = *((volatile INT32U *)(SDRAM_BASE | (0x33 << 12)))和dummy = *((volatile INT32U *)(SDRAM_BASE | (0x33 << 10)));都不行,不知道该怎么设置了,请高手指点?
|