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

📄 sst39vf3201.c

📁 SST flash driver,已经经过测试
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
Software Device Driver
SST39VF3201/SST39VF3202
32 Mbit Multi-Purpose Flash (MPF+)
Jerry Deng, Silicon Storage Technology, Inc.
Revision 2.0, December 2003

ABOUT THE SOFTWARE

This is a software device driver example for SST39VF3201/3202
32 Mbit Multi-Purpose Flash (MPF+). The code is written in generic C language, 
extensive comments are included in each routine to describe its function and usage. 

SST39VF3201/3202 datasheet should be reviewed in conjunction
with this code to completely understand the operation of this device.

The SST39VF3201 supports bottom boot block protection, and the SST39VF3202 
supports top boot block protection. The boot block memory area is protected from 
erase/programming when WP# is low and unprotected when WP# is high.

During execution of this code, it's assumed that RST# signal on device is held in 
logic high state, otherwise the device will be put into reset state (read mode) 
as long as RST# is low.
*/

#define AddrsShift              2           
// define 2 if it's true that A1 of system address bus has been shifted to A0 of device address, A2 to A1, etc.
// otherwise, change it to look like:
// #define AddrsShift           1 

#define DefaultBaseAddress      0x0         /* default device base address for SST39VF3201/3202 */
#define ChipEraseTime           714286      /* maximum timeout of read cycles for chip-erase, 50ms/70ns */
#define BlockEraseTime          357143      /* maximum timeout of read cycles for block-erase, 25ms/70ns */
#define SectorEraseTime         357143      /* maximum timeout of read cycles for sector-erase, 25ms/70ns */
#define WordProgramTime         143         /* maximum timeout of read cycles for word-program, 10us/70ns */

#define FALSE                   0
#define TRUE                    1
typedef unsigned char           BYTE;
typedef unsigned short int      WORD;
typedef unsigned long           DWORD;    


DWORD  BaseAddrs=DefaultBaseAddress;
// In some cases, system will assign a device base address for flash only at run time.
// This is the reason that we define BaseAddrs as a variable rather than a CONSTANT.

// The C code in this document contains the following routines in order:
//    Name                            Function

DWORD Check_SST_39VF320X(void);       // Check manufacturer and device ID
void  CFI_Query(WORD*);               // Read CFI information
void  SecID_Query(WORD*, WORD*);      // Read both SST SecID and User SecID information
BYTE  Erase_One_Sector(DWORD);        // Erase one sector (2K words)
BYTE  Erase_One_Block (DWORD);        // Erase one block (32K word)
BYTE  Erase_Entire_Chip(void);        // Erase the whole chip
BYTE  Program_One_Word(WORD, DWORD);  // Program one word into device
BYTE  SecID_Lock_Status(void);        // Check User SecID lock status
BYTE  User_SecID_Word_Program(WORD*, DWORD, BYTE); // Program one word into User SecID segment
BYTE  User_SecID_Lock_Out(void);                   // Lock out User SecID segment
void  Erase_Suspend(void);                         // Temporarily suspend one sector-erase or block-erase
BYTE  Erase_Resume(void);                          // Resume suspended sector-erase or block-erase
BYTE  Check_Toggle_Ready (DWORD, DWORD);           // Wait until DQ6 stops toggling
BYTE  Check_Data_Polling (DWORD, WORD, DWORD);     // Wait until DQ7 outputs true data

void Delay_150_Nano_Seconds(void);        // delay 150ns
void Delay_1_Microsecond(void);           // delay 1us
void Delay_20_Micro_Seconds(void);        // delay 20us

