Arkadi Rafalovich / SPI_MX25R

Dependents:   Demo_MX25Rxx35F_Serial_NOR_Flash_Testbench mbed-lorawan-pulga mbed-lorawan-pulga-serial_rx mbed-lorawan-pulga-gps-added_shared

Fork of SPI_MX25R by alec cohen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SPI_MX25R.h Source File

SPI_MX25R.h

00001 #ifndef _SPI_MX25R_H_
00002 #define _SPI_MX25R_H_
00003  
00004 #include "mbed.h"
00005  
00006  /**
00007  Page Defines, write read based on page size
00008  */
00009  #define MX25R_PAGES 0x7FFF // total memory size - Addresses 0x7FFFFF
00010 /**
00011  * Macronix Serial Flash Low Power Memories
00012  * SPI_MX25R Series SPI-Flash Memory
00013  */
00014 #define CS_LOW         0    // SPI CS# (Chip Select) Setting 
00015 #define CS_HIGH        1    // SPI CS# (Chip Select) Setting 
00016 #define DUMMY          0x00 // Dummy byte which can be changed to any value
00017 /**
00018  * MX25R Series Register Command Table. 
00019  * x2 and x4 commands not currently supported with FRDM K64F platform
00020  */
00021 #define CMD_READ      0x03  // x1 Normal Read Data Byte 
00022 #define CMD_FREAD     0x0B  // x1 Fast Read Data Byte
00023 #define CMD_2READ     0xBB  // x2 2READ 
00024 #define CMD_DREAD     0x3B  // x2 DREAD 
00025 #define CMD_4READ     0xEB  // x4 4READ 
00026 #define CMD_QREAD     0x6B  // x4 QREAD 
00027 #define CMD_PP        0x02  // Page Program 
00028 #define CMD_4PP       0x38  // x4 PP
00029 #define CMD_SE        0x20  // 4KB Sector Erase 
00030 #define CMD_32KBE     0x52  // 32KB Block Erase 
00031 #define CMD_BE        0xD8  // 64KB Block Erase 
00032 #define CMD_CE        0xC7  // Chip Erase 
00033 #define CMD_RDSFDP    0x5A  // Read SFDP 
00034 #define CMD_WREN      0x06  // Write Enable 
00035 #define CMD_WRDI      0x04  // Write Disable
00036 #define CMD_RDSR      0x05  // Read Status Register 
00037 #define CMD_RDCR      0x15  // Read Configuration Register 
00038 #define CMD_WRSR      0x01  // Write Status Register
00039 #define CMD_PESUS     0xB0  // Program/Erase Suspend 
00040 #define CMD_PERES     0x30  // Program/Erase Resume
00041 #define CMD_DP        0xB9  // Enter Deep Power Down 
00042 #define CMD_SBL       0xC0  // Set Burst Length 
00043 #define CMD_RDID      0x9F  // Read Manufacturer and JDEC Device ID 
00044 #define CMD_REMS      0x90  // Read Electronic Manufacturer and Device ID
00045 #define CMD_RES       0xAB  // Read Electronic ID
00046 #define CMD_ENSO      0xB1  // Enter Secure OTP
00047 #define CMD_EXSO      0xC1  // Exit Secure OTP
00048 #define CMD_RDSCUR    0x2B  // Read Security Register
00049 #define CMD_WRSCUR    0x2F  // Write Security Register
00050 #define CMD_NOP       0x00  // No Operation
00051 #define CMD_RSTEN     0x66  // Reset Enable 
00052 #define CMD_RST       0x99  // Reset 
00053 #define CMD_RRE       0xFF  // Release Read Enhanced Mode
00054  
00055  
00056 class SPI_MX25R
00057 {
00058 public:
00059 /**
00060  * Macronix MX25R Low Power and Wide Vcc SPI-Flash Memory Family 
00061  *
00062  * @param SI/SIO0 SPI_MOSI pin
00063  * @param SO/SI01 SPI_MISO pin
00064  * @param SCLK    SPI_CLK pin
00065  * @param CSb     SPI_CS  pin
00066  */
00067  SPI_MX25R(PinName mosi, PinName miso, PinName sclk, PinName cs) ;
00068  
00069  ~SPI_MX25R() ;
00070  
00071  SPI m_spi;
00072  DigitalOut m_cs ;
00073  int _mode ;
00074  
00075 /// Write Enable
00076   void writeEnable(void) ;
00077   
00078 /// Write Disable
00079   void writeDisable(void) ;
00080   
00081 /// Reset Enable
00082   void resetEnable(void) ;
00083   
00084 /// Reset 
00085   void reset(void) ;
00086  
00087 /// Program or Erase Suspend
00088   void pgmersSuspend(void) ;
00089  
00090 /// Program or Erase Resume
00091   void pgmersResume(void) ;
00092  
00093 /// Enter Deep Power Down
00094   void deepPowerdown(void) ;
00095  
00096 /// Set Burst Length 
00097   void setBurstlength(void) ;
00098  
00099 /// Release from Read Enhanced Mode 
00100   void releaseReadenhaced(void) ;
00101  
00102 /// No Operation 
00103   void noOperation(void) ;
00104  
00105 /// Enter OTP Area 
00106   void enterSecureOTP(void) ;
00107  
00108 /// Exit OTP Area 
00109   void exitSecureOTP(void) ;
00110  
00111 /// Chip Erase
00112   void chipErase(void) ;
00113   
00114 /// Write Status and Configuration Reg 1 and 2
00115   void writeStatusreg(int addr) ;
00116   
00117 /// Write Security Reg
00118   void writeSecurityreg(int addr) ;
00119   
00120 /** Page Program
00121  *
00122  * @param int addr start address
00123  * @param uint8_t *data data buffer
00124  * @param int numData the number of data to be written
00125  */
00126   void programPage(int addr, uint8_t *data, int numData) ;
00127   
00128 /** Sector Erase
00129  *
00130  * @param int addr specify the sector to be erased
00131  */
00132   void sectorErase(int addr) ;
00133   
00134 /** Block Erase
00135  *
00136  * @param int addr specify the sector to be erased
00137  */
00138   void blockErase(int addr) ;
00139   
00140 /** 32KB Block Erase
00141  *
00142  * @param int addr specify the sector to be erased
00143  */
00144   void blockErase32KB(int addr) ;
00145   
00146 /** Read Status Register
00147  *
00148  * @returns uint8_t status register value
00149  */
00150   uint8_t readStatus(void) ;
00151   
00152 /** Read Security Register
00153  *
00154  * @returns uint8_t security register value
00155  */
00156   uint8_t readSecurity(void) ;
00157 
00158 /** Read Manufacturer and JEDEC Device ID
00159  *
00160  * @returns uint32_t Manufacturer ID, Mem Type, Device ID
00161  */
00162   uint32_t readID(void) ;
00163   
00164 /** Read Electronic Manufacturer and Device ID
00165  *
00166  * @returns uint32_t Manufacturer ID, Device ID
00167  */
00168   uint32_t readREMS(void) ;
00169   
00170 /** Read Electronic ID
00171  *
00172  * @returns uint8_t Device ID
00173  */
00174   uint8_t readRES(void) ;
00175   
00176 /** Read Configuration Register
00177  *
00178  * @returns uint32_t configuration register value
00179  */
00180   uint32_t readConfig(void) ;
00181   uint8_t readSFDP(int addr) ;        
00182   uint8_t readFREAD(int addr) ; 
00183   uint8_t read8(int addr) ;
00184   void write8(int addr, uint8_t data) ;
00185   // read sequential n bytes
00186   void readNBytes(int addr, uint8_t *data, int nBytes);
00187   private:
00188  
00189 } ;
00190 #endif // _SPI_MX25R_H_