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

📄 c2082.h

📁 Description: Library routines for the M25P05A, M25P10A, M25P20, M25P40, M25P80, M25P16, M25P32, M25P
💻 H
📖 第 1 页 / 共 2 页
字号:
	SPI_FLASH_INS_DP          = 0xB9,		// deep power-down
	#endif

    #ifdef USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE
	SPI_FLASH_INS_RDID        = 0x9F,		// read identification
    #endif

	SPI_FLASH_INS_BE          = 0xC7		// bulk erase
};


/******** InstructionsType ********/ 

typedef enum {
   WriteEnable,
   WriteDisable,
   ReadDeviceIdentification, 
   #ifdef USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE
   ReadManufacturerIdentification, 
   #endif
   ReadStatusRegister,
   WriteStatusRegister,
   Read,
   FastRead,
   PageProgram,
   SectorErase,
   BulkErase,
   
   #ifndef NO_DEEP_POWER_DOWN_SUPPORT
   DeepPowerDown,
   ReleaseFromDeepPowerDown,
   #endif
   
   Program
} InstructionType; 

/******** ReturnType ********/ 

typedef enum { 
   Flash_AddressInvalid, 
   Flash_MemoryOverflow, 
   Flash_PageEraseFailed, 
   Flash_PageNrInvalid, 
   Flash_SectorNrInvalid, 
   Flash_FunctionNotSupported,
   Flash_NoInformationAvailable,
   Flash_OperationOngoing, 
   Flash_OperationTimeOut, 
   Flash_ProgramFailed, 
   Flash_WrongType,
   Flash_Success
} ReturnType; 

/******** SectorType ********/ 

typedef ST_uint8 uSectorType; 
 
/******** PageType ********/ 

typedef ST_uint16 uPageType; 
 
/******** AddrType ********/ 

typedef ST_uint32 uAddrType; 
 
/******** ParameterType ********/ 
 
typedef union { 
 
    /**** WriteEnable has no parameters ****/ 
 
    /**** WriteDisable has no parameters ****/ 
 
    /**** ReadDeviceIdentification Parameters ****/ 
    struct { 
      ST_uint16 ucDeviceIdentification; 
    } ReadDeviceIdentification; 
 
    /**** ReadManufacturerIdentification Parameters ****/ 
    struct { 
      ST_uint8 ucManufacturerIdentification; 
    } ReadManufacturerIdentification; 

    /**** ReadStatusRegister Parameters ****/ 
    struct { 
      ST_uint8 ucStatusRegister; 
    } ReadStatusRegister;  

    /**** WriteStatusRegister Parameters ****/ 
    struct { 
      ST_uint8 ucStatusRegister; 
    } WriteStatusRegister;  

    /**** Read Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsToRead;         
      void *pArray; 
    } Read; 

    /**** FastRead Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsToRead;         
      void *pArray; 
    } FastRead; 

    /**** PageWrite Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsInArray;         
      void *pArray; 
    } PageWrite; 
    
    /**** PageProgram Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsInArray;         
      void *pArray; 
    } PageProgram; 

    /**** PageErase Parameters ****/ 
    struct { 
      uPageType upgPageNr; 
    } PageErase; 

    /**** SectorErase Parameters ****/ 
    struct { 
      uSectorType ustSectorNr; 
    } SectorErase; 

    /**** Write Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsInArray;         
      void *pArray; 
    } Write; 
    
    /**** Program Parameters ****/ 
    struct { 
      uAddrType udAddr; 
      ST_uint32 udNrOfElementsInArray;         
      void *pArray; 
    } Program; 

} ParameterType; 
 

/******************************************************************************
    Standard functions
*******************************************************************************/ 
  ReturnType  Flash( InstructionType insInstruction, ParameterType *fp );
  ReturnType  FlashWriteEnable( void );
  ReturnType  FlashWriteDisable( void );
  ReturnType  FlashReadDeviceIdentification( ST_uint16 *uwpDeviceIdentification);
#ifdef USE_JEDEC_STANDARD_TWO_BYTE_SIGNATURE
  ReturnType  FlashReadManufacturerIdentification( ST_uint8 *ucpManufacturerIdentification);
#endif
  ReturnType  FlashReadStatusRegister( ST_uint8 *ucpStatusRegister);
  ReturnType  FlashWriteStatusRegister( ST_uint8 ucStatusRegister);
  ReturnType  FlashRead( uAddrType udAddr, ST_uint8 *ucpElements, ST_uint32 udNrOfElementsToRead);
  ReturnType  FlashFastRead( uAddrType udAddr, ST_uint8 *ucpElements, ST_uint32 udNrOfElementsToRead);
  ReturnType  FlashPageProgram( uAddrType udAddr, ST_uint8 *pArray, ST_uint16 udNrOfElementsInArray );
  ReturnType  FlashSectorErase( uSectorType uscSectorNr );
  ReturnType  FlashBulkErase( void );
#ifndef NO_DEEP_POWER_DOWN_SUPPORT
  ReturnType  FlashDeepPowerDown( void );
  ReturnType  FlashReleaseFromDeepPowerDown( void );
#endif
  ReturnType  FlashProgram( ST_uint32 udAddr, ST_uint8 *pArray , ST_uint32 udNrOfElementsInArray);

/******************************************************************************
    Utility functions
*******************************************************************************/ 
#ifdef VERBOSE
   ST_sint8 *FlashErrorStr( ReturnType rErrNum );
#endif

  ReturnType  FlashTimeOut( ST_uint32 udSeconds );
 
/******************************************************************************* 
List of Errors and Return values, Explanations and Help. 
******************************************************************************** 

Error Name:   Flash_AddressInvalid 
Description:  The address given is out of the range of the Flash device. 
Solution:     Check whether the address is in the valid range of the 
              Flash device. 
******************************************************************************** 
 
Error Name:   Flash_PageEraseFailed 
Description:  The Page erase Instruction did not complete successfully. 
Solution:     Try to erase the Page again. If this fails once more, the device 
              may be faulty and need to be replaced. 
******************************************************************************** 
 
Error Name:   Flash_PageNrInvalid 
Note:         The Flash memory is not at fault.
Description:  A Page has been selected (Parameter), which is not 
              within the valid range. Valid Page numbers are from 0 to
              FLASH_PAGE_COUNT - 1. 
Solution:     Check that the Page number given is in the valid range. 
******************************************************************************** 
 
Error Name:   Flash_SectorNrInvalid 
Note:         The Flash memory is not at fault. 
Description:  A Sector has been selected (Parameter), which is not 
              within the valid range. Valid Page numbers are from 0 to
              FLASH_SECTOR_COUNT - 1. 
Solution:     Check that the Sector number given is in the valid range. 
******************************************************************************** 

Return Name:  Flash_FunctionNotSupported 
Description:  The user has attempted to make use of a functionality not 
              available on this Fash device (and thus not provided by the
              software drivers).   
Solution:     This may happen after changing Flash SW Drivers in existing 
              environments. For example an application tries to use a
              functionality which is no longer provided with the new device. 
******************************************************************************** 
 
Return Name:  Flash_NoInformationAvailable
Description:  The system cannot give any additional information about the error.
Solution:     None
******************************************************************************** 
 
Error Name:   Flash_OperationOngoing 
Description:  This message is one of two messages that are given by the TimeOut 
              subroutine. It means that the ongoing Flash operation is still within
              the defined time frame.  
******************************************************************************** 
 
Error Name:   Flash_OperationTimeOut 
Description:  The Program/Erase Controller algorithm could not finish an 
              operation successfully. It should have set bit 7 of the Status
              Register from 0 to 1, but that did not happen within a predetermined
              time. The program execution was therefore cancelled by a
              timeout. This may be because the device is damaged.  
Solution:     Try the previous Instruction again. If it fails a second time then it 
              is likely that the device will need to be replaced. 
******************************************************************************** 
 
Error Name:   Flash_ProgramFailed 
Description:  The value that should be programmed has not been written correctly 
              to the Flash memory. 
Solutions:    Make sure that the Page which is supposed to receive the value 
              was erased successfully before programming. Try to erase the Page and
              to program the value again. If it fails again then the device may
              be faulty. 
******************************************************************************** 

Error Name:   Flash_WrongType 
Description:  This message appears if the Manufacture and Device Identifications read from 
              the current Flash device do not match the expected identifier
              codes. This means that the source code is not explicitely written for
              the currently used Flash chip. It may work, but the operation cannot be
              guaranteed. 
Solutions:    Use a different Flash chip with the target hardware or contact 
              STMicroelectronics for a different source code library. 
********************************************************************************

Return Name:  Flash_Success 
Description:  This value indicates that the Flash memory Instruction was executed 
              correctly. 
********************************************************************************/ 

/******************************************************************************
    External variable declaration
*******************************************************************************/ 

// none in this version of the release

/*******************************************************************************
Flash Status Register Definitions (see Datasheet)
*******************************************************************************/
enum
{
	SPI_FLASH_SRWD	= 0x80,				// Status Register Write Protect
	SPI_FLASH_BP2	= 0x10,				// Block Protect Bit2
	SPI_FLASH_BP1	= 0x08,				// Block Protect Bit1
	SPI_FLASH_BP0	= 0x04,				// Block Protect Bit0
	SPI_FLASH_WEL	= 0x02,				// write enable latch
	SPI_FLASH_WIP	= 0x01				// write/program/erase in progress indicator
};

/*******************************************************************************
Specific Function Prototypes
*******************************************************************************/
typedef unsigned char BOOL;

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

BOOL IsFlashBusy();

/*******************************************************************************
List of Specific Errors and Return values, Explanations and Help.
*******************************************************************************

// none in this version of the release
********************************************************************************/

#endif /* __c2082__H__  */
/* In order to avoid a repeated usage of the header file */

/*******************************************************************************  
     End of c2082.h
********************************************************************************/

⌨️ 快捷键说明

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