/************************************************************************/
/* PROCEDURE:   Check_SST_39VF320X                                      */
/*                                                                      */
/* This procedure decides whether a physical hardware device has a      */
/* SST39VF3201/3202 32 Mbit MPF+ Device installed or not.        		*/
/*                                                                      */
/* Input:                                                               */
/*          None                                                        */
/*                                                                      */
/* Output:                                                              */
/*     00BF235Bh for SST39VF3201,                                       */
/*     00BF235Ah for SST39VF3202,                                       */
/*     Any other value indicates non SST39VF3201/3202.                  */
/*     high word of returned value is vendor ID, low word is device ID. */
/************************************************************************/
DWORD Check_SST_39VF320X(void)
{
    WORD Vendor_ID;
    WORD Device_ID;
    DWORD  ReturnStatus;

//  Issue Software ID Entry command to SST39VF320X
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA;  // 1st write data 0x00AA to device addr 5555H
    *(WORD *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055;  // 2nd write data 0x0055 to device addr 2AAAH
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x0090;  // 3rd write data 0x0090 to device addr 5555H
    Delay_150_Nano_Seconds();                              // delay Tida (max. 150ns) for SST39VF320X

    Vendor_ID  = *(WORD *) (BaseAddrs + 0);                // read vendor ID
    Device_ID  = *(WORD *) (BaseAddrs + 1 * AddrsShift);   // read device ID  

    ReturnStatus = Vendor_ID * 65536 + Device_ID;

 // Issue Software ID Exit command to put SST39VF320X into normal read mode.
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA;  // 1st write data 0x00AA to device addr 5555H
    *(WORD *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055;  // 2nd write data 0x0055 to device addr 2AAAH
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00F0;  // 3rd write data 0x00F0 to device addr 5555H
    Delay_150_Nano_Seconds();                              // then delay Tida (max. 150ns) for SST39VF320X
                                    
    return ReturnStatus;
}

/************************************************************************/
/* PROCEDURE:   CFI_Query                                               */
/*                                                                      */
/* This procedure should be used to query for CFI information           */
/*                                                                      */
/* Input:                                                               */
/*          *CFI	a pointer to store CFI data string (total 37 words)	*/
/*                                                                      */
/* Output:                                                              */
/*          The pointer points to CFI data string.                      */
/************************************************************************/
void CFI_Query(WORD *CFI)
{ 
//  Issue the CFI Query Entry command to SST39VF320X
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA;  // 1st write data 0x00AA to device addr 5555H
    *(WORD *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055;  // 2nd write data 0x0055 to device addr 2AAAH
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x0098;  // 3rd write data 0x0098 to device addr 5555H
    Delay_150_Nano_Seconds( );                             // delay Tida (150ns)

//  retrieve all CFI data string from address 0010H--0034H

    for(BYTE i=0x10; i<=0x34; i++)
	{*CFI = *(WORD *)(BaseAddrs + i * AddrsShift);         // save CFI data into user-defined pointer
     ++CFI;
	}

// Issue CFI Exit command to return SST39VF320X to read mode.

    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA;  // 1st write data 0x00AA to device addr 5555H
    *(WORD *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055;  // 2nd write data 0x0055 to device addr 2AAAH
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00F0;  // 3rd write data 0x00F0 to device addr 5555H
    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	pointer to store SST SecID string (8 words)     */
/*          *User_SecID	pointer to store User SecID string (8 words)	*/
/*                                                                      */
/* Output:                                                              */
/*          pointer SST_SecID points to SST security ID                 */
/*          pointer User_SecID points to user security ID               */
/************************************************************************/
void SecID_Query(WORD *SST_SecID, WORD *User_SecID)
{
//  Issue Query SecID command to SST39VF320X
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x00AA;  // 1st write data 0x00AA to device addr 5555H
    *(WORD *) (BaseAddrs + 0x2AAA * AddrsShift) = 0x0055;  // 2nd write data 0x0055 to device addr 2AAAH
    *(WORD *) (BaseAddrs + 0x5555 * AddrsShift) = 0x0088;  // 3rd write data 0x0088 to device addr 5555H
    Delay_150_Nano_Seconds( );                             // insert delay time = Tida
//  read all Security ID information:
//  SST security ID is from address 000000H to 000007H,
// 	User security ID is from address 000010H to 000017H.

    BYTE i;
    for (i=0; i<=7; i++)
    {
    	 *SST_SecID = *(WORD *) (BaseAddrs + i * AddrsShift);          // read & save SST security ID
         ++SST_SecID;                                                  // point to next word

         *User_SecID = *(WORD *) (BaseAddrs + (i+0x10) * AddrsShift);  // read & save user security ID
         ++User_SecID;								     // point to next word
    }
 // Issue Sec ID Exit command to return SST39VF320X to read mode
    *(WORD *) (BaseAddrs+0x0) = 0x00F0;                                // writing F0h into any address
    Delay_150_Nano_Seconds( );                                         // insert delay time = Tida
}

⌨️ 快捷键说明

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