ST / EEPROM_DISCO_F429ZI

Dependents:   DISCO-F429ZI_EEPROM_demo WIRE-BANDING_FT810 WIRE-BANDING_copy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EEPROM_DISCO_F429ZI.h Source File

EEPROM_DISCO_F429ZI.h

00001 /* Copyright (c) 2010-2011 mbed.org, MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 
00019 #ifndef __EEPROM_DISCO_F429ZI_H
00020 #define __EEPROM_DISCO_F429ZI_H
00021 
00022 #ifdef TARGET_DISCO_F429ZI
00023 
00024 #include "mbed.h"
00025 #include "stm32f429i_discovery_eeprom.h"
00026 
00027 /*
00028  Class to drive a M24LR64 EEPROM.
00029 
00030  =================================================================== 
00031  Note:
00032     The I2C EEPROM memory (M24LR64) is available on a separate ANT7-M24LR-A
00033     daughter board (not provided with the STM32746G_DISCOVERY board).
00034     This daughter board must be connected on the CN2 connector.
00035  ===================================================================
00036              
00037  Usage:
00038 
00039 #include "mbed.h"
00040 #include "EEPROM_DISCO_F429ZI.h"
00041 
00042 EEPROM_DISCO_F429ZI eep;
00043 
00044 #define BUFFER_SIZE         ((uint32_t)32)
00045 #define WRITE_READ_ADDR     ((uint32_t)0x0000)
00046 
00047 int main()
00048 {
00049     //                                    12345678901234567890123456789012
00050     uint8_t WriteBuffer[BUFFER_SIZE+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
00051     uint8_t ReadBuffer[BUFFER_SIZE+1];
00052     uint16_t bytes_rd;
00053   
00054     // Check initialization
00055     if (eep.Init() != EEPROM_OK)
00056     {
00057       error("Initialization FAILED\n");
00058     }
00059 
00060     // Write buffer
00061     if (eep.WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE) != EEPROM_OK)
00062     {
00063       error("Write buffer FAILED\n");
00064     }
00065     
00066     // Read buffer
00067     bytes_rd = BUFFER_SIZE;
00068     if (eep.ReadBuffer(ReadBuffer, WRITE_READ_ADDR, &bytes_rd) != EEPROM_OK)
00069     {
00070       error("Read buffer FAILED\n");
00071     }
00072     else
00073     {
00074       ReadBuffer[BUFFER_SIZE] = '\0';
00075       printf("Read buffer PASSED\n");
00076       printf("Buffer read = [%s]\n", ReadBuffer);
00077       printf("Bytes read = %d\n", bytes_rd);
00078     }
00079 
00080     while(1) {
00081     }
00082 }
00083 
00084 */
00085 class EEPROM_DISCO_F429ZI
00086 {
00087   
00088 public:
00089     //! Constructor
00090     EEPROM_DISCO_F429ZI();
00091 
00092     //! Destructor
00093     ~EEPROM_DISCO_F429ZI();
00094     
00095   /**
00096     * @brief  Initializes peripherals used by the I2C EEPROM driver.
00097     * @param  None
00098     * @note   There are 2 different versions of M24LR64 (A01 & A02);.
00099     *         Then try to connect on 1st one (EEPROM_I2C_ADDRESS_A01); 
00100     *         and if problem, check the 2nd one (EEPROM_I2C_ADDRESS_A02);
00101     * @retval EEPROM_OK (0); if operation is correctly performed, else return value 
00102     *         different from EEPROM_OK (0);
00103     */
00104   uint32_t Init(void);
00105 
00106   /**
00107     * @brief  Reads a block of data from the EEPROM.
00108     * @param  pBuffer : pointer to the buffer that receives the data read from 
00109     *         the EEPROM.
00110     * @param  ReadAddr : EEPROM's internal address to start reading from.
00111     * @param  NumByteToRead : pointer to the variable holding number of bytes to 
00112     *         be read from the EEPROM.
00113     * 
00114     *        @note The variable pointed by NumByteToRead is reset to 0 when all the 
00115     *              data are read from the EEPROM. Application should monitor this 
00116     *              variable in order know when the transfer is complete.
00117     * 
00118     * @retval EEPROM_OK (0); if operation is correctly performed, else return value 
00119     *         different from EEPROM_OK (0); or the timeout user callback.
00120     */
00121   uint32_t ReadBuffer(uint8_t *pBuffer, uint16_t ReadAddr, uint16_t *NumByteToRead);
00122 
00123   /**
00124     * @brief  Writes more than one byte to the EEPROM with a single WRITE cycle.
00125     *
00126     * @note   The number of bytes (combined to write start address); must not 
00127     *         cross the EEPROM page boundary. This function can only write into
00128     *         the boundaries of an EEPROM page.
00129     *         This function doesn't check on boundaries condition (in this driver 
00130     *         the function WriteBuffer(); which calls BSP_EEPROM_WritePage() is 
00131     *         responsible of checking on Page boundaries);.
00132     * 
00133     * @param  pBuffer : pointer to the buffer containing the data to be written to 
00134     *         the EEPROM.
00135     * @param  WriteAddr : EEPROM's internal address to write to.
00136     * @param  NumByteToWrite : pointer to the variable holding number of bytes to 
00137     *         be written into the EEPROM. 
00138     * 
00139     *        @note The variable pointed by NumByteToWrite is reset to 0 when all the 
00140     *              data are written to the EEPROM. Application should monitor this 
00141     *              variable in order know when the transfer is complete.
00142     * 
00143     * @note This function just configure the communication and enable the DMA 
00144     *       channel to transfer data. Meanwhile, the user application may perform 
00145     *       other tasks in parallel.
00146     * 
00147     * @retval EEPROM_OK (0); if operation is correctly performed, else return value 
00148     *         different from EEPROM_OK (0); or the timeout user callback.
00149     */
00150   uint32_t WritePage(uint8_t *pBuffer, uint16_t WriteAddr, uint8_t *NumByteToWrite);
00151 
00152   /**
00153     * @brief  Writes buffer of data to the I2C EEPROM.
00154     * @param  pBuffer : pointer to the buffer  containing the data to be written 
00155     *         to the EEPROM.
00156     * @param  WriteAddr : EEPROM's internal address to write to.
00157     * @param  NumByteToWrite : number of bytes to write to the EEPROM.
00158     * @retval EEPROM_OK (0); if operation is correctly performed, else return value 
00159     *         different from EEPROM_OK (0); or the timeout user callback.
00160     */
00161   uint32_t WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
00162 
00163   /**
00164     * @brief  Wait for EEPROM Standby state.
00165     * 
00166     * @note  This function allows to wait and check that EEPROM has finished the 
00167     *        last operation. It is mostly used after Write operation: after receiving
00168     *        the buffer to be written, the EEPROM may need additional time to actually
00169     *        perform the write operation. During this time, it doesn't answer to
00170     *        I2C packets addressed to it. Once the write operation is complete
00171     *        the EEPROM responds to its address.
00172     * 
00173     * @param  None
00174     * @retval EEPROM_OK (0); if operation is correctly performed, else return value 
00175     *         different from EEPROM_OK (0); or the timeout user callback.
00176     */
00177   uint32_t WaitEepromStandbyState(void);
00178 
00179     private:
00180 
00181 };
00182 
00183 #else
00184 #error "This class must be used with DISCO_F429ZI board only."
00185 #endif // TARGET_DISCO_F429ZI
00186 
00187 #endif