lpcware

EMC StaticMem for nor flash

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Badman on Wed Apr 23 08:46:22 MST 2014
I have an example for LPC4088, which uses memory flash S29GL064 for Keil. Ported it to the LPCXpresso but the lack of data read from memory. Field variables NOR_ID always have a value 65535.
Why below code works compiled in Keil, but not LPCXpresso ?

#include "emc_nor.h"
#include "lpc_timer.h"

/* Private define ------------------------------------------------------------*/
#define NOR_FLASH_START_ADDR       ((uint32_t)0x90000000)
#define NOR_FLASH_END_ADDR         ((uint32_t)0x90800000)

/* Delay definition */  
#define SectorErase_Timeout        ((uint32_t)0x00A00000)
#define ChipErase_Timeout          ((uint32_t)0x30000000)
#define Program_Timeout            ((uint32_t)0x00001400)

#define ADDR_SHIFT(A)              (NOR_FLASH_START_ADDR + (2 * (A)))
#define NOR_WRITE(Address, Data)   (*(volatile short *)(Address) = (Data))

typedef struct
{
  uint16_t Manufacturer_Code;
  uint16_t Device_Code1;
  uint16_t Device_Code2;
  uint16_t Device_Code3;
}
NOR_IDTypeDef;

NOR_IDTypeDef NOR_ID;

/*******************************************************************************
* Function Name  : EMC_NOR_Init
* Description    : Configures the FSMC and GPIOs to interface with the NOR memory.
*                  This function must be called before any write/read operation
*                  on the NOR.
* Input          : None
* Output         : None
* Return         : None
* Attention : None
*******************************************************************************/
void EMC_NOR_Init(void)
{
TIM_TIMERCFG_Type TIM_ConfigStruct;
EMC_STATIC_MEM_Config_Type config;

/**************************************************************************
* Initialize EMC for NOR FLASH
**************************************************************************/
config.CSn = 1;
config.AddressMirror = 0;
config.ByteLane = 1;
config.DataWidth = 16;
config.ExtendedWait = 0;
config.PageMode = 0;
config.WaitWEn = 2;
config.WaitOEn = 2;
config.WaitWr = 0x1f;
config.WaitPage = 0x1f;
config.WaitRd = 0x1f;
config.WaitTurn = 0x1f;
StaticMem_Init(&config);

    // init timer
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue= 1;

// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
TIM_Waitms(100);

//delay time
TIM_Waitms(10);

  return;
}

/******************************************************************************
* Function Name  : EMC_NOR_ReadID
* Description    : Reads NOR memory's Manufacturer and Device Code.
* Input          : - NOR_ID: pointer to a NOR_IDTypeDef structure which will hold
*                    the Manufacturer and Device Code.
* Output         : None
* Return         : None
* Attention : None
*******************************************************************************/
void EMC_NOR_ReadID(NOR_IDTypeDef* NOR_ID)
{
  NOR_WRITE(ADDR_SHIFT(0x0555), 0x00AA);
  NOR_WRITE(ADDR_SHIFT(0x02AA), 0x0055);
  NOR_WRITE(ADDR_SHIFT(0x0555), 0x0090);

  NOR_ID->Manufacturer_Code = *(volatile short *) ADDR_SHIFT(0x0000);
  NOR_ID->Device_Code1 = *(volatile short *) ADDR_SHIFT(0x0001);
  NOR_ID->Device_Code2 = *(volatile short *) ADDR_SHIFT(0x000E);
  NOR_ID->Device_Code3 = *(volatile short *) ADDR_SHIFT(0x000F);
}

/******************************************************************************
* Function Name  : EMC_NOR_ReturnToReadMode
* Description    : Returns the NOR memory to Read mode.
* Input          : None
* Output         : None
* Return         : NOR_SUCCESS
* Attention : None
*******************************************************************************/
NOR_Status EMC_NOR_ReturnToReadMode(void)
{
  NOR_WRITE(NOR_FLASH_START_ADDR, 0x00F0);

  return (NOR_SUCCESS);
}
void main (void)
{
  uint32_t index;
  uint16_t sector;
  uint8_t nor_error;

  /* Initialize the FSMC NOR Flash Interface */
  EMC_NOR_Init();
  /* Set the NOR read modes */
  EMC_NOR_ReturnToReadMode();

  EMC_NOR_ReadID(&NOR_ID);

  while(1)
  {
  }
}


Outcomes