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

📄 sst39vf640xb.cpp

📁 sst39vf640xB flash driver
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//Software Driver
//SST39VF6401B/SST39VF6402B
//64 Mbit Multi-Purpose Flash (MPF+)
//
//June 2005
//
//ABOUT THE SOFTWARE
//
//This application note provides a software driver example for 39VF6401B/39VF6402B
//64 Mbit Multi-Purpose Flash (MPF+) that can be used in any microprocessor based
//system.
//
//The SST39VF6401B supports bottom boot block protection, and the SST39VF6402B
//supports top boot block protection. The boot block memory area is protected when
//WP# is low and unprotected when WP# is high.
//
//Software driver example routines provided in this document utilize high-level
//"C" programming language for broad platform support. In many cases, software
//driver routines can be inserted "as is" into the main body of code being
//developed by the system software developers. Extensive comments are included
//in each routine to describe the function of each routine. The software driver
//routines in "C" can be used with many microprocessors and microcontrollers.
//
//ABOUT THE SST39VF6401B/SST39VF6402B
//
//Companion product datasheet for 39VF6401/39VF6402 should be reviewed in
//conjunction with this application note for a complete understanding of the device.
//
//The C code in this document contains the following routines, which are listed
//in this order:
//
//Name                    Function
//------------------------------------------------------------------
//Check_SST_39VF640XB      Check manufacturer and device ID
//CFI_Query               CFI Query Entry/Exit command sequence
//SecID_Query		SecID Query Entry/Exit command sequence
//Erase_One_Sector        Erase a sector of 2048 words
//Erase_One_Block         Erase a block of 32K words
//Erase_Entire_Chip       Erase the contents of the entire chip
//Program_One_Word        Alter data in one word
//Program_One_Sector      Alter data in 2048-word sector
//Program_One_Block       Alter data in 32K-word block
//SecID_Lock_Status	Check the Lock Status of Security ID segment
//User_SecID_Word_Program Write data into User Security ID Segment
//User_SecID_Lock_Out 	Lock out the User Security ID Segment
//Erase_Suspend		Suspend Sector/Block Erase operation
//Erase_Resume		Resume Sector/Block Erase operation
//Check_Toggle_Ready      End of internal program or erase detection using
//                        Toggle bit
//Check_Data_Polling      End of internal program or erase detection using
//                        Data# polling
//
//"C" LANGUAGE DRIVERS


/***********************************************************************/
/* Copyright Silicon Storage Technology, Inc. (SST), 1994-2005         */
/* Example "C" language Driver of 39VF640X 64 Mbit MPF+ Device	       */
/* Verified by Yonglin, Silicon Storage Technology, Inc.                        */
/*                                                                     */
/* Revision 1.0, June 17, 2005                                         */
/*                                                                     */
/* This file requires these external "timing"  routines:               */
/*                                                                     */
/*      1.)  Delay_10_Micro_Seconds                                    */
/*      2.)  Delay_20_Micro_Seconds                                    */
/*      3.)  Delay_150_Nano_Seconds                                    */
/*      4.)  Delay_25_Milli_Seconds                                    */
/*      5.)  Delay_50_Milli_Seconds                                    */
/***********************************************************************/

#define FALSE                   0
#define TRUE                    1

#define SECTOR_SIZE             2048    // Must be 2048 words for 39VF640XB
#define BLOCK_SIZE              32768   // Must be 32K words for 39VF640XB

#define SST_ID                  0x00BF  // SST Manufacturer's ID code
#define SST_39VF6401B            0x236D  // SST39VF6401B device code
#define SST_39VF6402B            0x236C  // SST39VF6402B device code

typedef unsigned char           BYTE;     // BYTE is 8-bit in length
//typedef unsigned int            WORD;     // WORD is 16-bit in length
typedef unsigned short            WORD;     // WORD is 16-bit in length, ARM
//typedef unsigned long int       Uint32;   // Uint32 is 32-bit in length
typedef unsigned int       Uint32;   // Uint32 is 32-bit in length, ARM

//Uint32 system_base = 0x4000000;  // 4GByte System Memory Address.

#define system_base  0x4000000
	// This sample code uses 0x4000000 as the system_base address in ARM system.
   	// The user should modify this address accordingly.

