EEPROM component demo

Dependents:   DISCO-F429ZI_EEPROM_demo WIRE-BANDING_FT810 WIRE-BANDING_copy

Committer:
jeromecoutant
Date:
Tue Jul 04 16:10:30 2017 +0000
Revision:
1:0980ff473345
Parent:
0:caf01d53736a
Update with MBED rev145

Who changed what in which revision?

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