stud1 发表于 2011-12-14 10:49:11

LPC2478在启动代码里设置SDRAM,就不可以吗?

我有1个板子,硬件已经调试好,不用怀疑,用的Lpc2478主芯片,外挂2MB的SDRAM,options里勾上RAM1(ADDR=0xA0000000,SIZE=0x200000),在启动代码不初始化,在系统启动后开始初始化SDRAM接口,可以测试SDRAM通过。但是把初始化内容放在启动代码里设置就不行,请教如何设置?
#include <LPC24xx.H>

#define INT32U unsigned long
#define uint8_t unsigned char


// 硬件端口定义:
// BEEP: P0.0
#define BEEP                (1<<0)
#define BeepOFF()        FIO0SET |= BEEP
#define BeepON()         FIO0CLR |= BEEP

void delay_Ns (int idly)
{
    int i;
   
    for(; idly > 0; idly--) {
      for (i = 0; i < 5000; i++);
    }
}

voidsysDelayNS(INT32UuiDly)
{
    INT32Ui;
    for(; uiDly > 0; uiDly--){
      for(i = 0; i < 5000; i++);
    }
}
voidSDRAMInit( void )
{
    volatile INT32U i, dummy ;

    LCD_CTRL = 0x00;
        sysDelayNS(10);

        PCONP |= 1 << 11;
   
    /*
    * 使能SDRAM总线连接
    */
#if 0
    PINSEL4   |= 0x50000000;//SRAM(CS2,CS3)
    PINSEL5   |= 0x05010555;//SDRAM(CS0,CS1)
    PINSEL6   |= 0x55555555;//D0~D15
    PINSEL8   |= 0x15555555;//A0~A15
    PINSEL9   |= 0x50550000;//A16~A23 , /OE , /WE , BLS0 , BLS1 , /CS0 , /CS1;
    EMC_CTRL = 0x00000001;                                                    /* Disable Address mirror       */
#else
        //原程序
    PINSEL4   |= 0x50000000;//SRAM(CS2,CS3)
    PINSEL5   |= 0x05050555;//SDRAM(CS0,CS1)
    PINSEL6   |= 0x55555555;//D0~D15
    PINSEL8   |= 0x55555555;//A0~A15
    PINSEL9   |= 0x50555555;//A16~A23 , /OE , /WE , BLS0 , BLS1 , /CS0 , /CS1;
    EMC_CTRL = 0x00000001;                                                    /* Disable Address mirror       */

#endif
    /*
   * 设置SDRAM访问时序.
   */
    EMC_DYN_RP      = 1;
    EMC_DYN_RAS       = 2;
    EMC_DYN_SREX      = 1;
    EMC_DYN_APR       = 1;
    EMC_DYN_DAL       = 5;
    EMC_DYN_WR      = 2;
    EMC_DYN_RC      = 3;
    EMC_DYN_RFC       = 3;
    EMC_DYN_XSR       = 5;
    EMC_DYN_RRD       = 1;
    EMC_DYN_MRD       = 2;

    EMC_DYN_RD_CFG = 1;                                           /*Command delayed strategy    */

    /*
   * Default setting,
   * RAS latency 3 CCLKs,
   * CAS latenty 3 CCLKs.
   */
    EMC_DYN_RASCAS0   = 0x00000303;

    /*
   * 64MB, 1Mx16,
   * 4 banks, row=12,
   * column=8
   */
    EMC_DYN_CFG0   = 0x00000280;
    for (i = 0; i < 0x80; i++) {
    }

    /*
   * Mem clock enable,
   * CLKOUT runs, send command:
   * NOP
   */
    EMC_DYN_CTRL   = 0x00000183;
    for (i = 0; i < 0x80; i++) {
    }

    /*
   * Send command:
   * PRECHARGE-ALL,
   * shortest possible refresh period
   */
    EMC_DYN_CTRL   = 0x00000103;
    for (i = 0; i < 0x80; i++) {
    }


    /*
   * set 32 CCLKs
   * between SDRAM refresh
   * cycles
   */
    EMC_DYN_RFSH   = 0x00000004;
    for (i = 0; i < 0x80; i++) {                                        /*wait 128 AHB clock cycles   */
    }

    /*
   * set 45 x 16CCLKs=720CCLK=15us
   * between SDRAM refresh
   * cycles
   */
    EMC_DYN_RFSH   = 45;

    /*
   * To set mode register in SDRAM,
   * enter mode by issueMODE command, after finishing,
   * bailout and back to NORMAL mode.
   * Mem clock enable, CLKOUT runs, send command: MODE
   */
    EMC_DYN_CTRL   = 0x00000083;
    dummy               = *((volatile int *)(0xA0019800));
    EMC_DYN_CTRL   = 0x00000000;                                 /*Send command: NORMAL      */
    EMC_DYN_CFG0   = 0x00080280;                                 /*Enable buffer               */
    for (i = 0; i < 0x80; i++) {
    }

}

#define TEST_ADDR         0xA011FF00                /* 测试起始地址                                */
#define SIZE                100                                /* 测试100个SDRAM空间                */

int main(void)
{
        INT32U i;
        uint8_t * p_uint8_t = (uint8_t *)TEST_ADDR;

        PINSEL0= 0x00;
        SCS |= 0x01;
        FIO0DIR |= BEEP;
        BeepON();
        delay_Ns(100);
        BeepOFF();

        SDRAMInit();                   // 启动代码里的设置和这里是一样的值。

// 测试SDRAM连接是否正常
    p_uint8_t = (uint8_t *)TEST_ADDR;
        for (i=0;i < SIZE;i++)
                *p_uint8_t++ = (uint8_t)i;

    p_uint8_t = (uint8_t *)TEST_ADDR;
    for(i=0; i<SIZE; i++)
    {
      if( *p_uint8_t != (uint8_t)i )
      {
            while(1);
      }
      p_uint8_t++;
    }
// end

        while(1) {
                BeepON();
                delay_Ns(500);
                BeepOFF();
                delay_Ns(500);
                }

}

yankaiyutong 发表于 2011-12-23 21:15:43

在SDRAM中运行是需要2段独立代码的,不知道的初始化运行,又是开始运行的指的是那段代码?

vanwang 发表于 2011-12-24 17:11:16

围观中,我来学习的

jyg886688666 发表于 2011-12-25 23:20:31

没仔细看楼主的程序,不过楼主可以看下,在你初始化C语言前,是不是已经建立好了RW段和ZI段,不然的话,没有搭建好C环境,只能用汇编来实现初始化
页: [1]
查看完整版本: LPC2478在启动代码里设置SDRAM,就不可以吗?