//#define sysAddress(offset) ((volatile WORD *)(system_base + offset))
#define sysAddress(offset) ((volatile WORD *)(system_base + (((WORD)offset)<<1))) //For ARM CPU


#define MAX_TIMEOUT	0x07FFFFFF   // A ceiling constant used by Check_Toggle_
	// Ready() and Check_Data_Polling().
      	// The user should modify this constant accordingly.

// --------------------------------------------------------------------
//                       EXTERNAL ROUTINES
// --------------------------------------------------------------------
extern void     Delay_10_Micro_Seconds();
extern void     Delay_20_Micro_Seconds();
extern void     Delay_150_Nano_Seconds();
extern void     Delay_25_Milli_Seconds();
extern void     Delay_50_Milli_Seconds();



// --------------------------------------------------------------------

int Check_SST_39VF640XB(void);
void CFI_Query(WORD*);
void SecID_Query(WORD*, WORD*);
int Erase_One_Sector(Uint32);
int Erase_One_Block (Uint32);
int Erase_Entire_Chip(void);
int Program_One_Word (WORD*, Uint32);
int Program_One_Sector (WORD*, Uint32);
int Program_One_Block (WORD *Src, Uint32 Dst);
int SecID_Lock_Status(void);
int User_SecID_Word_Program (WORD*, WORD*, int);
void User_SecID_Lock_Out (void);
void Erase_Suspend (void);
void Erase_Resume (void);
int Check_Toggle_Ready (Uint32);
int Check_Data_Polling (Uint32, WORD);


/************************************************************************/
/* PROCEDURE:   Check_SST_39VF640XB                                      */
/*                                                                      */
/* This procedure decides whether a physical hardware device has a      */
/* SST39VF640XB 64 Mbit MPF+ Device installed or not.         		*/
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*          return TRUE:  indicates a SST39VF640XB                       */
/*          return FALSE: indicates not a SST39VF640XB                   */
/************************************************************************/
int Check_SST_39VF640XB(void)
{
    WORD SST_id1;
    WORD SST_id2;
    int  ReturnStatus;


    //  Issue the Software Product ID code to 39VF640XB
    *sysAddress(0x555) = 0x00AA;  // write data 0x00AA to device addr 0x555

    *sysAddress(0x2AA) = 0x0055;  // write data 0x0055 to device addr 0x2AA

    *sysAddress(0x555) = 0x0090;  // write data 0x0090 to device addr 0x555

    Delay_150_Nano_Seconds();   // Tida Max 150ns for 39VF640XB

    // Read the product ID from 39VF640XB
    SST_id1  = *sysAddress(0x0000);   // get first ID byte
    SST_id2  = *sysAddress(0x0001);   // get second ID byte

    // ------------------------------------------------------------
    // Determine whether there is a SST 39VF6401B installed or not
    // use the following code:

    //if ((SST_id1 == SST_ID) && (SST_id2 == SST_39VF6401B))
    //        ReturnStatus = TRUE;
    //else
    //        ReturnStatus = FALSE;
    // ------------------------------------------------------------
    // Or determine whether there is a SST 39VF6402B installed or not
    // use the following code:

    if ((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 0x555
    *sysAddress(0x2AA) = 0x0055;  // write data 0x0055 to device addr 0x2AA
    *sysAddress(0x555) = 0x00F0;  // write data 0x00F0 to device addr 0x555
    Delay_150_Nano_Seconds();   // Tida Max 150ns for 39VF640XB

    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(WORD *Src)
{
    WORD index;
    //  Issue the CFI Query entry code to 39VF640X
    *sysAddress(0x555) = 0x00AA;  // write data 0x00AA to device addr 0x555
    *sysAddress(0x2AA) = 0x0055;  // write data 0x0055 to device addr 0x2AA
    *sysAddress(0x555) = 0x0098;  // write data 0x0098 to device addr 0x555
    Delay_150_Nano_Seconds();     // 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 0x555
    *sysAddress(0x2AA) = 0x0055;  // write data 0x0055 to device addr 0x2AA
    *sysAddress(0x555) = 0x00F0;  // write data 0x00F0 to device addr 0x555
    Delay_150_Nano_Seconds();     // 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	*/

⌨️ 快捷键说明

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