📄 sst39vf6401.c
字号:
/* */
#include "bsp.h"
#include "lpc_types.h"
#include "SST39VF6401.h"
#include "lpc177x_8x_emc.h"
#include "lpc177x_8x_clkpwr.h"
#include "lpc177x_8x_pinsel.h"
#include "lpc177x_8x_timer.h"
/*********************************************************************//**
* @brief Delay
* @param[in] delayCnt Delay value
* @return None
**********************************************************************/
void delay_ns(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();
delay_ns(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(0x1f));
delay_ns(150);
return;
}
/************************************************************************/
/* PROCEDURE: Check_SST_39VF640X */
/* */
/* This procedure decides whether a physical hardware device has a */
/* SST39VF640X 16 Mbit MPF+ Device installed or not. */
/* */
/* Input: */
/* None */
/* */
/* Output: */
/* return TRUE: indicates a SST39VF640X */
/* return FALSE: indicates not a SST39VF640X */
/************************************************************************/
int Check_SST_39VF640XB(void)
{
uint16_t SST_id1;
uint16_t SST_id2;
int ReturnStatus;
// Issue the Software Product ID code to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x0090; // write data 0x0090 to device addr 0x5555
delay_ns(100);
// Read the product ID from 39VF640X
SST_id1 = *sysAddress(0x0000); // get first ID uint8_t
SST_id2 = *sysAddress(0x0001); // get second ID uint8_t
// ------------------------------------------------------------
// Determine whether there is a SST 39VF1601 installed or not
// use the following code:
if (((SST_id1 == SST_ID) && (SST_id2 == SST_39VF6401B))||((SST_id1 == SST_ID) && (SST_id2 == SST_39VF6402B)))
ReturnStatus = TRUE;
else
ReturnStatus = FALSE;
// ------------------------------------------------------------
// Issue the Software Product ID Exit code, thus returning the
// 39VF640X to the normal operation.
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x00F0; // write data 0x00F0 to device addr 0x5555
delay_ns(100); // Tida Max 150ns for 39VF640X
return (ReturnStatus);
}
/************************************************************************/
/* PROCEDURE: CFI_Query */
/* */
/* This procedure should be used to query for CFI information */
/* */
/* Input: */
/* Src Source address to store CFI_Query data string */
/* */
/* Output: */
/* None */
/************************************************************************/
void CFI_Query(uint16_t *Src)
{
uint16_t index;
// Issue the CFI Query entry code to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x0098; // write data 0x0098 to device addr 0x5555
Delay(1); // insert delay time = Tida
// ----------------------------------------------------------
// Perform all CFI operations here:
// CFI_Query_address is from 0010H--0034H
for (index = 0x0010; index <= 0x0034; index++)
{
*Src = *sysAddress(index);
++Src;
// CFI query data is stored in user-defined memory space.
}
// ----------------------------------------------------------
// Issue the CFI Exit code thus returning the 39VF640X
// to the read operating mode
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x00F0; // write data 0x00F0 to device addr 0x5555
Delay(1); // insert delay time = Tida
}
/************************************************************************/
/* PROCEDURE: SecID_Query */
/* */
/* This procedure should be used to query for Security ID information. */
/* */
/* Input: */
/* SST_SecID Source address to store SST SecID string */
/* User_SecID Source address to store User SecID string */
/* */
/* Output: */
/* None */
/************************************************************************/
void SecID_Query(uint16_t *SST_SecID, uint16_t *User_SecID)
{
uint16_t index;
// Issue the SecID Entry code to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x0088; // write data 0x0088 to device addr 0x5555
Delay(1); // insert delay time = Tida
// Perform all Security ID operations here:
// SST programmed segment is from address 000000H--000007H,
// User programmed segment is from address 000010H--000017H.
for (index = 0x0000; index <= 0x0007; index++)
{
*SST_SecID = *sysAddress(index);
++SST_SecID;
*User_SecID = *sysAddress(index+0x0010);
++User_SecID;
// Security query data is stored in user-defined memory space.
}
// Issue the Sec ID Exit code thus returning the 39VF640X
// to the read operating mode
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x00F0; // write data 0x00F0 to device addr 0x5555
Delay(1); // insert delay time = Tida
}
/************************************************************************/
/* PROCEDURE: Erase_One_Sector */
/* */
/* This procedure can be used to erase a total of 2048 uint16_ts. */
/* */
/* Input: */
/* Dst DESTINATION address where the erase operation starts */
/* */
/* Output: */
/* return TRUE: indicates success in sector-erase */
/* return FALSE: indicates failure in sector-erase */
/************************************************************************/
int Erase_One_Sector(uint32_t Dst)
{
uint32_t DestBuf = Dst;
int ReturnStatus;
// Issue the Sector Erase command to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x0080; // write data 0x0080 to device addr 0x5555
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(DestBuf) = 0x0050; // write data 0x0050 to device sector addr
ReturnStatus = Check_Toggle_Ready(DestBuf); // wait for TOGGLE bit ready
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Erase_One_Block */
/* */
/* This procedure can be used to erase a total of 32K uint16_ts. */
/* */
/* Input: */
/* Dst DESTINATION address where the erase operation starts */
/* */
/* Output: */
/* return TRUE: indicates success in block-erase */
/* return FALSE: indicates failure in block-erase */
/************************************************************************/
int Erase_One_Block (uint32_t Dst)
{
uint32_t DestBuf = Dst;
int ReturnStatus;
// Issue the Block Erase command to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x0080; // write data 0x0080 to device addr 0x5555
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(DestBuf) = 0x0030; // write data 0x0050 to device sector addr
ReturnStatus = Check_Toggle_Ready(DestBuf); // wait for TOGGLE bit ready
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Erase_Entire_Chip */
/* */
/* This procedure can be used to erase the entire chip. */
/* */
/* Input: */
/* NONE */
/* */
/* Output: */
/* NONE */
/************************************************************************/
int Erase_Entire_Chip(void)
{
// Issue the Chip Erase command to 39VF640X
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AA
*sysAddress(0x555) = 0x0080; // write data 0x0080 to device addr 0x555
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AA
*sysAddress(0x555) = 0x0010; // write data 0x0010 to device addr 0x555
delay_ns(100); // Delay Tsce time
if (Check_Data_Polling (0,0xFFFF))
return TRUE;
else
return FALSE;
}
/************************************************************************/
/* PROCEDURE: Program_One_uint16_t */
/* */
/* This procedure can be used to program ONE uint16_t of data to the */
/* 39VF640X. */
/* */
/* NOTE: It is necessary to first erase the sector containing the */
/* uint16_t to be programmed. */
/* */
/* Input: */
/* Srcuint16_t The uint16_t which will be written to the 39VF640X */
/* Dst DESTINATION address which will be written with the */
/* data passed in from Src */
/* */
/* Output: */
/* return TRUE: indicates success in uint16_t-program */
/* return FALSE: indicates failure in uint16_t-program */
/************************************************************************/
int Program_One_uint16_t (uint16_t *Srcuint16_t, uint32_t Dst)
{
uint32_t DestBuf = Dst;
uint16_t *SourceBuf = Srcuint16_t;
int ReturnStatus;
*sysAddress(0x555) = 0x00AA; // write data 0x00AA to device addr 0x5555
*sysAddress(0x2AA) = 0x0055; // write data 0x0055 to device addr 0x2AAA
*sysAddress(0x555) = 0x00A0; // write data 0x00A0 to device addr 0x5555
*sysAddress(DestBuf) = *SourceBuf; // transfer the uint16_t to destination
ReturnStatus = Check_Toggle_Ready(DestBuf); // wait for TOGGLE bit ready
return ReturnStatus;
}
/************************************************************************/
/* PROCEDURE: Program_One_Sector */
/* */
/* This procedure can be used to program a total of 2048 uint16_ts of data */
/* to the SST39VF640X. */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -