MX25R6435F Library

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

Committer:
alec1
Date:
Thu Jul 23 17:11:27 2015 +0000
Revision:
2:f72110475fec
Parent:
1:8403da5975cb
Child:
3:b6bb8d236251
added support for cmds REMS, RES, RDSCUR, WRSCUR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alec1 0:a16ad6f5c788 1 #ifndef _SPI_MX25R_H_
alec1 0:a16ad6f5c788 2 #define _SPI_MX25R_H_
alec1 2:f72110475fec 3
alec1 0:a16ad6f5c788 4 #include "mbed.h"
alec1 2:f72110475fec 5
alec1 2:f72110475fec 6 /**
alec1 2:f72110475fec 7 * Macronix Serial Flash Low Power Memories
alec1 2:f72110475fec 8 * SPI_MX25R Series SPI-Flash Memory
alec1 2:f72110475fec 9 */
alec1 2:f72110475fec 10 #define CS_LOW 0 // SPI CS# (Chip Select) Setting
alec1 2:f72110475fec 11 #define CS_HIGH 1 // SPI CS# (Chip Select) Setting
alec1 2:f72110475fec 12 #define DUMMY 0x00 // Dummy byte which can be changed to any value
alec1 0:a16ad6f5c788 13 /**
alec1 2:f72110475fec 14 * MX25R Series Register Command Table.
alec1 2:f72110475fec 15 * x2 and x4 commands not currently supported with FRDM K64F platform
alec1 0:a16ad6f5c788 16 */
alec1 2:f72110475fec 17 #define CMD_READ 0x03 // x1 Normal Read Data Byte
alec1 2:f72110475fec 18 #define CMD_FREAD 0x0B // x1 Fast Read Data Byte
alec1 2:f72110475fec 19 #define CMD_2READ 0xBB // x2 2READ
alec1 2:f72110475fec 20 #define CMD_DREAD 0x3B // x2 DREAD
alec1 2:f72110475fec 21 #define CMD_4READ 0xEB // x4 4READ
alec1 2:f72110475fec 22 #define CMD_QREAD 0x6B // x4 QREAD
alec1 2:f72110475fec 23 #define CMD_PP 0x02 // Page Program
alec1 2:f72110475fec 24 #define CMD_4PP 0x38 // x4 PP
alec1 2:f72110475fec 25 #define CMD_SE 0x20 // 4KB Sector Erase
alec1 2:f72110475fec 26 #define CMD_32KBE 0x52 // 32KB Block Erase
alec1 2:f72110475fec 27 #define CMD_BE 0xD8 // 64KB Block Erase
alec1 2:f72110475fec 28 #define CMD_CE 0xC7 // Chip Erase
alec1 2:f72110475fec 29 #define CMD_RDSFDP 0x5A // Read SFDP
alec1 2:f72110475fec 30 #define CMD_WREN 0x06 // Write Enable
alec1 2:f72110475fec 31 #define CMD_WRDI 0x04 // Write Disable
alec1 2:f72110475fec 32 #define CMD_RDSR 0x05 // Read Status Register
alec1 2:f72110475fec 33 #define CMD_RDCR 0x15 // Read Configuration Register
alec1 2:f72110475fec 34 #define CMD_WRSR 0x01 // Write Status Register
alec1 2:f72110475fec 35 #define CMD_PESUS 0xB0 // Program/Erase Suspend
alec1 2:f72110475fec 36 #define CMD_PERES 0x30 // Program/Erase Resume
alec1 2:f72110475fec 37 #define CMD_DP 0xB9 // Enter Deep Power Down
alec1 2:f72110475fec 38 #define CMD_SBL 0xC0 // Set Burst Length
alec1 2:f72110475fec 39 #define CMD_RDID 0x9F // Read Manufacturer and JDEC Device ID
alec1 2:f72110475fec 40 #define CMD_REMS 0x90 // Read Electronic Manufacturer and Device ID
alec1 2:f72110475fec 41 #define CMD_RES 0xAB // Read Electronic ID
alec1 2:f72110475fec 42 #define CMD_ENSO 0xB1 // Enter Secure OTP
alec1 2:f72110475fec 43 #define CMD_EXSO 0xC1 // Exit Secure OTP
alec1 2:f72110475fec 44 #define CMD_RDSCUR 0x2B // Read Security Register
alec1 2:f72110475fec 45 #define CMD_WRSCUR 0x2F // Write Security Register
alec1 2:f72110475fec 46 #define CMD_NOP 0x00 // No Operation
alec1 2:f72110475fec 47 #define CMD_RSTEN 0x66 // Reset Enable
alec1 2:f72110475fec 48 #define CMD_RST 0x99 // Reset
alec1 2:f72110475fec 49 #define CMD_RRE 0xFF // Release Read Enhanced Mode
alec1 2:f72110475fec 50
alec1 2:f72110475fec 51
alec1 0:a16ad6f5c788 52 class SPI_MX25R
alec1 0:a16ad6f5c788 53 {
alec1 0:a16ad6f5c788 54 public:
alec1 2:f72110475fec 55 /**
alec1 0:a16ad6f5c788 56 * Macronix MX25R Low Power and Wide Vcc SPI-Flash Memory Family
alec1 0:a16ad6f5c788 57 *
alec1 0:a16ad6f5c788 58 * @param SI/SIO0 SPI_MOSI pin
alec1 0:a16ad6f5c788 59 * @param SO/SI01 SPI_MISO pin
alec1 0:a16ad6f5c788 60 * @param SCLK SPI_CLK pin
alec1 0:a16ad6f5c788 61 * @param CSb SPI_CS pin
alec1 0:a16ad6f5c788 62 */
alec1 0:a16ad6f5c788 63 SPI_MX25R(PinName mosi, PinName miso, PinName sclk, PinName cs) ;
alec1 0:a16ad6f5c788 64
alec1 0:a16ad6f5c788 65 ~SPI_MX25R() ;
alec1 2:f72110475fec 66
alec1 0:a16ad6f5c788 67 SPI m_spi;
alec1 0:a16ad6f5c788 68 DigitalOut m_cs ;
alec1 0:a16ad6f5c788 69 int _mode ;
alec1 0:a16ad6f5c788 70
alec1 0:a16ad6f5c788 71 /// Write Enable
alec1 0:a16ad6f5c788 72 void writeEnable(void) ;
alec1 0:a16ad6f5c788 73
alec1 0:a16ad6f5c788 74 /// Write Disable
alec1 0:a16ad6f5c788 75 void writeDisable(void) ;
alec1 0:a16ad6f5c788 76
alec1 0:a16ad6f5c788 77 /// Reset Enable
alec1 0:a16ad6f5c788 78 void resetEnable(void) ;
alec1 0:a16ad6f5c788 79
alec1 0:a16ad6f5c788 80 /// Reset
alec1 0:a16ad6f5c788 81 void reset(void) ;
alec1 2:f72110475fec 82
alec1 1:8403da5975cb 83 /// Program or Erase Suspend
alec1 1:8403da5975cb 84 void pgmersSuspend(void) ;
alec1 1:8403da5975cb 85
alec1 1:8403da5975cb 86 /// Program or Erase Resume
alec1 1:8403da5975cb 87 void pgmersResume(void) ;
alec1 2:f72110475fec 88
alec1 1:8403da5975cb 89 /// Enter Deep Power Down
alec1 1:8403da5975cb 90 void deepPowerdown(void) ;
alec1 2:f72110475fec 91
alec1 1:8403da5975cb 92 /// Set Burst Length
alec1 1:8403da5975cb 93 void setBurstlength(void) ;
alec1 2:f72110475fec 94
alec1 1:8403da5975cb 95 /// Release from Read Enhanced Mode
alec1 1:8403da5975cb 96 void releaseReadenhaced(void) ;
alec1 2:f72110475fec 97
alec1 1:8403da5975cb 98 /// No Operation
alec1 1:8403da5975cb 99 void noOperation(void) ;
alec1 2:f72110475fec 100
alec1 1:8403da5975cb 101 /// Enter OTP Area
alec1 1:8403da5975cb 102 void enterSecureOTP(void) ;
alec1 1:8403da5975cb 103
alec1 1:8403da5975cb 104 /// Exit OTP Area
alec1 1:8403da5975cb 105 void exitSecureOTP(void) ;
alec1 2:f72110475fec 106
alec1 1:8403da5975cb 107 /// Chip Erase
alec1 1:8403da5975cb 108 void chipErase(void) ;
alec1 0:a16ad6f5c788 109
alec1 1:8403da5975cb 110 /// Write Status and Configuration Reg 1 and 2
alec1 1:8403da5975cb 111 void writeStatusreg(int addr) ;
alec1 0:a16ad6f5c788 112
alec1 2:f72110475fec 113 /// Write Security Reg
alec1 2:f72110475fec 114 void writeSecurityreg(int addr) ;
alec1 2:f72110475fec 115
alec1 0:a16ad6f5c788 116 /** Page Program
alec1 0:a16ad6f5c788 117 *
alec1 0:a16ad6f5c788 118 * @param int addr start address
alec1 0:a16ad6f5c788 119 * @param uint8_t *data data buffer
alec1 0:a16ad6f5c788 120 * @param int numData the number of data to be written
alec1 0:a16ad6f5c788 121 */
alec1 0:a16ad6f5c788 122 void programPage(int addr, uint8_t *data, int numData) ;
alec1 0:a16ad6f5c788 123
alec1 0:a16ad6f5c788 124 /** Sector Erase
alec1 0:a16ad6f5c788 125 *
alec1 0:a16ad6f5c788 126 * @param int addr specify the sector to be erased
alec1 0:a16ad6f5c788 127 */
alec1 0:a16ad6f5c788 128 void sectorErase(int addr) ;
alec1 0:a16ad6f5c788 129
alec1 2:f72110475fec 130 /** Block Erase
alec1 0:a16ad6f5c788 131 *
alec1 0:a16ad6f5c788 132 * @param int addr specify the sector to be erased
alec1 0:a16ad6f5c788 133 */
alec1 0:a16ad6f5c788 134 void blockErase(int addr) ;
alec1 0:a16ad6f5c788 135
alec1 2:f72110475fec 136 /** 32KB Block Erase
alec1 0:a16ad6f5c788 137 *
alec1 0:a16ad6f5c788 138 * @param int addr specify the sector to be erased
alec1 0:a16ad6f5c788 139 */
alec1 0:a16ad6f5c788 140 void blockErase32KB(int addr) ;
alec1 0:a16ad6f5c788 141
alec1 2:f72110475fec 142 /** Read Status Register
alec1 0:a16ad6f5c788 143 *
alec1 0:a16ad6f5c788 144 * @returns uint8_t status register value
alec1 0:a16ad6f5c788 145 */
alec1 0:a16ad6f5c788 146 uint8_t readStatus(void) ;
alec1 0:a16ad6f5c788 147
alec1 2:f72110475fec 148 /** Read Security Register
alec1 2:f72110475fec 149 *
alec1 2:f72110475fec 150 * @returns uint8_t security register value
alec1 2:f72110475fec 151 */
alec1 2:f72110475fec 152 uint8_t readSecurity(void) ;
alec1 2:f72110475fec 153
alec1 2:f72110475fec 154 /** Read Manufacturer and JEDEC Device ID
alec1 0:a16ad6f5c788 155 *
alec1 0:a16ad6f5c788 156 * @returns uint32_t Manufacturer ID, Mem Type, Device ID
alec1 0:a16ad6f5c788 157 */
alec1 0:a16ad6f5c788 158 uint32_t readID(void) ;
alec1 0:a16ad6f5c788 159
alec1 2:f72110475fec 160 /** Read Electronic Manufacturer and Device ID
alec1 2:f72110475fec 161 *
alec1 2:f72110475fec 162 * @returns uint32_t Manufacturer ID, Device ID
alec1 2:f72110475fec 163 */
alec1 2:f72110475fec 164 uint32_t readREMS(void) ;
alec1 2:f72110475fec 165
alec1 2:f72110475fec 166 /** Read Electronic ID
alec1 2:f72110475fec 167 *
alec1 2:f72110475fec 168 * @returns uint8_t Device ID
alec1 2:f72110475fec 169 */
alec1 2:f72110475fec 170 uint8_t readRES(void) ;
alec1 2:f72110475fec 171
alec1 2:f72110475fec 172 /** Read Configuration Register
alec1 0:a16ad6f5c788 173 *
alec1 0:a16ad6f5c788 174 * @returns uint32_t configuration register value
alec1 0:a16ad6f5c788 175 */
alec1 0:a16ad6f5c788 176 uint32_t readConfig(void) ;
alec1 1:8403da5975cb 177 uint8_t readSFDP(int addr) ;
alec1 1:8403da5975cb 178 uint8_t readFREAD(int addr) ;
alec1 0:a16ad6f5c788 179 uint8_t read8(int addr) ;
alec1 0:a16ad6f5c788 180 void write8(int addr, uint8_t data) ;
alec1 0:a16ad6f5c788 181 private:
alec1 2:f72110475fec 182
alec1 0:a16ad6f5c788 183 } ;
alec1 0:a16ad6f5c788 184 #endif // _SPI_MX25R_H_