⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 norflash_sst39vf3201.c

📁 LPC1788的USBHOST的FATFS移植
💻 C
字号:
/**********************************************************************
* $Id$		norflash_sst39vf3201.c			2011-06-02
*//**
* @file		norflash_sst39vf3201.c
* @brief	Contains all functions support for NOR Flash SamSung
*			SST39VF3201
* @version	1.0
* @date		02. June. 2011
* @author	NXP MCU SW Application Team
* 
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
**********************************************************************/
 
#include "norflash_sst39vf3201.h"
#include "lpc177x_8x_emc.h"
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_pinsel.h"
#include "lpc177x_8x_timer.h"

int32_t volatile timerdev = 0;

/*********************************************************************//**
 * @brief 		Delay
 * @param[in]	delayCnt Delay value
 * @return 		None
 **********************************************************************/
void delay(uint32_t delayCnt)
{
	uint32_t i;

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

/*********************************************************************//**
 * @brief 		Initialize external NOR FLASH memory
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void NORFLASHInit( void )
{
	TIM_TIMERCFG_Type TIM_ConfigStruct;
	/**************************************************************************
	* Initialize EMC for NOR FLASH
	**************************************************************************/
	EMC_Init();

    // 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(100);
	EMC_StaMemConfigMW (1,EMC_StaticConfig_MW_16BITS);
	EMC_StaMemConfigPB(1,EMC_StaticConfig_PB);
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITWEN, EMC_StaticWaitWen_WAITWEN(2));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITOEN, EMC_StaticWaitOen_WAITOEN(2));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITRD, EMC_StaticWaitRd_WAITRD(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITPAGE, EMC_StaticwaitPage_WAITPAGE(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITWR, EMC_StaticWaitwr_WAITWR(0x1f));
	EMC_SetStaMemoryParameter(1, EMC_STA_MEM_WAITTURN, EMC_StaticWaitTurn_WAITTURN(0xf));

	//delay time
 	delay(100);

  	return;
}

/*********************************************************************//**
 * @brief 		Toggle Bit check if the data is written or erased
 * @param[in]	Addr	address value
 * @param[in]	Data	expected data
 * @return 		Checking result, could be:
 * 					- TRUE: Done
 *					- FALSE: Timeout
 **********************************************************************/
unsigned int ToggleBitCheck( unsigned int Addr, short Data )
{
  volatile short *ip;
  short temp1, temp2;
  unsigned int TimeOut = PROGRAM_TIMEOUT;

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

	if ( (temp1 == temp2) && (temp1 == Data) )
	{
	  return( 1 );
	}
	TimeOut--;
  }
  return ( 0 );
}

/*********************************************************************//**
 * @brief 		Check ID from external NOR FLASH memory
 * @param[in]	None
 * @return 		Checking result, could be:
 * 					- TRUE: Correct
 *					- FALSE: Incorrect
 **********************************************************************/
uint32_t NORFLASHCheckID( void )
{
  
  volatile short *ip;
  short SST_id1, SST_id2;

  /* 确认对应AM29LV160的产品ID号 */
  ip  = GET_ADDR(0x5555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AAA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x5555);
  *ip = 0x0090;
  delay(100);	

  /* Read the product ID from 39VF160 */
  /* 从AM29LV160读取产品ID号 */
  ip  = GET_ADDR(0x0000); 
  SST_id1 = *ip & 0x00FF;
  ip  = GET_ADDR(0x0001);
  SST_id2 = *ip;             

  /* 确认AM29LV160的产品ID号,以便退出本函数 */
  /* 进入读操作模式 */
  ip  = GET_ADDR(0x5555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AAA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x5555);  
  *ip = 0x00F0;    
  delay(100);	

  /* 校验 ID */
  //if ((SST_id1 == MANUFACTURER_ID) && (SST_id2 ==DEVICE_ID))
  if ((SST_id1 == SST_ID) && (SST_id2 == SST_39VF160))
	return( 1 );
  else
	return( 0 );
}

/*********************************************************************//**
 * @brief 		Erase external NOR FLASH memory
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void NORFLASHErase( void )
{
  volatile uint16_t *ip;

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

}

void NORFLASHSectorErase(unsigned char sector)
{
volatile short *ip;

  //if(sector > SECTOR_NUM_AMD) return ;
  if(sector > SECTOR_NUM_SST) return ;
  ip  = GET_ADDR(0x5555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AAA);
  *ip = 0x0055;
  ip  = GET_ADDR(0x5555);
  *ip = 0x0080;
  ip  = GET_ADDR(0x5555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2AAA);
  *ip = 0x0055;
  ip  = GET_ADDR(sector);
  *ip = 0x0010;
  //wait(100);
  delay(10000000);	
  return;
}

/*********************************************************************//**
 * @brief 		Program one 16-bit data into external NOR FLASH memory
 *				This "uint16_t" for the external flash is 16 bits!!!
 * @param[in]	Addr	Address value
 * @param[in]	Data	data value
 * @return 		Program result, could be:
 					- TRUE: succesful
					- FALSE: fail
 **********************************************************************/
uint32_t NORFLASHWriteWord( unsigned int Addr, short Data )
{
  volatile uint16_t *ip;

  ip  = GET_ADDR(0x5555);
  *ip = 0x00AA;
  ip  = GET_ADDR(0x2aaa);
  *ip = 0x0055;
  ip  = GET_ADDR(0x5555);
  *ip = 0x00A0;

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

/*********************************************************************************
**                            End Of File
*********************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -