|
以下是SDRAM的初始化代码,配置如下:
1、2X16bit的SDRAM 组成32BIT的SDRAM使用
2、外部接800X480TFT
3、CPU 120MHZ, SDRAM 60MHZ
现象:
目前LCD可以正常使用,但是当我对SDRAM进行测试时,也就是写入全部数据,再读出来!
但是有时发现读出的数据和写入不同,且是随机的位置。
当我把LCD模块关闭后,再测试就无问题?请各位帮忙分析下?
谢谢!
#define SDRAM_BASE 0xA0000000
#define EMC_NS2CLK(ns, nsPerClk) ((ns + nsPerClk - 1) / nsPerClk)
#define SYSTEM_CORE_CLOCK 120000000
#define delayMs(temp, ms) \
do { \
*((volatile uint32_t *)0xE000E014) = SYSTEM_CORE_CLOCK / 100 - 1;\
*((volatile uint32_t *)0xE000E010) = (0x01 << 2) | 0x01; \
temp = ms / 10; \
do { \
if (*((volatile uint32_t *)0xE000E010) & (0x01 << 16)) { \
temp--; \
} \
} while (temp); \
*((volatile uint32_t *)0xE000E010) = 0x00; \
} while(0)
/*********************************************************************//**
* @brief Initialize external SDRAM memory Micron MT48LC8M32LFB5
* 256Mbit(8M x 32)
* @param[in] None
* @return None
**********************************************************************/
void SDRAMInit( void )
{
static uint32_t i ;//@ 0x10000500;
static uint32_t wtemp ;//@ 0x10000504;
static uint32_t mhz ;//@ 0x10000508;
static uint32_t nsPerClk ;//@ 0x1000050C;
LPC_IOCON->P2_16 = 0x21;
LPC_IOCON->P2_17 = 0x21;
LPC_IOCON->P2_18 = 0x21;
LPC_IOCON->P2_20 = 0x21;
LPC_IOCON->P2_24 = 0x21;
LPC_IOCON->P2_28 = 0x21;
LPC_IOCON->P2_29 = 0x21;
LPC_IOCON->P2_30 = 0x21;
LPC_IOCON->P2_31 = 0x21;
LPC_IOCON->P3_0 = 0x21;
LPC_IOCON->P3_1 = 0x21;
LPC_IOCON->P3_2 = 0x21;
LPC_IOCON->P3_3 = 0x21;
LPC_IOCON->P3_4 = 0x21;
LPC_IOCON->P3_5 = 0x21;
LPC_IOCON->P3_6 = 0x21;
LPC_IOCON->P3_7 = 0x21;
LPC_IOCON->P3_8 = 0x21;
LPC_IOCON->P3_9 = 0x21;
LPC_IOCON->P3_10 = 0x21;
LPC_IOCON->P3_11 = 0x21;
LPC_IOCON->P3_12 = 0x21;
LPC_IOCON->P3_13 = 0x21;
LPC_IOCON->P3_14 = 0x21;
LPC_IOCON->P3_15 = 0x21;
LPC_IOCON->P3_16 = 0x21;
LPC_IOCON->P3_17 = 0x21;
LPC_IOCON->P3_18 = 0x21;
LPC_IOCON->P3_19 = 0x21;
LPC_IOCON->P3_20 = 0x21;
LPC_IOCON->P3_21 = 0x21;
LPC_IOCON->P3_22 = 0x21;
LPC_IOCON->P3_23 = 0x21;
LPC_IOCON->P3_24 = 0x21;
LPC_IOCON->P3_25 = 0x21;
LPC_IOCON->P3_26 = 0x21;
LPC_IOCON->P3_27 = 0x21;
LPC_IOCON->P3_28 = 0x21;
LPC_IOCON->P3_29 = 0x21;
LPC_IOCON->P3_30 = 0x21;
LPC_IOCON->P3_31 = 0x21;
LPC_IOCON->P4_0 = 0x21;
LPC_IOCON->P4_1 = 0x21;
LPC_IOCON->P4_2 = 0x21;
LPC_IOCON->P4_3 = 0x21;
LPC_IOCON->P4_4 = 0x21;
LPC_IOCON->P4_5 = 0x21;
LPC_IOCON->P4_6 = 0x21;
LPC_IOCON->P4_7 = 0x21;
LPC_IOCON->P4_8 = 0x21;
LPC_IOCON->P4_9 = 0x21;
LPC_IOCON->P4_10 = 0x21;
LPC_IOCON->P4_11 = 0x21;
LPC_IOCON->P4_12 = 0x21;
LPC_IOCON->P4_13 = 0x21;
LPC_IOCON->P4_14 = 0x21;
LPC_IOCON->P4_25 = 0x21;
/* Enable External Memory Controller power/clock */
LPC_SC->PCONP |= 0x00000800;
LPC_SC->EMCDLYCTL = 0x00080808;
LPC_EMC->Control = 0x00000001;
LPC_EMC->Config = 0x00000000;
mhz = SYSTEM_CORE_CLOCK / 1000000;
if (LPC_SC->EMCCLKSEL) {
mhz >>= 1;
}
nsPerClk = 1000 / mhz;
LPC_EMC->Control = 0x01;
LPC_EMC->DynamicReadConfig = 0x01;
// -------------------------------------------------------------------------
// RAS latency (active to read/write delay) (RAS): 3 CCLK cycles
// CAS latency (CAS) : 3 CCLK cycles
// -------------------------------------------------------------------------
LPC_EMC->DynamicRasCas0 = (0x03 << 8 | 0x03);
LPC_EMC->DynamicRP = EMC_NS2CLK(20, nsPerClk); /* 20ns, */
LPC_EMC->DynamicRAS = /*EMC_NS2CLK(42, nsPerClk);*/ 15; /* 42ns to 100K ns, */
LPC_EMC->DynamicSREX = 1 - 1; /* tSRE, 1clk, */
LPC_EMC->DynamicAPR = 2 - 1; /* Not found!!! Estimated as 2clk, */
LPC_EMC->DynamicDAL = EMC_NS2CLK(20, nsPerClk) + 2; /* tDAL = tRP + tDPL = 20ns + 2clk */
LPC_EMC->DynamicWR = 2 - 1; /* 2CLK, */
LPC_EMC->DynamicRC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRC=63ns(min)*/
LPC_EMC->DynamicRFC = EMC_NS2CLK(63, nsPerClk); /* H57V2562GTR-75C tRFC=tRC */
LPC_EMC->DynamicXSR = 0x0000000F; /* exit self-refresh to active, 不知道,设为最久 */
LPC_EMC->DynamicRRD = EMC_NS2CLK(63, nsPerClk); /* 3clk, tRRD=15ns(min) */
LPC_EMC->DynamicMRD = 2 - 1; /* 2clk, tMRD=2clk(min) */
LPC_EMC->DynamicReadConfig = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */
/* H57V2562GTR-75C: tCL=3CLK, tRCD=20ns(min), 3 CLK=24ns */
LPC_EMC->DynamicRasCas0 = 0x00000303;
LPC_EMC->DynamicConfig0 = 0x4480; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */
delayMs(wtemp, 100);
LPC_EMC->DynamicControl = 0x00000183; /* Issue NOP command */
delayMs(wtemp, 200); /* wait 200ms */
LPC_EMC->DynamicControl = 0x00000103; /* Issue PALL command */
LPC_EMC->DynamicRefresh = 0x00000002; /* ( n * 16 ) -> 32 clock cycles */
for(i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */
/* 64ms/8192=7.8125us, nx16x8.33ns<7.8125us, n<58.6*/
wtemp = 64000000 / (1 << 13);
wtemp -= 16;
wtemp >>= 4;
wtemp = wtemp * mhz / 1000;
LPC_EMC->DynamicRefresh = wtemp;
LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */
wtemp = *((volatile uint32_t *)(SDRAM_BASE | (0x32<<13))); /* 4 burst, 3 CAS latency */
LPC_EMC->DynamicControl = 0x00000000; /* Issue NORMAL command */
LPC_EMC->DynamicConfig0 |= 0x80000; /* enable buffer */
delayMs(wtemp, 10);
}
/*********************************************************************************
** End Of File
*********************************************************************************/
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|