Class to drive a M24LR64 EEPROM with the STM32746G_DISCOVERY board. This EEPROM can be found on the additional ANT7-M24LR-A daughter board.
Dependents: DISCO-F746NG_Monttory_Base DISCO-F746NG_Monttory_Base
Deprecated lib
EEPROM_DISCO_F746NG.h@0:71d257cea6b2, 2016-01-05 (annotated)
- Committer:
- bcostm
- Date:
- Tue Jan 05 09:02:48 2016 +0000
- Revision:
- 0:71d257cea6b2
First version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:71d257cea6b2 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
bcostm | 0:71d257cea6b2 | 2 | * |
bcostm | 0:71d257cea6b2 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
bcostm | 0:71d257cea6b2 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
bcostm | 0:71d257cea6b2 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
bcostm | 0:71d257cea6b2 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
bcostm | 0:71d257cea6b2 | 7 | * Software is furnished to do so, subject to the following conditions: |
bcostm | 0:71d257cea6b2 | 8 | * |
bcostm | 0:71d257cea6b2 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
bcostm | 0:71d257cea6b2 | 10 | * substantial portions of the Software. |
bcostm | 0:71d257cea6b2 | 11 | * |
bcostm | 0:71d257cea6b2 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
bcostm | 0:71d257cea6b2 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
bcostm | 0:71d257cea6b2 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
bcostm | 0:71d257cea6b2 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
bcostm | 0:71d257cea6b2 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
bcostm | 0:71d257cea6b2 | 17 | */ |
bcostm | 0:71d257cea6b2 | 18 | |
bcostm | 0:71d257cea6b2 | 19 | #ifndef __EEPROM_DISCO_F746NG_H |
bcostm | 0:71d257cea6b2 | 20 | #define __EEPROM_DISCO_F746NG_H |
bcostm | 0:71d257cea6b2 | 21 | |
bcostm | 0:71d257cea6b2 | 22 | #ifdef TARGET_DISCO_F746NG |
bcostm | 0:71d257cea6b2 | 23 | |
bcostm | 0:71d257cea6b2 | 24 | #include "mbed.h" |
bcostm | 0:71d257cea6b2 | 25 | #include "stm32746g_discovery_eeprom.h" |
bcostm | 0:71d257cea6b2 | 26 | |
bcostm | 0:71d257cea6b2 | 27 | /* |
bcostm | 0:71d257cea6b2 | 28 | Class to drive a M24LR64 EEPROM. |
bcostm | 0:71d257cea6b2 | 29 | |
bcostm | 0:71d257cea6b2 | 30 | =================================================================== |
bcostm | 0:71d257cea6b2 | 31 | Note: |
bcostm | 0:71d257cea6b2 | 32 | The I2C EEPROM memory (M24LR64) is available on a separate ANT7-M24LR-A |
bcostm | 0:71d257cea6b2 | 33 | daughter board (not provided with the STM32746G_DISCOVERY board). |
bcostm | 0:71d257cea6b2 | 34 | This daughter board must be connected on the CN2 connector. |
bcostm | 0:71d257cea6b2 | 35 | =================================================================== |
bcostm | 0:71d257cea6b2 | 36 | |
bcostm | 0:71d257cea6b2 | 37 | Usage: |
bcostm | 0:71d257cea6b2 | 38 | |
bcostm | 0:71d257cea6b2 | 39 | #include "mbed.h" |
bcostm | 0:71d257cea6b2 | 40 | #include "EEPROM_DISCO_F746NG.h" |
bcostm | 0:71d257cea6b2 | 41 | |
bcostm | 0:71d257cea6b2 | 42 | EEPROM_DISCO_F746NG eep; |
bcostm | 0:71d257cea6b2 | 43 | |
bcostm | 0:71d257cea6b2 | 44 | #define BUFFER_SIZE ((uint32_t)32) |
bcostm | 0:71d257cea6b2 | 45 | #define WRITE_READ_ADDR ((uint32_t)0x0000) |
bcostm | 0:71d257cea6b2 | 46 | |
bcostm | 0:71d257cea6b2 | 47 | int main() |
bcostm | 0:71d257cea6b2 | 48 | { |
bcostm | 0:71d257cea6b2 | 49 | // 12345678901234567890123456789012 |
bcostm | 0:71d257cea6b2 | 50 | uint8_t WriteBuffer[BUFFER_SIZE+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345"; |
bcostm | 0:71d257cea6b2 | 51 | uint8_t ReadBuffer[BUFFER_SIZE+1]; |
bcostm | 0:71d257cea6b2 | 52 | uint16_t bytes_rd; |
bcostm | 0:71d257cea6b2 | 53 | |
bcostm | 0:71d257cea6b2 | 54 | // Check initialization |
bcostm | 0:71d257cea6b2 | 55 | if (eep.Init() != EEPROM_OK) |
bcostm | 0:71d257cea6b2 | 56 | { |
bcostm | 0:71d257cea6b2 | 57 | error("Initialization FAILED\n"); |
bcostm | 0:71d257cea6b2 | 58 | } |
bcostm | 0:71d257cea6b2 | 59 | |
bcostm | 0:71d257cea6b2 | 60 | // Write buffer |
bcostm | 0:71d257cea6b2 | 61 | if (eep.WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != EEPROM_OK) |
bcostm | 0:71d257cea6b2 | 62 | { |
bcostm | 0:71d257cea6b2 | 63 | error("Write buffer FAILED\n"); |
bcostm | 0:71d257cea6b2 | 64 | } |
bcostm | 0:71d257cea6b2 | 65 | |
bcostm | 0:71d257cea6b2 | 66 | // Read buffer |
bcostm | 0:71d257cea6b2 | 67 | bytes_rd = BUFFER_SIZE; |
bcostm | 0:71d257cea6b2 | 68 | if (eep.ReadBuffer(ReadBuffer, WRITE_READ_ADDR, &bytes_rd) != EEPROM_OK) |
bcostm | 0:71d257cea6b2 | 69 | { |
bcostm | 0:71d257cea6b2 | 70 | error("Read buffer FAILED\n"); |
bcostm | 0:71d257cea6b2 | 71 | } |
bcostm | 0:71d257cea6b2 | 72 | else |
bcostm | 0:71d257cea6b2 | 73 | { |
bcostm | 0:71d257cea6b2 | 74 | ReadBuffer[BUFFER_SIZE] = '\0'; |
bcostm | 0:71d257cea6b2 | 75 | printf("Read buffer PASSED\n"); |
bcostm | 0:71d257cea6b2 | 76 | printf("Buffer read = [%s]\n", ReadBuffer); |
bcostm | 0:71d257cea6b2 | 77 | printf("Bytes read = %d\n", bytes_rd); |
bcostm | 0:71d257cea6b2 | 78 | } |
bcostm | 0:71d257cea6b2 | 79 | |
bcostm | 0:71d257cea6b2 | 80 | while(1) { |
bcostm | 0:71d257cea6b2 | 81 | } |
bcostm | 0:71d257cea6b2 | 82 | } |
bcostm | 0:71d257cea6b2 | 83 | |
bcostm | 0:71d257cea6b2 | 84 | */ |
bcostm | 0:71d257cea6b2 | 85 | class EEPROM_DISCO_F746NG |
bcostm | 0:71d257cea6b2 | 86 | { |
bcostm | 0:71d257cea6b2 | 87 | |
bcostm | 0:71d257cea6b2 | 88 | public: |
bcostm | 0:71d257cea6b2 | 89 | //! Constructor |
bcostm | 0:71d257cea6b2 | 90 | EEPROM_DISCO_F746NG(); |
bcostm | 0:71d257cea6b2 | 91 | |
bcostm | 0:71d257cea6b2 | 92 | //! Destructor |
bcostm | 0:71d257cea6b2 | 93 | ~EEPROM_DISCO_F746NG(); |
bcostm | 0:71d257cea6b2 | 94 | |
bcostm | 0:71d257cea6b2 | 95 | /** |
bcostm | 0:71d257cea6b2 | 96 | * @brief Initializes peripherals used by the I2C EEPROM driver. |
bcostm | 0:71d257cea6b2 | 97 | * |
bcostm | 0:71d257cea6b2 | 98 | * @note There are 2 different versions of M24LR64 (A01 & A02);. |
bcostm | 0:71d257cea6b2 | 99 | * Then try to connect on 1st one (EEPROM_I2C_ADDRESS_A01); |
bcostm | 0:71d257cea6b2 | 100 | * and if problem, check the 2nd one (EEPROM_I2C_ADDRESS_A02); |
bcostm | 0:71d257cea6b2 | 101 | * @retval EEPROM_OK (0); if operation is correctly performed, else return value |
bcostm | 0:71d257cea6b2 | 102 | * different from EEPROM_OK (0); |
bcostm | 0:71d257cea6b2 | 103 | */ |
bcostm | 0:71d257cea6b2 | 104 | uint32_t Init(void); |
bcostm | 0:71d257cea6b2 | 105 | |
bcostm | 0:71d257cea6b2 | 106 | /** |
bcostm | 0:71d257cea6b2 | 107 | * @brief DeInitializes the EEPROM. |
bcostm | 0:71d257cea6b2 | 108 | * @retval EEPROM state |
bcostm | 0:71d257cea6b2 | 109 | */ |
bcostm | 0:71d257cea6b2 | 110 | uint8_t DeInit(void); |
bcostm | 0:71d257cea6b2 | 111 | |
bcostm | 0:71d257cea6b2 | 112 | /** |
bcostm | 0:71d257cea6b2 | 113 | * @brief Reads a block of data from the EEPROM. |
bcostm | 0:71d257cea6b2 | 114 | * @param pBuffer: pointer to the buffer that receives the data read from |
bcostm | 0:71d257cea6b2 | 115 | * the EEPROM. |
bcostm | 0:71d257cea6b2 | 116 | * @param ReadAddr: EEPROM's internal address to start reading from. |
bcostm | 0:71d257cea6b2 | 117 | * @param NumByteToRead: pointer to the variable holding number of bytes to |
bcostm | 0:71d257cea6b2 | 118 | * be read from the EEPROM. |
bcostm | 0:71d257cea6b2 | 119 | * |
bcostm | 0:71d257cea6b2 | 120 | * @note The variable pointed by NumByteToRead is reset to 0 when all the |
bcostm | 0:71d257cea6b2 | 121 | * data are read from the EEPROM. Application should monitor this |
bcostm | 0:71d257cea6b2 | 122 | * variable in order know when the transfer is complete. |
bcostm | 0:71d257cea6b2 | 123 | * |
bcostm | 0:71d257cea6b2 | 124 | * @retval EEPROM_OK (0); if operation is correctly performed, else return value |
bcostm | 0:71d257cea6b2 | 125 | * different from EEPROM_OK (0); or the timeout user callback. |
bcostm | 0:71d257cea6b2 | 126 | */ |
bcostm | 0:71d257cea6b2 | 127 | uint32_t ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead); |
bcostm | 0:71d257cea6b2 | 128 | |
bcostm | 0:71d257cea6b2 | 129 | /** |
bcostm | 0:71d257cea6b2 | 130 | * @brief Writes more than one byte to the EEPROM with a single WRITE cycle. |
bcostm | 0:71d257cea6b2 | 131 | * |
bcostm | 0:71d257cea6b2 | 132 | * @note The number of bytes (combined to write start address); must not |
bcostm | 0:71d257cea6b2 | 133 | * cross the EEPROM page boundary. This function can only write into |
bcostm | 0:71d257cea6b2 | 134 | * the boundaries of an EEPROM page. |
bcostm | 0:71d257cea6b2 | 135 | * This function doesn't check on boundaries condition (in this driver |
bcostm | 0:71d257cea6b2 | 136 | * the function WriteBuffer(); which calls BSP_EEPROM_WritePage() is |
bcostm | 0:71d257cea6b2 | 137 | * responsible of checking on Page boundaries);. |
bcostm | 0:71d257cea6b2 | 138 | * |
bcostm | 0:71d257cea6b2 | 139 | * @param pBuffer: pointer to the buffer containing the data to be written to |
bcostm | 0:71d257cea6b2 | 140 | * the EEPROM. |
bcostm | 0:71d257cea6b2 | 141 | * @param WriteAddr: EEPROM's internal address to write to. |
bcostm | 0:71d257cea6b2 | 142 | * @param NumByteToWrite: pointer to the variable holding number of bytes to |
bcostm | 0:71d257cea6b2 | 143 | * be written into the EEPROM. |
bcostm | 0:71d257cea6b2 | 144 | * |
bcostm | 0:71d257cea6b2 | 145 | * @note The variable pointed by NumByteToWrite is reset to 0 when all the |
bcostm | 0:71d257cea6b2 | 146 | * data are written to the EEPROM. Application should monitor this |
bcostm | 0:71d257cea6b2 | 147 | * variable in order know when the transfer is complete. |
bcostm | 0:71d257cea6b2 | 148 | * |
bcostm | 0:71d257cea6b2 | 149 | * @note This function just configure the communication and enable the DMA |
bcostm | 0:71d257cea6b2 | 150 | * channel to transfer data. Meanwhile, the user application may perform |
bcostm | 0:71d257cea6b2 | 151 | * other tasks in parallel. |
bcostm | 0:71d257cea6b2 | 152 | * |
bcostm | 0:71d257cea6b2 | 153 | * @retval EEPROM_OK (0); if operation is correctly performed, else return value |
bcostm | 0:71d257cea6b2 | 154 | * different from EEPROM_OK (0); or the timeout user callback. |
bcostm | 0:71d257cea6b2 | 155 | */ |
bcostm | 0:71d257cea6b2 | 156 | uint32_t WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite); |
bcostm | 0:71d257cea6b2 | 157 | |
bcostm | 0:71d257cea6b2 | 158 | /** |
bcostm | 0:71d257cea6b2 | 159 | * @brief Writes buffer of data to the I2C EEPROM. |
bcostm | 0:71d257cea6b2 | 160 | * @param pBuffer: pointer to the buffer containing the data to be written |
bcostm | 0:71d257cea6b2 | 161 | * to the EEPROM. |
bcostm | 0:71d257cea6b2 | 162 | * @param WriteAddr: EEPROM's internal address to write to. |
bcostm | 0:71d257cea6b2 | 163 | * @param NumByteToWrite: number of bytes to write to the EEPROM. |
bcostm | 0:71d257cea6b2 | 164 | * @retval EEPROM_OK (0); if operation is correctly performed, else return value |
bcostm | 0:71d257cea6b2 | 165 | * different from EEPROM_OK (0); or the timeout user callback. |
bcostm | 0:71d257cea6b2 | 166 | */ |
bcostm | 0:71d257cea6b2 | 167 | uint32_t WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite); |
bcostm | 0:71d257cea6b2 | 168 | |
bcostm | 0:71d257cea6b2 | 169 | /** |
bcostm | 0:71d257cea6b2 | 170 | * @brief Wait for EEPROM Standby state. |
bcostm | 0:71d257cea6b2 | 171 | * |
bcostm | 0:71d257cea6b2 | 172 | * @note This function allows to wait and check that EEPROM has finished the |
bcostm | 0:71d257cea6b2 | 173 | * last operation. It is mostly used after Write operation: after receiving |
bcostm | 0:71d257cea6b2 | 174 | * the buffer to be written, the EEPROM may need additional time to actually |
bcostm | 0:71d257cea6b2 | 175 | * perform the write operation. During this time, it doesn't answer to |
bcostm | 0:71d257cea6b2 | 176 | * I2C packets addressed to it. Once the write operation is complete |
bcostm | 0:71d257cea6b2 | 177 | * the EEPROM responds to its address. |
bcostm | 0:71d257cea6b2 | 178 | * |
bcostm | 0:71d257cea6b2 | 179 | * @retval EEPROM_OK (0); if operation is correctly performed, else return value |
bcostm | 0:71d257cea6b2 | 180 | * different from EEPROM_OK (0); or the timeout user callback. |
bcostm | 0:71d257cea6b2 | 181 | */ |
bcostm | 0:71d257cea6b2 | 182 | uint32_t WaitEepromStandbyState(void); |
bcostm | 0:71d257cea6b2 | 183 | |
bcostm | 0:71d257cea6b2 | 184 | private: |
bcostm | 0:71d257cea6b2 | 185 | |
bcostm | 0:71d257cea6b2 | 186 | }; |
bcostm | 0:71d257cea6b2 | 187 | |
bcostm | 0:71d257cea6b2 | 188 | #else |
bcostm | 0:71d257cea6b2 | 189 | #error "This class must be used with DISCO_F746NG board only." |
bcostm | 0:71d257cea6b2 | 190 | #endif // TARGET_DISCO_F746NG |
bcostm | 0:71d257cea6b2 | 191 | |
bcostm | 0:71d257cea6b2 | 192 | #endif |