資源簡介
M25P64的驅動程序,有頁的讀寫及塊的擦除等操作

代碼片段和文件信息
///////////////////////////////////////////////////////////////
//
//?VisualDSP++?4.0?“Flash?Programmer“?flash?driver?for?use?to
//?programm?the?STMicro.?M25P64?SPI?flash?device.
//?M25P64?--?64Mbit?(?8M?x?8?)
//?128?(sectors)?x?256?(pages)?x?256?(bytes)
//?
///////////////////////////////////////////////////////////////
//?error?enum
#include?“Errors.h“
#include?
#include?
//?#defines
#define?TRUE 0x1
#define?FALSE 0x0
//?#define?NULL 0x0
#define?BUFFER_SIZE 0x600
#define NUM_SECTORS? 128 //?number?of?sectors?in?the?M25P20?flash?device
//Application?definitions
#define?COMMON_SPI_SETTINGS?(SPE|MSTR|CPHA|CPOL)?//Settings?to?the?SPI_CTL
#define?TIMOD01?(0x01) //stes?the?SPI?to?work?with?core?instructions
#define?BAUD_RATE_DIVISOR?200
//Flash?commands
#define?SPI_WREN????????????(0x06)??//Set?Write?Enable?Latch
#define?SPI_WRDI????????????(0x04)??//Reset?Write?Enable?Latch
#define?SPI_RDSR????????????(0x05)??//Read?Status?Register
#define?SPI_WRSR????????????(0x01)??//Write?Status?Register
#define?SPI_READ????????????(0x03)??//Read?data?from?memory
#define?SPI_PP??????????????(0x02)??//Program?Data?into?memory
#define?SPI_SE??????????????(0xD8)??//Erase?one?sector?in?memory
#define?SPI_BE??????????????(0xC7)??//Erase?all?memory
#define?WIP (0x1) //Check?the?write?in?progress?bit?of?the?SPI?status?register
#define?WEL (0x2) //Check?the?write?enable?bit?of?the?SPI?status?register
#define?TIMEOUT????????35000*64
//?structure?for?flash?sector?information
//?for?the?purpose?of?erase?single?sectors?of?the?SPI?flash?the?right?sector?must?be?chosen
typedef?struct?_SECTORLOCATION
{
long?lStartOff;
long?lEndOff;
}SECTORLOCATION;
//?Flash?Programmer?commands
//?The?VisualDSP++?flash?progammer?plug-in?“Flash?Programmer?Tool“?will?send?commands
//?to?this?driver.?These?commands?will?be?taken?to?execute?the?corresponding?C?function
//?The?commands?are?used?at?the?switch?case?below.
typedef?enum
{
NO_COMMAND //?0
GET_CODES //?1
RESET //?2
WRITE //?3
FILL //?4
ERASE_ALL //?5
ERASE_SECT //?6
READ //?7
GET_SECTNUM //?8
}enProgCmds;
//?function?prototypes
ERROR_CODE?SetupForFlash();
ERROR_CODE?GetCodes();
ERROR_CODE?Wait_For_Status(char?Statusbit);
ERROR_CODE?Wait_For_WEL();
ERROR_CODE?ResetFlash();
ERROR_CODE?EraseFlash();
ERROR_CODE?EraseBlock(?int?nBlock?);
ERROR_CODE?FillData(?unsigned?long?ulStart?long?lCount?long?lStride?int?*pnData?);
ERROR_CODE?ReadData(??unsigned?long?ulStart?long?lCount?long?lStride?int?*pnData??);
ERROR_CODE?WriteData(?unsigned?long?ulStart?long?lCount?long?lStride?int?*pnData?);
ERROR_CODE?GetSectorNumber(?unsigned?long?ulOffset?int?*pnSector?);
ERROR_CODE?WriteFlash?(?unsigned?long?StartAddr?long?Count?long?Stride?int?*pnData?long?*pnWriteCount?);
char?ReadStatusRegister(void);
void?Wait_For_SPIF(void);
void?SetupSPI(?const?int?spi_setting?);
void?SPI_OF
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????26540??2010-10-22?11:07??M25P64.c
-----------?---------??----------?-----??----
????????????????26540????????????????????1
評論
共有 條評論