搜索
bottom↓
回复: 12

投降了,被LPC1788的EMC搞了快4天了,请求帮助!

[复制链接]

出0入0汤圆

发表于 2012-7-18 16:00:56 | 显示全部楼层 |阅读模式
以下是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周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2012-7-18 16:08:19 | 显示全部楼层
另外对于 LPC177x_8x的EMC有一个EMCDLYCTL寄存器,一直不太清楚!

出0入0汤圆

 楼主| 发表于 2012-7-18 18:17:55 来自手机 | 显示全部楼层
自己顶顶!

出0入0汤圆

发表于 2012-7-19 14:57:47 | 显示全部楼层
顶顶!顶个废,呵呵。

出0入0汤圆

发表于 2012-7-19 20:13:24 | 显示全部楼层
这个不是我共享那个SK1788的例程里面的吗?楼主加我啊,我给你个带注释的,我的板卡上使用的,我觉得还是蛮好用的啊,不用想那么复杂的啊~这个SK的例程我基本都没有用~有的例程好像不通过的,但是LCD的例程是通过了的,我验证过~~

出0入0汤圆

发表于 2012-8-15 09:17:53 | 显示全部楼层
我的是上了 ucgui的  但是sdram 设置到120M  就死机了  郁闷都快半个月了   还没有解决啊

出0入0汤圆

发表于 2012-8-15 09:23:51 | 显示全部楼层
如果你用的优龙的板子,恭喜楼主,你中奖了,发回去换把。

出0入0汤圆

发表于 2012-8-16 00:21:18 | 显示全部楼层
chuyong999 发表于 2012-8-15 09:17
我的是上了 ucgui的  但是sdram 设置到120M  就死机了  郁闷都快半个月了   还没有解决啊 ...

SDRAM最高只能到80MHZ。

出0入0汤圆

发表于 2012-8-16 00:37:23 | 显示全部楼层
楼主是买的开发板还是自己做的功能板,俺这几天画那个板,要用两个SDRAM 主要考虑数据线和地址线等长,保稳定,痛苦死了

出0入0汤圆

发表于 2012-9-28 01:36:31 | 显示全部楼层
路过看看!!学习

出0入0汤圆

发表于 2012-9-29 09:23:11 | 显示全部楼层
路过,看看

出0入0汤圆

发表于 2012-10-30 14:35:01 | 显示全部楼层
路过看看,学习学习。

出0入0汤圆

发表于 2012-11-1 17:10:21 | 显示全部楼层
LPC_EMC->DynamicConfig0    = 0x4480;按照你的sdram,应该是0x4680,改改试试。在1788手册的176页,可以看看。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-20 21:49

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表