Advertisement
Guest User

Untitled

a guest
Aug 5th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.79 KB | None | 0 0
  1. void MyEMCConfig()
  2. {
  3.     uint32_t WaitN=10000;
  4.     uint32_t *pConfig; //Register pointer
  5.     /**Enable EMC clocking*/
  6.     Chip_SCU_ClockPinMuxSet(0,SCU_MODE_FUNC0); //CLK0 pad N5 set to EMC_CLOCK 0
  7.  
  8.     //Set CREG6 control register for EMC_CLK_SEL (bit # 16) = 1 => EMC_CLK_DIV divided by 2.
  9.     LPC_CREG->CREG6 |= 1 << 16;
  10.  
  11.     //Set CCU1 branch clock configuration register. Clock divider value (bit 5:7) 0x1 (divided by 2)
  12.     pConfig=(volatile uint32_t *)0x40051478;
  13.     *pConfig|=0x23; //bit 0,1 and 5 is 1
  14.  
  15.  
  16.  
  17.     //Configure EMCCLKDELAY for frequencies above 95 Mhz
  18.     pConfig=(volatile uint32_t *)0x40086D00;    //EMC clock delay register
  19.     *pConfig |= 0x7FFF; //~ 3.5 ns delay. Page 429
  20.  
  21.  
  22.     /**Enable the EMC interface and set EMC endian-ness*/
  23.     pConfig=(volatile uint32_t *)0x40005000; //EMC Control register
  24.     *pConfig |= 0x1;                         //Enable EMC
  25.     pConfig=(volatile uint32_t *)0x40005008; //EMC Configuration register
  26.     *pConfig |= 0x0;                         //Bit 0: Endianess. 0 for little-endian (POR value)
  27.  
  28.  
  29.     /**Set a long period for the dynamic refresh rate*/
  30.     pConfig=(volatile uint32_t *)0x40005024; //Dynamic Memory Refresh Timer Register
  31.     *pConfig |= 0x7FF;                       //Long refresh period
  32.  
  33.     /**Setup address mapping*/
  34.     pConfig=(volatile uint32_t *)0x40005100;    //Dynamic Memory Configuration Register
  35.     *pConfig |= 0x6 << 7;                       //AM0 Address mapping bit 7:12
  36.     *pConfig |= 0x1 << 14;                      //AM1 Address mapping bit 14
  37.     WaitState(WaitN);                           //Empty for-loop for WaitN iterations
  38.  
  39.     //Ends up 0x4300 => RBC mapping as expected
  40.  
  41.     /**Setup RAS and CAS latencies*/
  42.     pConfig=(volatile uint32_t *)0x40005104;   //Dynamic Memory RAS & CAS Delay registers
  43.     *pConfig |= 0x3;                           //RAS 3 bit 0:1
  44.     *pConfig |= 0x3 << 8;                      //CAS 3 bit 8:9
  45.     WaitState(WaitN);                          //Empty for-loop for WaitN iterations
  46.  
  47.     /**Setup the SDRAM command and read strategy*/
  48.     pConfig=(volatile uint32_t *)0x40005028; //Dynamic Memory Read Configuration register
  49.     *pConfig |= 0x1;                         //0x1 for SDRAM operation
  50.  
  51.     /**Setup interface timing*/
  52.     LPC_EMC->DYNAMICRP      = 4;
  53.  
  54.     LPC_EMC->DYNAMICRAS     = 7;
  55.  
  56.     LPC_EMC->DYNAMICSREX    = 9;
  57.  
  58.     LPC_EMC->DYNAMICAPR     = 1;
  59.  
  60.     LPC_EMC->DYNAMICDAL     = 7;
  61.  
  62.     LPC_EMC->DYNAMICWR      = 4;
  63.  
  64.     LPC_EMC->DYNAMICRC      = 9;
  65.  
  66.     LPC_EMC->DYNAMICRFC     = 9;
  67.  
  68.     LPC_EMC->DYNAMICXSR     = 9;
  69.  
  70.     LPC_EMC->DYNAMICRRD     = 4;
  71.  
  72.     LPC_EMC->DYNAMICMRD     = 2;
  73.  
  74.  
  75.     /**Enable SDRAM clocks and clock enables and issues NOPs for 200 us*/
  76.     pConfig=(volatile uint32_t *)0x40005020; //Dynamic Control Register
  77.     *pConfig |= 0x1;                         //Clock enable
  78.     *pConfig |= 0x1 << 1;                    //Clock Control enable
  79.  
  80.     pConfig=(volatile uint32_t *)0x40005000; //EMC Control register
  81.     *pConfig |= 0x3 <<7;                     //NOP
  82.     WaitState(WaitN);
  83.  
  84.     /**Step 13: Issue precharge-all command*/
  85.     pConfig=(volatile uint32_t *)0x40005020; //Dynamic Control Register
  86.     *pConfig |= 0x1;                         //Clock enable
  87.     *pConfig |= 0x1 << 1;                    //Clock Control enable
  88.  
  89.  
  90.     pConfig=(volatile uint32_t *)0x40005024;   //Dynamic Memory Refresh Timer Register
  91.     *pConfig = 0x001;                          //Short refresh period
  92.  
  93.     pConfig=(volatile uint32_t *)0x40005020;  //EMC Control register
  94.     *pConfig |= 0x2 <<7;                      //PALL
  95.  
  96.     WaitState(WaitN);
  97.  
  98.  
  99.     /**Set normal dynamic refresh timing*/
  100.     pConfig=(volatile uint32_t *)0x40005024; //Dynamic Memory Refresh Timer Register
  101.     *pConfig |= 0x64;                        //0x64 EMC_CLK cycles => ~ 15.6 us
  102.  
  103.     /**Issue mode word*/
  104.     uint32_t ConfigRead;
  105.     //ConfigRead=*((volatile uint32_t *)(0x28000000|0x32<<12)); //DYSC0 Base Address + MODE << OFFSET
  106.     ConfigRead=*((volatile uint32_t *)(0x28032000)); //DYSC0 Base Address + MODE << OFFSET
  107.  
  108.     pConfig=(volatile uint32_t *)0x40005000; //EMC Control register
  109.     *pConfig |= 0x3 <<7;                     //NOP
  110.     WaitState(WaitN);
  111.     *pConfig |= 0x3 <<7;                     //NOP
  112.     WaitState(WaitN);
  113.  
  114.     /**Enter normal operational mode*/
  115.     pConfig=(volatile uint32_t *)0x40005020; //Dynamic Control Register
  116.     //*pConfig |= 0x00 << 7;                    //Normal mode (bit 7:8)
  117.     //*pConfig |= 0x0  << 2;                    //Self-refresh normal
  118.     *pConfig = 0x00;                            //Clear
  119.     *pConfig = 0x7;                             //CE, CS, SR
  120.  
  121.     /** Enable buffer*/
  122.     pConfig=(volatile uint32_t *)0x40005100;    //Dynamic Memory Configuration Register
  123.     *pConfig |= 0x1 << 19;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement