📄 dataflash.h
字号:
/**** 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;
/**** ReadLockRegister Parameters ****/
struct {
uAddrType udAddr;
ST_uint8 ucpLockRegister;
} ReadLockRegister;
/**** WriteLockRegister Parameters ****/
struct {
uAddrType udAddr;
ST_uint8 ucLockRegister;
} WriteLockRegister;
} ParameterType;
/******************************************************************************
Standard functions
*******************************************************************************/
ReturnType Flash( InstructionType insInstruction, ParameterType *fp );
ReturnType FlashWriteEnable( void );
ReturnType FlashWriteDisable( void );
ReturnType FlashReadDeviceIdentification( ST_uint16 *uwpDeviceIdentification);
ReturnType FlashReadManufacturerIdentification( ST_uint8 *ucpManufacturerIdentification);
ReturnType FlashReadStatusRegister( ST_uint8 *ucpStatusRegister);
ReturnType FlashRead( uAddrType udAddr, ST_uint8 *ucpElements, ST_uint32 udNrOfElementsToRead);
ReturnType FlashFastRead( uAddrType udAddr, ST_uint8 *ucpElements, ST_uint32 udNrOfElementsToRead);
ReturnType FlashPageWrite( uAddrType udAddr, ST_uint8 *pArray , ST_uint16 udNrOfElementsInArray);
ReturnType FlashPageProgram( uAddrType udAddr, ST_uint8 *pArray, ST_uint16 udNrOfElementsInArray );
ReturnType FlashPageErase( uPageType upgPageNr );
ReturnType FlashSectorErase( uSectorType uscSectorNr );
ReturnType FlashBulkErase( void );
ReturnType FlashDeepPowerDown( void );
ReturnType FlashReleaseFromDeepPowerDown( void );
ReturnType FlashWrite( ST_uint32 udAddr, ST_uint8 *pArray, ST_uint32 udNrOfElementsInArray );
ReturnType FlashProgram( ST_uint32 udAddr, ST_uint8 *pArray , ST_uint32 udNrOfElementsInArray);
ReturnType FlashReadLockRegister( ST_uint32 udAddr, ST_uint8 *ucLockRegister );
ReturnType FlashWriteLockRegister( ST_uint32 udAddr, ST_uint8 ucLockRegister );
/******************************************************************************
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 Flash memory address range.
Solution: Check whether the address given is in the valid Flash memory address range.
********************************************************************************
Error Name: Flash_PageEraseFailed
Description: The Page Erase instruction did not complete successfully.
Solution: Try to erase the Page again. If the operation fails again, the device
may be faulty and need to be replaced.
********************************************************************************
Error Name: Flash_PageNrInvalid
Note: The Flash memory is not at fault.
Description: An attempt to select a Page (Parameter) that is not
within the valid range has been made. 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: An attempt to select a Sector(Parameter) that is not
within the valid range has been made. Valid Sector 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 Flash 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 that 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 which are given by the TimeOut
subroutine. That means that the current Flash memory operation is still
within the defined time frame.
********************************************************************************
Error Name: Flash_OperationTimeOut
Description: The Program/Erase Controller algorithm could not complete an
operation successfully. It should have set bit 7 of the Status
Register from 0 to 1, but this did not happen within the predefined
time limit. The operation was therefore cancelled by a timeout.
This may be due to the device that is damaged.
Solution: Try the previous instruction again. If it fails a second time then it
is likely that the device needs 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 Manufacturer and Device Identifications read from
the Flash device in use do not match the expected Identification
values. This means that the source code is not explicitly written for
the currently used Flash chip. It may work, but correct operation is not
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.
********************************************************************************/
/*******************************************************************************
Device Constants
*******************************************************************************/
#define MANUFACTURER_ST (0x20) /* ST Manufacturer Code is 0x20 */
#define ANY_ADDR (0x0) /* Any address offset within the Flash Memory will do */
#ifdef USE_M25PE10 /* The M25PE10 device */
#define EXPECTED_DEVICE (0x8011) /* Device code for the M25PE10 */
#define FLASH_SIZE (0x020000) /* Total device size in Bytes */
#define FLASH_PAGE_COUNT (0x0200) /* Total device size in Pages */
#define FLASH_SECTOR_COUNT (0x02) /* Total device size in Sectors */
#define FLASH_WRITE_BUFFER_SIZE 0x100 /* Write Buffer = 256 bytes */
#define FLASH_MWA 1 /* Minimum Write Access */
#define PW_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Write Operation*/
#define PP_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Program Operation*/
#define PE_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Erase Operation*/
#define SE_TIMEOUT (0x06) /* Timeout in seconds suggested for Sector Erase Operation*/
#define NUM_NV_PAGES (0x08)
#define NUM_SYS_PAGES (0x01)
#define NV_BASE_ADDRESS (0x00)
#define NUM_DL_FALLOW_PAGES (0x08)
#define DL_BASE_ADDRESS ((NUM_NV_PAGES+NUM_SYS_PAGES+NUM_DL_FALLOW_PAGES)*FLASH_WRITE_BUFFER_SIZE)
#define SYSNV_BASE_ADDRESS (NUM_NV_PAGES*FLASH_WRITE_BUFFER_SIZE)
#define DF_PAGESIZE FLASH_WRITE_BUFFER_SIZE
#define DF_SHIFTCOUNT 8
#endif /* USE_M25PE10 */
#ifdef USE_M25PE20 /* The M25PE20 device */
#define EXPECTED_DEVICE (0x8012) /* Device code for the M25PE20 */
#define FLASH_SIZE (0x040000) /* Total device size in Bytes */
#define FLASH_PAGE_COUNT (0x0400) /* Total device size in Pages */
#define FLASH_SECTOR_COUNT (0x04) /* Total device size in Sectors */
#define FLASH_WRITE_BUFFER_SIZE 0x100 /* Write Buffer = 256 bytes */
#define FLASH_MWA 1 /* Minimum Write Access */
#define PW_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Write Operation*/
#define PP_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Program Operation*/
#define PE_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Erase Operation*/
#define SE_TIMEOUT (0x06) /* Timeout in seconds suggested for Sector Erase Operation*/
#endif /* USE_M25PE20 */
#ifdef USE_M25PE40 /* The M25PE40 device */
#define EXPECTED_DEVICE (0x8013) /* Device code for the M25PE40 */
#define FLASH_SIZE (0x080000) /* Total device size in Bytes */
#define FLASH_PAGE_COUNT (0x0800) /* Total device size in Pages */
#define FLASH_SECTOR_COUNT (0x08) /* Total device size in Sectors */
#define FLASH_WRITE_BUFFER_SIZE 0x100 /* Write Buffer = 256 bytes */
#define FLASH_MWA 1 /* Minimum Write Access */
#define PW_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Write Operation*/
#define PP_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Program Operation*/
#define PE_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Erase Operation*/
#define SE_TIMEOUT (0x06) /* Timeout in seconds suggested for Sector Erase Operation*/
#endif /* USE_M25PE40 */
#ifdef USE_M25PE80 /* The M25PE80 device */
#define EXPECTED_DEVICE (0x8014) /* Device code for the M25PE80 */
#define FLASH_SIZE (0x100000) /* Total device size in Bytes */
#define FLASH_PAGE_COUNT (0x1000) /* Total device size in Pages */
#define FLASH_SECTOR_COUNT (0x10) /* Total device size in Sectors */
#define FLASH_SUBSECTOR_COUNT (0x10) /* Total sub-Sector size in Sectors */
#define FLASH_WRITE_BUFFER_SIZE 0x100 /* Write Buffer = 256 bytes */
#define FLASH_MWA 1 /* Minimum Write Access */
#define PW_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Write Operation*/
#define PP_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Program Operation*/
#define PE_TIMEOUT (0x01) /* Timeout in seconds suggested for Page Erase Operation*/
#define SE_TIMEOUT (0x06) /* Timeout in seconds suggested for Sector Erase Operation*/
#define BE_TIMEOUT (0x3D) /* Timeout in seconds suggested for Bulk Erase Operation*/
#endif /* USE_M25PE80 */
/******************************************************************************
External variable declaration
*******************************************************************************/
// none in this version of the release
/*******************************************************************************
Flash Status Register Definitions (see Datasheet)
*******************************************************************************/
enum
{
SPI_FLASH_WIP = 0x01, // write/program/erase in progress indicator
SPI_FLASH_WEL = 0x02 // write enable latch
};
/*******************************************************************************
Specific Function Prototypes
*******************************************************************************/
//typedef unsigned char BOOL;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
uint8 IsFlashBusy(void);
/*******************************************************************************
List of Specific Errors and Return values, Explanations and Help.
*******************************************************************************
// none in this version of the release
********************************************************************************/
#endif /* __C2195__H__ */
/* In order to avoid a repeated usage of the header file */
/*******************************************************************************
End of C2195.h
********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -