SPI Flash AT45DBXXXD

Fork of at45db161d by Suga koubou

Committer:
LeoHsueh
Date:
Fri Apr 17 11:49:27 2015 +0000
Revision:
9:8b1cf34d290e
Parent:
8:1ec3997fe258
Fix inactive.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okini3939 0:2e953bbaf3a5 1 /**
okini3939 0:2e953bbaf3a5 2 * @file at45db161d.h
okini3939 0:2e953bbaf3a5 3 * @brief AT45DB161D module
okini3939 0:2e953bbaf3a5 4 **/
LeoHsueh 6:1872f591d604 5
LeoHsueh 6:1872f591d604 6 #ifndef AT45DB161D_H_
LeoHsueh 6:1872f591d604 7 #define AT45DB161D_H_
okini3939 0:2e953bbaf3a5 8
okini3939 0:2e953bbaf3a5 9 #include "mbed.h"
okini3939 0:2e953bbaf3a5 10
okini3939 0:2e953bbaf3a5 11 /**
okini3939 0:2e953bbaf3a5 12 * @brief at45db161d module
okini3939 0:2e953bbaf3a5 13 * @todo
okini3939 0:2e953bbaf3a5 14 * - TESTS!
okini3939 0:2e953bbaf3a5 15 * - Protection and Security Commands
okini3939 0:2e953bbaf3a5 16 * - Auto Page Rewrite through Buffer 1
okini3939 0:2e953bbaf3a5 17 * - Auto Page Rewrite through Buffer 2
okini3939 0:2e953bbaf3a5 18 **/
LeoHsueh 6:1872f591d604 19 class ATD45DB161D {
okini3939 0:2e953bbaf3a5 20 public:
okini3939 0:2e953bbaf3a5 21 /**
okini3939 0:2e953bbaf3a5 22 * @brief ID structure
okini3939 0:2e953bbaf3a5 23 * This structure contains various informations about the
okini3939 0:2e953bbaf3a5 24 * dataflash chip being used.
okini3939 0:2e953bbaf3a5 25 **/
LeoHsueh 7:2f9d8b47704f 26 typedef struct {
LeoHsueh 6:1872f591d604 27 uint8_t manufacturer; /**< Manufacturer id **/
LeoHsueh 6:1872f591d604 28 uint8_t device[2]; /**< Device id **/
LeoHsueh 6:1872f591d604 29 uint8_t extendedInfoLength; /**< Extended device information string length **/
LeoHsueh 7:2f9d8b47704f 30 uint16_t pageSize, pageLength;
LeoHsueh 7:2f9d8b47704f 31 } Info;
LeoHsueh 5:ef7247c6f073 32
LeoHsueh 5:ef7247c6f073 33 /**
LeoHsueh 5:ef7247c6f073 34 * ATD45DBxxxD
LeoHsueh 5:ef7247c6f073 35 */
LeoHsueh 5:ef7247c6f073 36 ATD45DB161D(SPI *spi, PinName cs);
okini3939 0:2e953bbaf3a5 37
okini3939 0:2e953bbaf3a5 38 /**
okini3939 0:2e953bbaf3a5 39 * Read status register
okini3939 0:2e953bbaf3a5 40 * @return The content of the status register
okini3939 0:2e953bbaf3a5 41 * **/
okini3939 0:2e953bbaf3a5 42 uint8_t ReadStatusRegister();
okini3939 0:2e953bbaf3a5 43
okini3939 0:2e953bbaf3a5 44 /**
okini3939 0:2e953bbaf3a5 45 * Read Manufacturer and Device ID
okini3939 0:2e953bbaf3a5 46 * @note if id.extendedInfoLength is not equal to zero,
okini3939 0:2e953bbaf3a5 47 * successive calls to spi_transfer(0xff) will return
okini3939 0:2e953bbaf3a5 48 * the extended device information string bytes.
okini3939 0:2e953bbaf3a5 49 * @param id Pointer to the ID structure to initialize
okini3939 0:2e953bbaf3a5 50 **/
LeoHsueh 7:2f9d8b47704f 51 ATD45DB161D::Info *getInfo();
LeoHsueh 6:1872f591d604 52
okini3939 0:2e953bbaf3a5 53 /**
okini3939 0:2e953bbaf3a5 54 * A main memory page read allows the user to read data directly from
okini3939 0:2e953bbaf3a5 55 * any one of the 4096 pages in the main memory, bypassing both of the
okini3939 0:2e953bbaf3a5 56 * data buffers and leaving the contents of the buffers unchanged.
okini3939 0:2e953bbaf3a5 57 * @param page Page of the main memory to read
okini3939 0:2e953bbaf3a5 58 * @param offset Starting byte address within the page
okini3939 0:2e953bbaf3a5 59 **/
okini3939 0:2e953bbaf3a5 60 void ReadMainMemoryPage(uint16_t page, uint16_t offset);
okini3939 0:2e953bbaf3a5 61
okini3939 0:2e953bbaf3a5 62 /**
okini3939 0:2e953bbaf3a5 63 * Sequentially read a continuous stream of data.
okini3939 0:2e953bbaf3a5 64 * @param page Page of the main memory where the sequential read will start
okini3939 0:2e953bbaf3a5 65 * @param offset Starting byte address within the page
okini3939 0:2e953bbaf3a5 66 * @param low If true the read operation will be performed in low speed mode (and in high speed mode if it's false).
okini3939 0:2e953bbaf3a5 67 * @note The legacy mode is not currently supported
okini3939 0:2e953bbaf3a5 68 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 69 **/
okini3939 0:2e953bbaf3a5 70 void ContinuousArrayRead(uint16_t page, uint16_t offset, uint8_t low);
okini3939 0:2e953bbaf3a5 71
LeoHsueh 8:1ec3997fe258 72 void readBuffer(uint16_t addr, void *buf, uint16_t len);
??? 3:82157896d90d 73
LeoHsueh 8:1ec3997fe258 74 void writeBuffer(uint16_t addr, void *buf, uint16_t len);
??? 3:82157896d90d 75
okini3939 0:2e953bbaf3a5 76 /**
okini3939 0:2e953bbaf3a5 77 * Read the content of one of the SRAM data buffers (in low or high speed mode).
okini3939 0:2e953bbaf3a5 78 * @param bufferNum Buffer to read (1 or 2)
okini3939 0:2e953bbaf3a5 79 * @param offset Starting byte within the buffer
okini3939 0:2e953bbaf3a5 80 * @param low If true the read operation will be performed in low speed mode (and in high speed mode if it's false).
okini3939 0:2e953bbaf3a5 81 **/
okini3939 0:2e953bbaf3a5 82 void BufferRead(uint8_t bufferNum, uint16_t offset, uint8_t low);
okini3939 0:2e953bbaf3a5 83
okini3939 0:2e953bbaf3a5 84 /**
okini3939 0:2e953bbaf3a5 85 * Write data to one of the SRAM data buffers. Any further call to
okini3939 0:2e953bbaf3a5 86 * spi_tranfer will return bytes contained in the data buffer until
okini3939 0:2e953bbaf3a5 87 * a low-to-high transition is detected on the CS pin. If the end of
okini3939 0:2e953bbaf3a5 88 * the data buffer is reached, the device will wrap around back to the
okini3939 0:2e953bbaf3a5 89 * beginning of the buffer.
okini3939 0:2e953bbaf3a5 90 * @param bufferNum Buffer to read (1 or 2)
okini3939 0:2e953bbaf3a5 91 * @param offset Starting byte within the buffer
okini3939 0:2e953bbaf3a5 92 **/
okini3939 0:2e953bbaf3a5 93 void BufferWrite(uint8_t bufferNum, uint16_t offset);
LeoHsueh 6:1872f591d604 94
okini3939 0:2e953bbaf3a5 95 /**
okini3939 0:2e953bbaf3a5 96 * Transfer data from buffer 1 or 2 to main memory page.
okini3939 0:2e953bbaf3a5 97 * @param bufferNum Buffer to use (1 or 2)
okini3939 0:2e953bbaf3a5 98 * @param page Page where the content of the buffer will transfered
okini3939 0:2e953bbaf3a5 99 * @param erase If set the page will be first erased before the buffer transfer.
okini3939 0:2e953bbaf3a5 100 * @note If erase is equal to zero, the page must have been previously erased using one of the erase command (Page or Block Erase).
okini3939 0:2e953bbaf3a5 101 **/
LeoHsueh 6:1872f591d604 102 void BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase);
okini3939 0:2e953bbaf3a5 103
okini3939 0:2e953bbaf3a5 104 /**
okini3939 0:2e953bbaf3a5 105 * Transfer a page of data from main memory to buffer 1 or 2.
okini3939 0:2e953bbaf3a5 106 * @param page Main memory page to transfer
okini3939 0:2e953bbaf3a5 107 * @param buffer Buffer (1 or 2) where the data will be written
okini3939 0:2e953bbaf3a5 108 **/
okini3939 0:2e953bbaf3a5 109 void PageToBuffer(uint16_t page, uint8_t bufferNum);
okini3939 0:2e953bbaf3a5 110
okini3939 0:2e953bbaf3a5 111 /**
okini3939 0:2e953bbaf3a5 112 * Erase a page in the main memory array.
okini3939 0:2e953bbaf3a5 113 * @param page Page to erase
okini3939 0:2e953bbaf3a5 114 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 115 **/
okini3939 0:2e953bbaf3a5 116 void PageErase(uint16_t page);
LeoHsueh 6:1872f591d604 117
okini3939 0:2e953bbaf3a5 118 /**
okini3939 0:2e953bbaf3a5 119 * Erase a block of eight pages at one time.
okini3939 0:2e953bbaf3a5 120 * @param block Index of the block to erase
okini3939 0:2e953bbaf3a5 121 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 122 **/
okini3939 0:2e953bbaf3a5 123 void BlockErase(uint16_t block);
okini3939 0:2e953bbaf3a5 124
okini3939 0:2e953bbaf3a5 125 /**
okini3939 0:2e953bbaf3a5 126 * Erase a sector in main memory. There are 16 sector on the
okini3939 0:2e953bbaf3a5 127 * at45db161d and only one can be erased at one time.
okini3939 0:2e953bbaf3a5 128 * @param sector Sector to erase
okini3939 0:2e953bbaf3a5 129 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 130 **/
okini3939 0:2e953bbaf3a5 131 void SectoreErase(uint8_t sector);
okini3939 0:2e953bbaf3a5 132
okini3939 0:2e953bbaf3a5 133 /**
okini3939 0:2e953bbaf3a5 134 * Erase the entire chip memory. Sectors proteced or locked down will
okini3939 0:2e953bbaf3a5 135 * not be erased.
okini3939 0:2e953bbaf3a5 136 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 137 **/
okini3939 0:2e953bbaf3a5 138 void ChipErase();
okini3939 0:2e953bbaf3a5 139
okini3939 0:2e953bbaf3a5 140 /**
okini3939 0:2e953bbaf3a5 141 * This a combination of Buffer Write and Buffer to Page with
okini3939 0:2e953bbaf3a5 142 * Built-in Erase.
okini3939 0:2e953bbaf3a5 143 * @note You must call EndAndWait in order to start transfering data from buffer to page
okini3939 0:2e953bbaf3a5 144 * @param page Page where the content of the buffer will transfered
okini3939 0:2e953bbaf3a5 145 * @param offset Starting byte address within the buffer
okini3939 0:2e953bbaf3a5 146 * @param bufferNum Buffer to use (1 or 2)
okini3939 0:2e953bbaf3a5 147 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 148 **/
okini3939 0:2e953bbaf3a5 149 void BeginPageWriteThroughBuffer(uint16_t page, uint16_t offset, uint8_t bufferNum);
LeoHsueh 6:1872f591d604 150
okini3939 0:2e953bbaf3a5 151 /**
okini3939 0:2e953bbaf3a5 152 * Perform a low-to-high transition on the CS pin and then poll
okini3939 0:2e953bbaf3a5 153 * the status register to check if the dataflash is busy.
okini3939 0:2e953bbaf3a5 154 **/
okini3939 0:2e953bbaf3a5 155 void EndAndWait();
okini3939 0:2e953bbaf3a5 156
okini3939 0:2e953bbaf3a5 157 /**
okini3939 0:2e953bbaf3a5 158 * Compare a page of data in main memory to the data in buffer 1 or 2.
okini3939 0:2e953bbaf3a5 159 * @param page Page to test
okini3939 0:2e953bbaf3a5 160 * @param bufferNum Buffer number
okini3939 0:2e953bbaf3a5 161 * @return
okini3939 0:2e953bbaf3a5 162 * - 1 if the page and the buffer contains the same data
okini3939 0:2e953bbaf3a5 163 * - 0 else
okini3939 0:2e953bbaf3a5 164 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 165 **/
okini3939 0:2e953bbaf3a5 166 int8_t ComparePageToBuffer(uint16_t page, uint8_t bufferNum);
okini3939 0:2e953bbaf3a5 167
okini3939 0:2e953bbaf3a5 168 /**
okini3939 0:2e953bbaf3a5 169 * Put the device into the lowest power consumption mode.
okini3939 0:2e953bbaf3a5 170 * Once the device has entered the Deep Power-down mode, all
okini3939 0:2e953bbaf3a5 171 * instructions are ignored except the Resume from Deep
okini3939 0:2e953bbaf3a5 172 * Power-down command.
okini3939 0:2e953bbaf3a5 173 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 174 **/
okini3939 0:2e953bbaf3a5 175 void DeepPowerDown();
okini3939 0:2e953bbaf3a5 176
okini3939 0:2e953bbaf3a5 177 /**
okini3939 0:2e953bbaf3a5 178 * Takes the device out of Deep Power-down mode.
okini3939 0:2e953bbaf3a5 179 * @warning UNTESTED
okini3939 0:2e953bbaf3a5 180 **/
okini3939 0:2e953bbaf3a5 181 void ResumeFromDeepPowerDown();
okini3939 0:2e953bbaf3a5 182
okini3939 0:2e953bbaf3a5 183 private:
okini3939 0:2e953bbaf3a5 184 /* Nothing atm but who knows... */
okini3939 0:2e953bbaf3a5 185
LeoHsueh 5:ef7247c6f073 186 SPI *_spi;
okini3939 0:2e953bbaf3a5 187 DigitalOut _cs;
LeoHsueh 7:2f9d8b47704f 188 Info _info;
??? 3:82157896d90d 189
okini3939 0:2e953bbaf3a5 190 };
okini3939 0:2e953bbaf3a5 191
okini3939 0:2e953bbaf3a5 192 /**
okini3939 0:2e953bbaf3a5 193 * @}
okini3939 0:2e953bbaf3a5 194 **/
okini3939 0:2e953bbaf3a5 195
okini3939 0:2e953bbaf3a5 196 #endif /* AT45DB161D_H */