EMC + LPC1788 + s29gl064 norFlash

cancel
Showing results for 
Search instead for 
Did you mean: 

EMC + LPC1788 + s29gl064 norFlash

157 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yanvasilij on Fri Jul 20 05:25:32 MST 2012
Hello!

I have a board with s29GL064 norFlash. The flash memory  connected like sst39vf3201 in OEM NXP board for LPC1788. The timings are  equal in both memories.  There is some differences in commands, so I  had to change original sample. Here is code:
void delay(uint32_t delayCnt)
{
    uint32_t i;

    for ( i = 0; i < delayCnt; i++ );
    return;
}

void NORFLASHInit( void )
{
    TIM_TIMERCFG_Type TIM_ConfigStruct;

    EMC_Init();

    TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
    TIM_ConfigStruct.PrescaleValue    = 1;

    TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
    TIM_Waitms(100);

    EMC_StaMemConfigMW (0,EMC_StaticConfig_MW_16BITS);
    EMC_StaMemConfigPB(0,EMC_StaticConfig_PB);
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(0x0F));            
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(0x04));            
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x0F));
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1f));
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1f));
    EMC_SetStaMemoryParameter(0, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0x1f));

    //delay time
     TIM_Waitms(10);

      return;
}


uint32_t ToggleBitCheck( uint32_t Addr, uint16_t Data )
{
    volatile uint16_t *ip;
    uint16_t temp1, temp2;
    uint32_t TimeOut = PROGRAM_TIMEOUT;

    while( TimeOut > 0 )
    {
        ip = GET_ADDR(Addr);
        temp1 = *ip;
        ip = GET_ADDR(Addr);
        temp2 = *ip;

        if ( (temp1 == temp2) && (temp1 == Data) )
        {
             return( TRUE );
        }
        TimeOut--;
    }
    return ( FALSE );
}

uint32_t NORFLASHCheckID( void )
{
  volatile uint16_t *ip;
  uint16_t SST_id1 = 0, SST_id2 = 0;

  ip  = GET_ADDR(0x555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x555);
  *ip = 0x0090;
  delay(10);

  ip  = GET_ADDR(0x0001);
  SST_id2 = *ip;
  delay(10);

    return SST_id2;
}


void NORFLASHErase( void )
{
  volatile uint16_t *ip;

  ip  = GET_ADDR(0x555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x555);
  *ip = 0x0080;
  ip  = GET_ADDR(0x555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x555);
  *ip = 0x0010;
  delay(10000000);                /* Use timer 1 */
  return;

}


uint32_t NORFLASHWriteWord( uint32_t Addr, uint16_t Data )
{
  volatile uint16_t *ip;

  ip  = GET_ADDR(0x555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x555);
  *ip = 0x00A0;

  ip = GET_ADDR(Addr);        /* Program 16-bit word */
  *ip = Data;
  return ( ToggleBitCheck( Addr, Data ) );
}

Unfortunately it doesn't work at all. Reading  ID always returns 0xFFFF, writing in flash stops in ToggleBitCheck(  Addr, Data ) (always loops). Could somebody to explain to me what is  wrong?

Regards, Vasilij.
0 Kudos
2 Replies

71 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_Europe on Tue Jul 24 03:33:04 MST 2012
Hi yanvasilij,

What happens if you change (add volatile):
uint16_t temp1, temp2; ... => ... volatile uint16_t temp1, temp2;

see:
uint32_t ToggleBitCheck( uint32_t Addr, uint16_t Data )
{
...
volatile uint16_t *ip;
uint16_t temp1, temp2;
uint32_t TimeOut = PROGRAM_TIMEOUT;
...
}

(...)
0 Kudos

71 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by yanvasilij on Mon Jul 23 04:22:50 MST 2012
People, please help! I really don't know haw to configure EMC with my flash:confused:. Could somebody tell me which values of timing I should to select? And which values I should to write to LPC_EMC->StaticWaitWen0, LPC_EMC->StaticWaitOen0 and LPC_EMC->StaticWaitRd0. I thought I should to take 0x0C because timing for writing and readings for s29GL064 is 90-110 ns. But I suppose I was wrong. :(
0 Kudos