lpcware

problem with EMC LPC1788

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by kickoune on Fri Dec 16 02:36:44 MST 2011
hello, i have reading lot of topic about configuration of EMC.I have change micro on my projet board ( LPC2478 --> LPC1788).
I have try to translate startup.s to C file for initialisation of EMC. i havec add EMCDELAYCTRL = 0 (no present at LPC2478)
i use AM29F320DT x2 for flash (const of picture for lcd) and MT48LC4M32B2 for SDRAM.

i think SRAM works because, variable is defined in external RAM. But external flash not works. 0xFFFF in const variable declared external ROM.


my initialisation in system_Init()



void SystemInit (void)
{
volatile uint32_t temp;
//volatile uint32_t* Pt;
uint32_t l_i;
//static uint32_t i = 0;

#if (CLOCK_SETUP)                       /* Clock Setup                        */
  LPC_SC->SCS       = SCS_Val;
  if (SCS_Val & (1 << 5)) {             /* If Main Oscillator is enabled      */
    while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready    */
  }

  LPC_SC->CLKSRCSEL = CLKSRCSEL_Val;    /* Select Clock Source for sysclk/PLL0*/

#if (PLL0_SETUP)
  LPC_SC->PLL0CFG   = PLL0CFG_Val;
  LPC_SC->PLL0CON   = 0x01;             /* PLL0 Enable                        */
  LPC_SC->PLL0FEED  = 0xAA;
  LPC_SC->PLL0FEED  = 0x55;
  while (!(LPC_SC->PLL0STAT & (1<<10)));/* Wait for PLOCK0                    */
#endif

#if (PLL1_SETUP)
  LPC_SC->PLL1CFG   = PLL1CFG_Val;
  LPC_SC->PLL1CON   = 0x01;             /* PLL1 Enable                        */
  LPC_SC->PLL1FEED  = 0xAA;
  LPC_SC->PLL1FEED  = 0x55;
  while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1                    */
#endif

  LPC_SC->CCLKSEL   = CCLKSEL_Val;      /* Setup Clock Divider                */
  LPC_SC->USBCLKSEL = USBCLKSEL_Val;    /* Setup USB Clock Divider            */
  LPC_SC->EMCCLKSEL = EMCCLKSEL_Val;    /* EMC Clock Selection                */
  LPC_SC->PCLKSEL   = PCLKSEL_Val;      /* Peripheral Clock Selection         */
  LPC_SC->PCONP     = PCONP_Val;        /* Power Control for Peripherals      */
  LPC_SC->CLKOUTCFG = CLKOUTCFG_Val;    /* Clock Output Configuration         */
#endif

#if (FLASH_SETUP == 1)                  /* Flash Accelerator Setup            */
  LPC_SC->FLASHCFG  = FLASHCFG_Val|0x03A;
#endif
#ifdef  __RAM_MODE__
  SCB->VTOR  = 0x10000000 & 0x3FFFFF80;
#else
  SCB->VTOR  = 0x00000000 & 0x3FFFFF80;
#endif

SystemCoreClockUpdate();


//PINSEL 0
LPC_IOCON->P0_00 = 0xB1;
LPC_IOCON->P0_01 = 0xB1;
LPC_IOCON->P0_02 = 0xB1;
LPC_IOCON->P0_03 = 0xB1;
LPC_IOCON->P0_04 = 0xB1;
LPC_IOCON->P0_05 = 0xB0;
LPC_IOCON->P0_06 = 0xB1;
LPC_IOCON->P0_07 = 0xA1;
LPC_IOCON->P0_08 = 0xA1;
LPC_IOCON->P0_09 = 0xA1;
LPC_IOCON->P0_10 = 0xB0;
LPC_IOCON->P0_11 = 0xB0;
LPC_IOCON->P0_12 = 0xB0;
LPC_IOCON->P0_13 = 0xB0;
LPC_IOCON->P0_14 = 0xB0;
LPC_IOCON->P0_15 = 0xB2;
LPC_IOCON->P0_16 = 0xB0;
LPC_IOCON->P0_17 = 0xB2;
LPC_IOCON->P0_18 = 0xB2;
LPC_IOCON->P0_19 = 0xB0;
LPC_IOCON->P0_20 = 0xB0;
LPC_IOCON->P0_21 = 0xB0;
LPC_IOCON->P0_22 = 0xB0;
LPC_IOCON->P0_23 = 0xB0;
LPC_IOCON->P0_24 = 0xB0;
LPC_IOCON->P0_25 = 0xB0;
LPC_IOCON->P0_26 = 0xB0;
LPC_IOCON->P0_27 = 0xB0;
LPC_IOCON->P0_28 = 0xB0;
LPC_IOCON->P0_29 = 0xB1;
LPC_IOCON->P0_30 = 0xB1;
LPC_IOCON->P0_31 = 0xB0;

//PINSEL 1
LPC_IOCON->P1_00 = 0xB0;
LPC_IOCON->P1_01 = 0xB0;
LPC_IOCON->P1_02 = 0xB0;
LPC_IOCON->P1_03 = 0xB0;
LPC_IOCON->P1_04 = 0xB0;
LPC_IOCON->P1_05 = 0xB0;
LPC_IOCON->P1_06 = 0xB0;
LPC_IOCON->P1_07 = 0xB0;
LPC_IOCON->P1_08 = 0xB0;
LPC_IOCON->P1_09 = 0xB0;
LPC_IOCON->P1_10 = 0xB0;
LPC_IOCON->P1_11 = 0xB0;
LPC_IOCON->P1_12 = 0xB0;
LPC_IOCON->P1_13 = 0xB0;
LPC_IOCON->P1_14 = 0xB0;
LPC_IOCON->P1_15 = 0xB0;
LPC_IOCON->P1_16 = 0xB0;
LPC_IOCON->P1_17 = 0xB0;
LPC_IOCON->P1_18 = 0xB2;
LPC_IOCON->P1_19 = 0xB1;
LPC_IOCON->P1_20 = 0xB1;
LPC_IOCON->P1_21 = 0xB1;
LPC_IOCON->P1_22 = 0xB1;
LPC_IOCON->P1_23 = 0xB1;
LPC_IOCON->P1_24 = 0xB1;
LPC_IOCON->P1_25 = 0xB1;
LPC_IOCON->P1_26 = 0xB1;
LPC_IOCON->P1_27 = 0xB1;
LPC_IOCON->P1_28 = 0xB1;
LPC_IOCON->P1_29 = 0xB1;
LPC_IOCON->P1_30 = 0xB2;
LPC_IOCON->P1_31 = 0xA8;

//PINSEL 2
LPC_IOCON->P2_00 = 0xB0;
LPC_IOCON->P2_01 = 0xB0;
LPC_IOCON->P2_02 = 0xB0;
LPC_IOCON->P2_03 = 0xB0;
LPC_IOCON->P2_04 = 0xB0;
LPC_IOCON->P2_05 = 0xB0;
LPC_IOCON->P2_06 = 0xB0;
LPC_IOCON->P2_07 = 0xB0;
LPC_IOCON->P2_08 = 0xB0;
LPC_IOCON->P2_09 = 0xB0;
LPC_IOCON->P2_10 = 0xB0;
LPC_IOCON->P2_11 = 0xB1;
LPC_IOCON->P2_12 = 0xB1;
LPC_IOCON->P2_13 = 0xB1;
LPC_IOCON->P2_14 = 0xB0;
LPC_IOCON->P2_15 = 0xB0;
LPC_IOCON->P2_16 = 0xB1;
LPC_IOCON->P2_17 = 0xB1;
LPC_IOCON->P2_18 = 0xB1;
LPC_IOCON->P2_19 = 0xB0;
LPC_IOCON->P2_20 = 0xB1;
LPC_IOCON->P2_21 = 0xB0;
LPC_IOCON->P2_22 = 0xB0;
LPC_IOCON->P2_23 = 0xB0;
LPC_IOCON->P2_24 = 0xB1;
LPC_IOCON->P2_25 = 0xB0;
LPC_IOCON->P2_26 = 0xB0;
LPC_IOCON->P2_27 = 0xB0;
LPC_IOCON->P2_28 = 0xB1;
LPC_IOCON->P2_29 = 0xB1;
LPC_IOCON->P2_30 = 0xB1;
LPC_IOCON->P2_31 = 0xB1;

//PINSEL 3
LPC_IOCON->P3_00 = 0xB1;
LPC_IOCON->P3_01 = 0xB1;
LPC_IOCON->P3_02 = 0xB1;
LPC_IOCON->P3_03 = 0xB1;
LPC_IOCON->P3_04 = 0xB1;
LPC_IOCON->P3_05 = 0xB1;
LPC_IOCON->P3_06 = 0xB1;
LPC_IOCON->P3_07 = 0xB1;
LPC_IOCON->P3_08 = 0xB1;
LPC_IOCON->P3_09 = 0xB1;
LPC_IOCON->P3_10 = 0xB1;
LPC_IOCON->P3_11 = 0xB1;
LPC_IOCON->P3_12 = 0xB1;
LPC_IOCON->P3_13 = 0xB1;
LPC_IOCON->P3_14 = 0xB1;
LPC_IOCON->P3_15 = 0xB1;
LPC_IOCON->P3_16 = 0xB1;
LPC_IOCON->P3_17 = 0xB1;
LPC_IOCON->P3_18 = 0xB1;
LPC_IOCON->P3_19 = 0xB1;
LPC_IOCON->P3_20 = 0xB1;
LPC_IOCON->P3_21 = 0xB1;
LPC_IOCON->P3_22 = 0xB1;
LPC_IOCON->P3_23 = 0xB1;
LPC_IOCON->P3_24 = 0xB1;
LPC_IOCON->P3_25 = 0xB1;
LPC_IOCON->P3_26 = 0xB1;
LPC_IOCON->P3_27 = 0xB1;
LPC_IOCON->P3_28 = 0xB1;
LPC_IOCON->P3_29 = 0xB1;
LPC_IOCON->P3_30 = 0xB1;
LPC_IOCON->P3_31 = 0xB1;

//PINSEL 4
LPC_IOCON->P4_00 = 0xB1;
LPC_IOCON->P4_01 = 0xB1;
LPC_IOCON->P4_02 = 0xB1;
LPC_IOCON->P4_03 = 0xB1;
LPC_IOCON->P4_04 = 0xB1;
LPC_IOCON->P4_05 = 0xB1;
LPC_IOCON->P4_06 = 0xB1;
LPC_IOCON->P4_07 = 0xB1;
LPC_IOCON->P4_08 = 0xB1;
LPC_IOCON->P4_09 = 0xB1;
LPC_IOCON->P4_10 = 0xB1;
LPC_IOCON->P4_11 = 0xB1;
LPC_IOCON->P4_12 = 0xB1;
LPC_IOCON->P4_13 = 0xB1;
LPC_IOCON->P4_14 = 0xB1;
LPC_IOCON->P4_15 = 0xB1;
LPC_IOCON->P4_16 = 0xB1;
LPC_IOCON->P4_17 = 0xB1;
LPC_IOCON->P4_18 = 0xB1;
LPC_IOCON->P4_19 = 0xB1;
LPC_IOCON->P4_20 = 0xB1;
LPC_IOCON->P4_21 = 0xB1;
LPC_IOCON->P4_22 = 0xB1;
LPC_IOCON->P4_23 = 0xB1;
LPC_IOCON->P4_24 = 0xB1;
LPC_IOCON->P4_25 = 0xB1;
LPC_IOCON->P4_26 = 0xB1;
LPC_IOCON->P4_27 = 0xB1;
LPC_IOCON->P4_28 = 0xB3;
LPC_IOCON->P4_29 = 0xB3;
LPC_IOCON->P4_30 = 0xB1;
LPC_IOCON->P4_31 = 0xB1;


LPC_SC->EMCDLYCTL = 0;

//PCONP DEJA ALIMENTEE
//CLOCK CONFIGURE CCLK 72MHZ
LPC_EMC->Control = EMC_CTRL_Val;               //enabled
LPC_EMC->Config = EMC_CONFIG_Val;                //little endian CLK:CLKOUT ratio 1:1
//PIN CONFIGURE AU DESSUS

LPC_EMC->DynamicRP = EMC_DYN_RP_Val;        //0
LPC_EMC->DynamicRAS = EMC_DYN_RAS_Val;      //2
LPC_EMC->DynamicSREX = EMC_DYN_SREX_Val;    //5
LPC_EMC->DynamicAPR = EMC_DYN_APR_Val;      //1
LPC_EMC->DynamicDAL = EMC_DYN_DAL_Val;      //4
LPC_EMC->DynamicWR = EMC_DYN_WR_Val;        //0
LPC_EMC->DynamicRC = EMC_DYN_RC_Val;        //4
LPC_EMC->DynamicRFC = EMC_DYN_RFC_Val;      //4
LPC_EMC->DynamicXSR = EMC_DYN_XSR_Val;      //5
LPC_EMC->DynamicRRD = EMC_DYN_RRD_Val;      //0
LPC_EMC->DynamicMRD = EMC_DYN_MRD_Val;      //0

LPC_EMC->DynamicReadConfig = EMC_DYN_RD_CFG_Val;            //1
LPC_EMC->DynamicRasCas0 = EMC_DYN_RASCAS0_Val;              //0x0202
LPC_EMC->DynamicConfig0 = EMC_DYN_CFG0_Val & ~((uint32_t)BUFEN_Const);        //b19 = 0

for (l_i=1440000;l_i>0;l_i--);   //attente environ 100ms


LPC_EMC->DynamicControl = NOP_CMD | 0x03;                           //write NOP COMMAND (3 << 7)
for (l_i=2880000;l_i>0;l_i--);   //attente environ 200ms


LPC_EMC->DynamicControl = PALL_CMD | 0x03;                           //precharge all command   (2 << 7)
LPC_EMC->DynamicRefresh = 2;

for (l_i=64;l_i>0;l_i--);   //attente
LPC_EMC->DynamicRefresh = EMC_DYN_RFSH_Val;                         //0x7FF


LPC_EMC->DynamicControl = MODE_CMD | 0x03;                           //write MODE COMMAND     (1 << 7)

temp =*((uint32_t*) (DYN_MEM0_BASE + (((uint32_t)0x11) << 11)));

LPC_EMC->DynamicControl = NORMAL_CMD;                           //write NORMAL COMMAND        (0 << 7)

#if (EMC_DYN_CFG0_Val & BUFEN_Const)
LPC_EMC->DynamicConfig0 = EMC_DYN_CFG0_Val;                   //0x85508
#endif

for (l_i=14400;l_i>0;l_i--);     //attente
for (l_i=1440000;l_i>0;l_i--);   //attente

//FLASH EXTERNE
LPC_EMC->StaticConfig0   = EMC_STA_CFG0_Val;      //EMC STATIC COnfig0      82
LPC_EMC->StaticWaitWen0  = EMC_STA_WWEN0_Val;     //0
LPC_EMC->StaticWaitOen0  = EMC_STA_WOEN0_Val;     //0
LPC_EMC->StaticWaitRd0   = EMC_STA_WRD0_Val;      //4
LPC_EMC->StaticWaitPage0 = EMC_STA_WPAGE0_Val;    //0
LPC_EMC->StaticWaitWr0   = EMC_STA_WWR0_Val;      //5
LPC_EMC->StaticWaitTurn0 = EMC_STA_WTURN0_Val;    //0

for (l_i=144000;l_i>0;l_i--);   //attente


temp = *(uint32_t*) (LPC_EMC_BASE + EMC_STA_EXT_W_OFS);             //0FFSET 0x880
[\code]
INI FILE Utilities

/******************************************************************************/
/* Ext_NOR.INI: External NOR Flash Initialization File for NXP LPC24xx        */
/******************************************************************************/
// <<< Use Configuration Wizard in Context Menu >>>                           //
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2007 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/

_WDWORD(0x2009C000, 0x00000001);        // EMC_CTRL: Disable address mirror

_WDWORD(0x2009C008, 0x00000000);        //EMCCONFIG: rajout tr
_WDWORD(0x400FC1DC, 0x00000000);        //EMCDLYCTL: TR

_WDWORD(0x400FC0C4, 0x00000800);        // PCONP: Turn on EMC PCLK

_WDWORD(0x4002C140, 0x000000B1);        //P2.16       CAS
_WDWORD(0x4002C144, 0x000000B1);        //P2.17       RAS
_WDWORD(0x4002C148, 0x000000B1);        //P2.18       CLKOUt0
_WDWORD(0x4002C150, 0x000000B1);        //P2.20       DYCS0
_WDWORD(0x4002C160, 0x000000B1);        //P2.24       CKEOUT0
_WDWORD(0x4002C170, 0x000000B1);        //P2.28       DQMOUT0
_WDWORD(0x4002C174, 0x000000B1);        //P2.29       DQMOUT1
_WDWORD(0x4002C178, 0x000000B1);        //P2.30       DQMOUT2

_WDWORD(0x4002C180, 0x000000B1);        //P3.00       D0
_WDWORD(0x4002C184, 0x000000B1);        //P3.01       D1
_WDWORD(0x4002C188, 0x000000B1);        //P3.02       D2
_WDWORD(0x4002C18C, 0x000000B1);        //P3.03       D3
_WDWORD(0x4002C190, 0x000000B1);        //P3.04       D4
_WDWORD(0x4002C194, 0x000000B1);        //P3.05       D5
_WDWORD(0x4002C198, 0x000000B1);        //P3.06       D6
_WDWORD(0x4002C19C, 0x000000B1);        //P3.07       D7
_WDWORD(0x4002C1A0, 0x000000B1);        //P3.08       D8
_WDWORD(0x4002C1A4, 0x000000B1);        //P3.09       D9

_WDWORD(0x4002C200, 0x000000B1);        //P4.00       A0
_WDWORD(0x4002C204, 0x000000B1);        //P4.01       A1
_WDWORD(0x4002C208, 0x000000B1);        //P4.02       A2
_WDWORD(0x4002C20C, 0x000000B1);        //P4.03       A3
_WDWORD(0x4002C210, 0x000000B1);        //P4.04       A4
_WDWORD(0x4002C214, 0x000000B1);        //P4.05       A5
_WDWORD(0x4002C218, 0x000000B1);        //P4.06       A6
_WDWORD(0x4002C21C, 0x000000B1);        //P4.07       A7
_WDWORD(0x4002C220, 0x000000B1);        //P4.08       A8
_WDWORD(0x4002C224, 0x000000B1);        //P4.09       A9
_WDWORD(0x4002C228, 0x000000B1);        //P4.10       A10
_WDWORD(0x4002C22C, 0x000000B1);        //P4.11       A11
_WDWORD(0x4002C230, 0x000000B1);        //P4.12       A12
_WDWORD(0x4002C234, 0x000000B1);        //P4.13       A13
_WDWORD(0x4002C238, 0x000000B1);        //P4.14       A14
_WDWORD(0x4002C23C, 0x000000B1);        //P4.15       A15
_WDWORD(0x4002C240, 0x000000B1);        //P4.16       A16
_WDWORD(0x4002C244, 0x000000B1);        //P4.17       A17
_WDWORD(0x4002C248, 0x000000B1);        //P4.18       A18
_WDWORD(0x4002C24C, 0x000000B1);        //P4.19       A19
_WDWORD(0x4002C250, 0x000000B1);        //P4.20       A20
_WDWORD(0x4002C254, 0x000000B1);        //P4.21       A21
_WDWORD(0x4002C258, 0x000000B1);        //P4.22       A22
_WDWORD(0x4002C25C, 0x000000B1);        //P4.23       A23
_WDWORD(0x4002C260, 0x000000B1);        //P4.24       OE
_WDWORD(0x4002C264, 0x000000B1);        //P4.25       WE
_WDWORD(0x4002C268, 0x000000B1);        //P4.26       BLS0
_WDWORD(0x4002C26C, 0x000000B1);        //P4.27       BLS1

_WDWORD(0x4002C278, 0x000000B1);        //P4.30       CS0
_WDWORD(0x4002C27C, 0x000000B1);        //P4.31       CS1


// Setup controller for External NOR Flash
_WDWORD(0x2009C200, 0x00000082);        // EMCStaticConfig0
_WDWORD(0x2009C204, 0x00000000);        // EMCStaticWaitWen0 0x2 EA / 0 x292
_WDWORD(0x2009C208, 0x00000000);        // EMCStaticWaitOen0 0x2 EA / 0 x292
_WDWORD(0x2009C20C, 0x00000004);        // EMCStaticWaitRd0  0x5 EA / 4 x292
_WDWORD(0x2009C210, 0x00000000);        // EMCStaticWaitPage0
_WDWORD(0x2009C214, 0x00000005);        // EMCStaticWaitWr0
_WDWORD(0x2009C218, 0x00000000);        // EMCStaticWaitTurn0

[\CODE]


have you an idea?
have you a similar INI?


thank's

Outcomes