SPI Flash AT45DBXXXD
Fork of at45db161d by
at45db161d.h@6:1872f591d604, 2015-03-06 (annotated)
- Committer:
- LeoHsueh
- Date:
- Fri Mar 06 09:42:28 2015 +0800
- Revision:
- 6:1872f591d604
- Parent:
- 5:ef7247c6f073
- Child:
- 7:2f9d8b47704f
Format code.
Who changed what in which revision?
User | Revision | Line number | New 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 |
6:1872f591d604 | 26 | struct ID { |
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 **/ |
okini3939 | 0:2e953bbaf3a5 | 30 | }; |
okini3939 | 0:2e953bbaf3a5 | 31 | |
okini3939 | 0:2e953bbaf3a5 | 32 | public: |
LeoHsueh |
5:ef7247c6f073 | 33 | |
LeoHsueh |
5:ef7247c6f073 | 34 | /** |
LeoHsueh |
5:ef7247c6f073 | 35 | * ATD45DBxxxD |
LeoHsueh |
5:ef7247c6f073 | 36 | */ |
LeoHsueh |
5:ef7247c6f073 | 37 | ATD45DB161D(SPI *spi, PinName cs); |
okini3939 | 0:2e953bbaf3a5 | 38 | |
okini3939 | 0:2e953bbaf3a5 | 39 | /** |
okini3939 | 0:2e953bbaf3a5 | 40 | * Read status register |
okini3939 | 0:2e953bbaf3a5 | 41 | * @return The content of the status register |
okini3939 | 0:2e953bbaf3a5 | 42 | * **/ |
okini3939 | 0:2e953bbaf3a5 | 43 | uint8_t ReadStatusRegister(); |
okini3939 | 0:2e953bbaf3a5 | 44 | |
okini3939 | 0:2e953bbaf3a5 | 45 | /** |
okini3939 | 0:2e953bbaf3a5 | 46 | * Read Manufacturer and Device ID |
okini3939 | 0:2e953bbaf3a5 | 47 | * @note if id.extendedInfoLength is not equal to zero, |
okini3939 | 0:2e953bbaf3a5 | 48 | * successive calls to spi_transfer(0xff) will return |
okini3939 | 0:2e953bbaf3a5 | 49 | * the extended device information string bytes. |
okini3939 | 0:2e953bbaf3a5 | 50 | * @param id Pointer to the ID structure to initialize |
okini3939 | 0:2e953bbaf3a5 | 51 | **/ |
okini3939 | 0:2e953bbaf3a5 | 52 | void ReadManufacturerAndDeviceID(struct ATD45DB161D::ID *id); |
LeoHsueh |
6:1872f591d604 | 53 | |
okini3939 | 0:2e953bbaf3a5 | 54 | /** |
okini3939 | 0:2e953bbaf3a5 | 55 | * A main memory page read allows the user to read data directly from |
okini3939 | 0:2e953bbaf3a5 | 56 | * any one of the 4096 pages in the main memory, bypassing both of the |
okini3939 | 0:2e953bbaf3a5 | 57 | * data buffers and leaving the contents of the buffers unchanged. |
okini3939 | 0:2e953bbaf3a5 | 58 | * @param page Page of the main memory to read |
okini3939 | 0:2e953bbaf3a5 | 59 | * @param offset Starting byte address within the page |
okini3939 | 0:2e953bbaf3a5 | 60 | **/ |
okini3939 | 0:2e953bbaf3a5 | 61 | void ReadMainMemoryPage(uint16_t page, uint16_t offset); |
okini3939 | 0:2e953bbaf3a5 | 62 | |
okini3939 | 0:2e953bbaf3a5 | 63 | /** |
okini3939 | 0:2e953bbaf3a5 | 64 | * Sequentially read a continuous stream of data. |
okini3939 | 0:2e953bbaf3a5 | 65 | * @param page Page of the main memory where the sequential read will start |
okini3939 | 0:2e953bbaf3a5 | 66 | * @param offset Starting byte address within the page |
okini3939 | 0:2e953bbaf3a5 | 67 | * @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 | 68 | * @note The legacy mode is not currently supported |
okini3939 | 0:2e953bbaf3a5 | 69 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 70 | **/ |
okini3939 | 0:2e953bbaf3a5 | 71 | void ContinuousArrayRead(uint16_t page, uint16_t offset, uint8_t low); |
okini3939 | 0:2e953bbaf3a5 | 72 | |
LeoHsueh |
6:1872f591d604 | 73 | void read(uint16_t addr, void *buf, uint16_t len); |
??? |
3:82157896d90d | 74 | |
LeoHsueh |
6:1872f591d604 | 75 | void write(uint16_t addr, void *buf, uint16_t len); |
??? |
3:82157896d90d | 76 | |
okini3939 | 0:2e953bbaf3a5 | 77 | /** |
okini3939 | 0:2e953bbaf3a5 | 78 | * Read the content of one of the SRAM data buffers (in low or high speed mode). |
okini3939 | 0:2e953bbaf3a5 | 79 | * @param bufferNum Buffer to read (1 or 2) |
okini3939 | 0:2e953bbaf3a5 | 80 | * @param offset Starting byte within the buffer |
okini3939 | 0:2e953bbaf3a5 | 81 | * @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 | 82 | **/ |
okini3939 | 0:2e953bbaf3a5 | 83 | void BufferRead(uint8_t bufferNum, uint16_t offset, uint8_t low); |
okini3939 | 0:2e953bbaf3a5 | 84 | |
okini3939 | 0:2e953bbaf3a5 | 85 | /** |
okini3939 | 0:2e953bbaf3a5 | 86 | * Write data to one of the SRAM data buffers. Any further call to |
okini3939 | 0:2e953bbaf3a5 | 87 | * spi_tranfer will return bytes contained in the data buffer until |
okini3939 | 0:2e953bbaf3a5 | 88 | * a low-to-high transition is detected on the CS pin. If the end of |
okini3939 | 0:2e953bbaf3a5 | 89 | * the data buffer is reached, the device will wrap around back to the |
okini3939 | 0:2e953bbaf3a5 | 90 | * beginning of the buffer. |
okini3939 | 0:2e953bbaf3a5 | 91 | * @param bufferNum Buffer to read (1 or 2) |
okini3939 | 0:2e953bbaf3a5 | 92 | * @param offset Starting byte within the buffer |
okini3939 | 0:2e953bbaf3a5 | 93 | **/ |
okini3939 | 0:2e953bbaf3a5 | 94 | void BufferWrite(uint8_t bufferNum, uint16_t offset); |
LeoHsueh |
6:1872f591d604 | 95 | |
okini3939 | 0:2e953bbaf3a5 | 96 | /** |
okini3939 | 0:2e953bbaf3a5 | 97 | * Transfer data from buffer 1 or 2 to main memory page. |
okini3939 | 0:2e953bbaf3a5 | 98 | * @param bufferNum Buffer to use (1 or 2) |
okini3939 | 0:2e953bbaf3a5 | 99 | * @param page Page where the content of the buffer will transfered |
okini3939 | 0:2e953bbaf3a5 | 100 | * @param erase If set the page will be first erased before the buffer transfer. |
okini3939 | 0:2e953bbaf3a5 | 101 | * @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 | 102 | **/ |
LeoHsueh |
6:1872f591d604 | 103 | void BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase); |
okini3939 | 0:2e953bbaf3a5 | 104 | |
okini3939 | 0:2e953bbaf3a5 | 105 | /** |
okini3939 | 0:2e953bbaf3a5 | 106 | * Transfer a page of data from main memory to buffer 1 or 2. |
okini3939 | 0:2e953bbaf3a5 | 107 | * @param page Main memory page to transfer |
okini3939 | 0:2e953bbaf3a5 | 108 | * @param buffer Buffer (1 or 2) where the data will be written |
okini3939 | 0:2e953bbaf3a5 | 109 | **/ |
okini3939 | 0:2e953bbaf3a5 | 110 | void PageToBuffer(uint16_t page, uint8_t bufferNum); |
okini3939 | 0:2e953bbaf3a5 | 111 | |
okini3939 | 0:2e953bbaf3a5 | 112 | /** |
okini3939 | 0:2e953bbaf3a5 | 113 | * Erase a page in the main memory array. |
okini3939 | 0:2e953bbaf3a5 | 114 | * @param page Page to erase |
okini3939 | 0:2e953bbaf3a5 | 115 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 116 | **/ |
okini3939 | 0:2e953bbaf3a5 | 117 | void PageErase(uint16_t page); |
LeoHsueh |
6:1872f591d604 | 118 | |
okini3939 | 0:2e953bbaf3a5 | 119 | /** |
okini3939 | 0:2e953bbaf3a5 | 120 | * Erase a block of eight pages at one time. |
okini3939 | 0:2e953bbaf3a5 | 121 | * @param block Index of the block to erase |
okini3939 | 0:2e953bbaf3a5 | 122 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 123 | **/ |
okini3939 | 0:2e953bbaf3a5 | 124 | void BlockErase(uint16_t block); |
okini3939 | 0:2e953bbaf3a5 | 125 | |
okini3939 | 0:2e953bbaf3a5 | 126 | /** |
okini3939 | 0:2e953bbaf3a5 | 127 | * Erase a sector in main memory. There are 16 sector on the |
okini3939 | 0:2e953bbaf3a5 | 128 | * at45db161d and only one can be erased at one time. |
okini3939 | 0:2e953bbaf3a5 | 129 | * @param sector Sector to erase |
okini3939 | 0:2e953bbaf3a5 | 130 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 131 | **/ |
okini3939 | 0:2e953bbaf3a5 | 132 | void SectoreErase(uint8_t sector); |
okini3939 | 0:2e953bbaf3a5 | 133 | |
okini3939 | 0:2e953bbaf3a5 | 134 | /** |
okini3939 | 0:2e953bbaf3a5 | 135 | * Erase the entire chip memory. Sectors proteced or locked down will |
okini3939 | 0:2e953bbaf3a5 | 136 | * not be erased. |
okini3939 | 0:2e953bbaf3a5 | 137 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 138 | **/ |
okini3939 | 0:2e953bbaf3a5 | 139 | void ChipErase(); |
okini3939 | 0:2e953bbaf3a5 | 140 | |
okini3939 | 0:2e953bbaf3a5 | 141 | /** |
okini3939 | 0:2e953bbaf3a5 | 142 | * This a combination of Buffer Write and Buffer to Page with |
okini3939 | 0:2e953bbaf3a5 | 143 | * Built-in Erase. |
okini3939 | 0:2e953bbaf3a5 | 144 | * @note You must call EndAndWait in order to start transfering data from buffer to page |
okini3939 | 0:2e953bbaf3a5 | 145 | * @param page Page where the content of the buffer will transfered |
okini3939 | 0:2e953bbaf3a5 | 146 | * @param offset Starting byte address within the buffer |
okini3939 | 0:2e953bbaf3a5 | 147 | * @param bufferNum Buffer to use (1 or 2) |
okini3939 | 0:2e953bbaf3a5 | 148 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 149 | **/ |
okini3939 | 0:2e953bbaf3a5 | 150 | void BeginPageWriteThroughBuffer(uint16_t page, uint16_t offset, uint8_t bufferNum); |
LeoHsueh |
6:1872f591d604 | 151 | |
okini3939 | 0:2e953bbaf3a5 | 152 | /** |
okini3939 | 0:2e953bbaf3a5 | 153 | * Perform a low-to-high transition on the CS pin and then poll |
okini3939 | 0:2e953bbaf3a5 | 154 | * the status register to check if the dataflash is busy. |
okini3939 | 0:2e953bbaf3a5 | 155 | **/ |
okini3939 | 0:2e953bbaf3a5 | 156 | void EndAndWait(); |
okini3939 | 0:2e953bbaf3a5 | 157 | |
okini3939 | 0:2e953bbaf3a5 | 158 | /** |
okini3939 | 0:2e953bbaf3a5 | 159 | * Compare a page of data in main memory to the data in buffer 1 or 2. |
okini3939 | 0:2e953bbaf3a5 | 160 | * @param page Page to test |
okini3939 | 0:2e953bbaf3a5 | 161 | * @param bufferNum Buffer number |
okini3939 | 0:2e953bbaf3a5 | 162 | * @return |
okini3939 | 0:2e953bbaf3a5 | 163 | * - 1 if the page and the buffer contains the same data |
okini3939 | 0:2e953bbaf3a5 | 164 | * - 0 else |
okini3939 | 0:2e953bbaf3a5 | 165 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 166 | **/ |
okini3939 | 0:2e953bbaf3a5 | 167 | int8_t ComparePageToBuffer(uint16_t page, uint8_t bufferNum); |
okini3939 | 0:2e953bbaf3a5 | 168 | |
okini3939 | 0:2e953bbaf3a5 | 169 | /** |
okini3939 | 0:2e953bbaf3a5 | 170 | * Put the device into the lowest power consumption mode. |
okini3939 | 0:2e953bbaf3a5 | 171 | * Once the device has entered the Deep Power-down mode, all |
okini3939 | 0:2e953bbaf3a5 | 172 | * instructions are ignored except the Resume from Deep |
okini3939 | 0:2e953bbaf3a5 | 173 | * Power-down command. |
okini3939 | 0:2e953bbaf3a5 | 174 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 175 | **/ |
okini3939 | 0:2e953bbaf3a5 | 176 | void DeepPowerDown(); |
okini3939 | 0:2e953bbaf3a5 | 177 | |
okini3939 | 0:2e953bbaf3a5 | 178 | /** |
okini3939 | 0:2e953bbaf3a5 | 179 | * Takes the device out of Deep Power-down mode. |
okini3939 | 0:2e953bbaf3a5 | 180 | * @warning UNTESTED |
okini3939 | 0:2e953bbaf3a5 | 181 | **/ |
okini3939 | 0:2e953bbaf3a5 | 182 | void ResumeFromDeepPowerDown(); |
okini3939 | 0:2e953bbaf3a5 | 183 | |
okini3939 | 0:2e953bbaf3a5 | 184 | private: |
okini3939 | 0:2e953bbaf3a5 | 185 | /* Nothing atm but who knows... */ |
okini3939 | 0:2e953bbaf3a5 | 186 | |
LeoHsueh |
5:ef7247c6f073 | 187 | SPI *_spi; |
okini3939 | 0:2e953bbaf3a5 | 188 | DigitalOut _cs; |
??? |
3:82157896d90d | 189 | |
??? |
3:82157896d90d | 190 | uint16_t _bytes, _pages; |
??? |
3:82157896d90d | 191 | |
okini3939 | 0:2e953bbaf3a5 | 192 | }; |
okini3939 | 0:2e953bbaf3a5 | 193 | |
okini3939 | 0:2e953bbaf3a5 | 194 | /** |
okini3939 | 0:2e953bbaf3a5 | 195 | * @} |
okini3939 | 0:2e953bbaf3a5 | 196 | **/ |
okini3939 | 0:2e953bbaf3a5 | 197 | |
okini3939 | 0:2e953bbaf3a5 | 198 | #endif /* AT45DB161D_H */ |