library

Dependents:   Aprendendo Final_v3

Committer:
zigdrix
Date:
Mon Oct 19 22:13:50 2020 +0000
Revision:
4:e746cdd3e76a
Parent:
0:0002c86c2220
Projeto Final PI 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:0002c86c2220 1 /**
bcostm 0:0002c86c2220 2 ******************************************************************************
bcostm 0:0002c86c2220 3 * @file stm32469i_discovery_eeprom.c
bcostm 0:0002c86c2220 4 * @author MCD Application Team
bcostm 0:0002c86c2220 5 * @version V1.0.1
bcostm 0:0002c86c2220 6 * @date 29-September-2015
bcostm 0:0002c86c2220 7 * @brief This file provides a set of functions needed to manage an I2C M24LR64
bcostm 0:0002c86c2220 8 * EEPROM memory.
bcostm 0:0002c86c2220 9 * To be able to use this driver, the switch EE_M24LR64 must be defined
bcostm 0:0002c86c2220 10 * in your toolchain compiler preprocessor
bcostm 0:0002c86c2220 11 *
bcostm 0:0002c86c2220 12 * ===================================================================
bcostm 0:0002c86c2220 13 * Notes:
bcostm 0:0002c86c2220 14 * - This driver is intended for STM32F4xx families devices only.
bcostm 0:0002c86c2220 15 * - The I2C EEPROM memory (M24LR64) is available on separate daughter
bcostm 0:0002c86c2220 16 * board ANT7-M24LR-A, which is not provided with the STM32469I-Discovery
bcostm 0:0002c86c2220 17 * board.
bcostm 0:0002c86c2220 18 * To use this driver you have to connect the ANT7-M24LR-A to CN11
bcostm 0:0002c86c2220 19 * connector of STM32469I-Discovery board.
bcostm 0:0002c86c2220 20 * ===================================================================
bcostm 0:0002c86c2220 21 *
bcostm 0:0002c86c2220 22 * It implements a high level communication layer for read and write
bcostm 0:0002c86c2220 23 * from/to this memory. The needed STM32F4xx hardware resources (I2C and
bcostm 0:0002c86c2220 24 * GPIO) are defined in stm32469i_discovery.h file, and the initialization is
bcostm 0:0002c86c2220 25 * performed in EEPROM_IO_Init() function declared in stm32469i_discovery.c
bcostm 0:0002c86c2220 26 * file.
bcostm 0:0002c86c2220 27 * You can easily tailor this driver to any other development board,
bcostm 0:0002c86c2220 28 * by just adapting the defines for hardware resources and
bcostm 0:0002c86c2220 29 * EEPROM_IO_Init() function.
bcostm 0:0002c86c2220 30 *
bcostm 0:0002c86c2220 31 * @note In this driver, basic read and write functions (BSP_EEPROM_ReadBuffer()
bcostm 0:0002c86c2220 32 * and BSP_EEPROM_WritePage()) use DMA mode to perform the data
bcostm 0:0002c86c2220 33 * transfer to/from EEPROM memory.
bcostm 0:0002c86c2220 34 *
bcostm 0:0002c86c2220 35 * @note Regarding BSP_EEPROM_WritePage(), it is a optimized function to perform
bcostm 0:0002c86c2220 36 * small write (less than 1 page) BUT The number of bytes (combined to write start address) must not
bcostm 0:0002c86c2220 37 * cross the EEPROM page boundary. This function can only write into
bcostm 0:0002c86c2220 38 * the boundaries of an EEPROM page.
bcostm 0:0002c86c2220 39 * This function doesn't check on boundaries condition (in this driver
bcostm 0:0002c86c2220 40 * the function BSP_EEPROM_WriteBuffer() which calls BSP_EEPROM_WritePage() is
bcostm 0:0002c86c2220 41 * responsible of checking on Page boundaries).
bcostm 0:0002c86c2220 42 *
bcostm 0:0002c86c2220 43 *
bcostm 0:0002c86c2220 44 * +-----------------------------------------------------------------+
bcostm 0:0002c86c2220 45 * | Pin assignment for M24LR64 EEPROM |
bcostm 0:0002c86c2220 46 * +---------------------------------------+-----------+-------------+
bcostm 0:0002c86c2220 47 * | STM32F4xx I2C Pins | EEPROM | Pin |
bcostm 0:0002c86c2220 48 * +---------------------------------------+-----------+-------------+
bcostm 0:0002c86c2220 49 * | . | E0(GND) | 1 (0V) |
bcostm 0:0002c86c2220 50 * | . | AC0 | 2 |
bcostm 0:0002c86c2220 51 * | . | AC1 | 3 |
bcostm 0:0002c86c2220 52 * | . | VSS | 4 (0V) |
bcostm 0:0002c86c2220 53 * | SDA | SDA | 5 |
bcostm 0:0002c86c2220 54 * | SCL | SCL | 6 |
bcostm 0:0002c86c2220 55 * | . | E1(GND) | 7 (0V) |
bcostm 0:0002c86c2220 56 * | . | VDD | 8 (3.3V) |
bcostm 0:0002c86c2220 57 * +---------------------------------------+-----------+-------------+
bcostm 0:0002c86c2220 58 *
bcostm 0:0002c86c2220 59 ******************************************************************************
bcostm 0:0002c86c2220 60 * @attention
bcostm 0:0002c86c2220 61 *
bcostm 0:0002c86c2220 62 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bcostm 0:0002c86c2220 63 *
bcostm 0:0002c86c2220 64 * Redistribution and use in source and binary forms, with or without modification,
bcostm 0:0002c86c2220 65 * are permitted provided that the following conditions are met:
bcostm 0:0002c86c2220 66 * 1. Redistributions of source code must retain the above copyright notice,
bcostm 0:0002c86c2220 67 * this list of conditions and the following disclaimer.
bcostm 0:0002c86c2220 68 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 0:0002c86c2220 69 * this list of conditions and the following disclaimer in the documentation
bcostm 0:0002c86c2220 70 * and/or other materials provided with the distribution.
bcostm 0:0002c86c2220 71 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bcostm 0:0002c86c2220 72 * may be used to endorse or promote products derived from this software
bcostm 0:0002c86c2220 73 * without specific prior written permission.
bcostm 0:0002c86c2220 74 *
bcostm 0:0002c86c2220 75 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcostm 0:0002c86c2220 76 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcostm 0:0002c86c2220 77 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bcostm 0:0002c86c2220 78 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bcostm 0:0002c86c2220 79 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bcostm 0:0002c86c2220 80 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bcostm 0:0002c86c2220 81 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bcostm 0:0002c86c2220 82 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bcostm 0:0002c86c2220 83 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bcostm 0:0002c86c2220 84 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 0:0002c86c2220 85 *
bcostm 0:0002c86c2220 86 ******************************************************************************
bcostm 0:0002c86c2220 87 */
bcostm 0:0002c86c2220 88 /* Includes ------------------------------------------------------------------*/
bcostm 0:0002c86c2220 89 #include "stm32469i_discovery_eeprom.h"
bcostm 0:0002c86c2220 90
bcostm 0:0002c86c2220 91 /** @addtogroup BSP
bcostm 0:0002c86c2220 92 * @{
bcostm 0:0002c86c2220 93 */
bcostm 0:0002c86c2220 94
bcostm 0:0002c86c2220 95 /** @addtogroup STM32469I-Discovery
bcostm 0:0002c86c2220 96 * @{
bcostm 0:0002c86c2220 97 */
bcostm 0:0002c86c2220 98
bcostm 0:0002c86c2220 99 /** @addtogroup STM32469I-Discovery_EEPROM
bcostm 0:0002c86c2220 100 * @brief This file includes the I2C EEPROM driver of STM32469I-Discovery board.
bcostm 0:0002c86c2220 101 * @{
bcostm 0:0002c86c2220 102 */
bcostm 0:0002c86c2220 103
bcostm 0:0002c86c2220 104 /** @defgroup STM32469I-Discovery_EEPROM_Private_Types STM32469I Discovery Eeprom Private Types
bcostm 0:0002c86c2220 105 * @{
bcostm 0:0002c86c2220 106 */
bcostm 0:0002c86c2220 107 /**
bcostm 0:0002c86c2220 108 * @}
bcostm 0:0002c86c2220 109 */
bcostm 0:0002c86c2220 110
bcostm 0:0002c86c2220 111 /** @defgroup STM32469I-Discovery_EEPROM_Private_Defines STM32469I Discovery Eeprom Private Defines
bcostm 0:0002c86c2220 112 * @{
bcostm 0:0002c86c2220 113 */
bcostm 0:0002c86c2220 114 /**
bcostm 0:0002c86c2220 115 * @}
bcostm 0:0002c86c2220 116 */
bcostm 0:0002c86c2220 117
bcostm 0:0002c86c2220 118 /** @defgroup STM32469I-Discovery_EEPROM_Private_Macros STM32469I Discovery Eeprom Private Macros
bcostm 0:0002c86c2220 119 * @{
bcostm 0:0002c86c2220 120 */
bcostm 0:0002c86c2220 121 /**
bcostm 0:0002c86c2220 122 * @}
bcostm 0:0002c86c2220 123 */
bcostm 0:0002c86c2220 124
bcostm 0:0002c86c2220 125 /** @defgroup STM32469I-Discovery_EEPROM_Private_Variables STM32469I Discovery Eeprom Private Variables
bcostm 0:0002c86c2220 126 * @{
bcostm 0:0002c86c2220 127 */
bcostm 0:0002c86c2220 128 __IO uint16_t EEPROMAddress = 0;
bcostm 0:0002c86c2220 129 __IO uint32_t EEPROMTimeout = EEPROM_READ_TIMEOUT;
bcostm 0:0002c86c2220 130 __IO uint16_t EEPROMDataRead;
bcostm 0:0002c86c2220 131 __IO uint8_t EEPROMDataWrite;
bcostm 0:0002c86c2220 132 /**
bcostm 0:0002c86c2220 133 * @}
bcostm 0:0002c86c2220 134 */
bcostm 0:0002c86c2220 135
bcostm 0:0002c86c2220 136 /** @defgroup STM32469I-Discovery_EEPROM_Private_Function_Prototypes STM32469I Discovery Eeprom Private Prototypes
bcostm 0:0002c86c2220 137 * @{
bcostm 0:0002c86c2220 138 */
bcostm 0:0002c86c2220 139 /**
bcostm 0:0002c86c2220 140 * @}
bcostm 0:0002c86c2220 141 */
bcostm 0:0002c86c2220 142
bcostm 0:0002c86c2220 143 /** @defgroup STM32469I-Discovery_EEPROM_Private_Functions STM32469I Discovery Eeprom Private Functions
bcostm 0:0002c86c2220 144 * @{
bcostm 0:0002c86c2220 145 */
bcostm 0:0002c86c2220 146
bcostm 0:0002c86c2220 147 /**
bcostm 0:0002c86c2220 148 * @brief Initializes peripherals used by the I2C EEPROM driver.
bcostm 0:0002c86c2220 149 *
bcostm 0:0002c86c2220 150 * @note There are 2 different versions of M24LR64 (A01 & A02).
bcostm 0:0002c86c2220 151 * Then try to connect on 1st one (EEPROM_I2C_ADDRESS_A01)
bcostm 0:0002c86c2220 152 * and if problem, check the 2nd one (EEPROM_I2C_ADDRESS_A02)
bcostm 0:0002c86c2220 153 * @retval EEPROM_OK (0) if operation is correctly performed, else return value
bcostm 0:0002c86c2220 154 * different from EEPROM_OK (0)
bcostm 0:0002c86c2220 155 */
bcostm 0:0002c86c2220 156 uint32_t BSP_EEPROM_Init(void)
bcostm 0:0002c86c2220 157 {
bcostm 0:0002c86c2220 158 /* I2C Initialization */
bcostm 0:0002c86c2220 159 EEPROM_IO_Init();
bcostm 0:0002c86c2220 160
bcostm 0:0002c86c2220 161 /* Select the EEPROM address for A01 and check if OK */
bcostm 0:0002c86c2220 162 EEPROMAddress = EEPROM_I2C_ADDRESS_A01;
bcostm 0:0002c86c2220 163 if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
bcostm 0:0002c86c2220 164 {
bcostm 0:0002c86c2220 165 /* Select the EEPROM address for A02 and check if OK */
bcostm 0:0002c86c2220 166 EEPROMAddress = EEPROM_I2C_ADDRESS_A02;
bcostm 0:0002c86c2220 167 if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
bcostm 0:0002c86c2220 168 {
bcostm 0:0002c86c2220 169 return EEPROM_FAIL;
bcostm 0:0002c86c2220 170 }
bcostm 0:0002c86c2220 171 }
bcostm 0:0002c86c2220 172 return EEPROM_OK;
bcostm 0:0002c86c2220 173 }
bcostm 0:0002c86c2220 174
bcostm 0:0002c86c2220 175 /**
bcostm 0:0002c86c2220 176 * @brief DeInitializes the EEPROM.
bcostm 0:0002c86c2220 177 * @retval EEPROM state
bcostm 0:0002c86c2220 178 */
bcostm 0:0002c86c2220 179 uint8_t BSP_EEPROM_DeInit(void)
bcostm 0:0002c86c2220 180 {
bcostm 0:0002c86c2220 181 /* I2C won't be disabled because common to other functionalities */
bcostm 0:0002c86c2220 182 return EEPROM_OK;
bcostm 0:0002c86c2220 183 }
bcostm 0:0002c86c2220 184
bcostm 0:0002c86c2220 185 /**
bcostm 0:0002c86c2220 186 * @brief Reads a block of data from the EEPROM.
bcostm 0:0002c86c2220 187 * @param pBuffer: pointer to the buffer that receives the data read from
bcostm 0:0002c86c2220 188 * the EEPROM.
bcostm 0:0002c86c2220 189 * @param ReadAddr: EEPROM's internal address to start reading from.
bcostm 0:0002c86c2220 190 * @param NumByteToRead: pointer to the variable holding number of bytes to
bcostm 0:0002c86c2220 191 * be read from the EEPROM.
bcostm 0:0002c86c2220 192 *
bcostm 0:0002c86c2220 193 * @note The variable pointed by NumByteToRead is reset to 0 when all the
bcostm 0:0002c86c2220 194 * data are read from the EEPROM. Application should monitor this
bcostm 0:0002c86c2220 195 * variable in order know when the transfer is complete.
bcostm 0:0002c86c2220 196 *
bcostm 0:0002c86c2220 197 * @retval EEPROM_OK (0) if operation is correctly performed, else return value
bcostm 0:0002c86c2220 198 * different from EEPROM_OK (0) or the timeout user callback.
bcostm 0:0002c86c2220 199 */
bcostm 0:0002c86c2220 200 uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
bcostm 0:0002c86c2220 201 {
bcostm 0:0002c86c2220 202 uint32_t buffersize = *NumByteToRead;
bcostm 0:0002c86c2220 203
bcostm 0:0002c86c2220 204 /* Set the pointer to the Number of data to be read. This pointer will be used
bcostm 0:0002c86c2220 205 by the DMA Transfer Completer interrupt Handler in order to reset the
bcostm 0:0002c86c2220 206 variable to 0. User should check on this variable in order to know if the
bcostm 0:0002c86c2220 207 DMA transfer has been complete or not. */
bcostm 0:0002c86c2220 208 EEPROMDataRead = *NumByteToRead;
bcostm 0:0002c86c2220 209
bcostm 0:0002c86c2220 210 if(EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK)
bcostm 0:0002c86c2220 211 {
bcostm 0:0002c86c2220 212 BSP_EEPROM_TIMEOUT_UserCallback();
bcostm 0:0002c86c2220 213 return EEPROM_FAIL;
bcostm 0:0002c86c2220 214 }
bcostm 0:0002c86c2220 215
bcostm 0:0002c86c2220 216 /* If all operations OK, return EEPROM_OK (0) */
bcostm 0:0002c86c2220 217 return EEPROM_OK;
bcostm 0:0002c86c2220 218 }
bcostm 0:0002c86c2220 219
bcostm 0:0002c86c2220 220 /**
bcostm 0:0002c86c2220 221 * @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
bcostm 0:0002c86c2220 222 *
bcostm 0:0002c86c2220 223 * @note The number of bytes (combined to write start address) must not
bcostm 0:0002c86c2220 224 * cross the EEPROM page boundary. This function can only write into
bcostm 0:0002c86c2220 225 * the boundaries of an EEPROM page.
bcostm 0:0002c86c2220 226 * This function doesn't check on boundaries condition (in this driver
bcostm 0:0002c86c2220 227 * the function BSP_EEPROM_WriteBuffer() which calls BSP_EEPROM_WritePage() is
bcostm 0:0002c86c2220 228 * responsible of checking on Page boundaries).
bcostm 0:0002c86c2220 229 *
bcostm 0:0002c86c2220 230 * @param pBuffer: pointer to the buffer containing the data to be written to
bcostm 0:0002c86c2220 231 * the EEPROM.
bcostm 0:0002c86c2220 232 * @param WriteAddr: EEPROM's internal address to write to.
bcostm 0:0002c86c2220 233 * @param NumByteToWrite: pointer to the variable holding number of bytes to
bcostm 0:0002c86c2220 234 * be written into the EEPROM.
bcostm 0:0002c86c2220 235 *
bcostm 0:0002c86c2220 236 * @note The variable pointed by NumByteToWrite is reset to 0 when all the
bcostm 0:0002c86c2220 237 * data are written to the EEPROM. Application should monitor this
bcostm 0:0002c86c2220 238 * variable in order know when the transfer is complete.
bcostm 0:0002c86c2220 239 *
bcostm 0:0002c86c2220 240 * @note This function just configure the communication and enable the DMA
bcostm 0:0002c86c2220 241 * channel to transfer data. Meanwhile, the user application may perform
bcostm 0:0002c86c2220 242 * other tasks in parallel.
bcostm 0:0002c86c2220 243 *
bcostm 0:0002c86c2220 244 * @retval EEPROM_OK (0) if operation is correctly performed, else return value
bcostm 0:0002c86c2220 245 * different from EEPROM_OK (0) or the timeout user callback.
bcostm 0:0002c86c2220 246 */
bcostm 0:0002c86c2220 247 uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
bcostm 0:0002c86c2220 248 {
bcostm 0:0002c86c2220 249 uint32_t buffersize = *NumByteToWrite;
bcostm 0:0002c86c2220 250 uint32_t status = EEPROM_OK;
bcostm 0:0002c86c2220 251
bcostm 0:0002c86c2220 252 /* Set the pointer to the Number of data to be written. This pointer will be used
bcostm 0:0002c86c2220 253 by the DMA Transfer Completer interrupt Handler in order to reset the
bcostm 0:0002c86c2220 254 variable to 0. User should check on this variable in order to know if the
bcostm 0:0002c86c2220 255 DMA transfer has been complete or not. */
bcostm 0:0002c86c2220 256 EEPROMDataWrite = *NumByteToWrite;
bcostm 0:0002c86c2220 257
bcostm 0:0002c86c2220 258 if(EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK)
bcostm 0:0002c86c2220 259 {
bcostm 0:0002c86c2220 260 BSP_EEPROM_TIMEOUT_UserCallback();
bcostm 0:0002c86c2220 261 status = EEPROM_FAIL;
bcostm 0:0002c86c2220 262 }
bcostm 0:0002c86c2220 263
bcostm 0:0002c86c2220 264 if(BSP_EEPROM_WaitEepromStandbyState() != EEPROM_OK)
bcostm 0:0002c86c2220 265 {
bcostm 0:0002c86c2220 266 return EEPROM_FAIL;
bcostm 0:0002c86c2220 267 }
bcostm 0:0002c86c2220 268
bcostm 0:0002c86c2220 269 /* If all operations OK, return EEPROM_OK (0) */
bcostm 0:0002c86c2220 270 return status;
bcostm 0:0002c86c2220 271 }
bcostm 0:0002c86c2220 272
bcostm 0:0002c86c2220 273 /**
bcostm 0:0002c86c2220 274 * @brief Writes buffer of data to the I2C EEPROM.
bcostm 0:0002c86c2220 275 * @param pBuffer: pointer to the buffer containing the data to be written
bcostm 0:0002c86c2220 276 * to the EEPROM.
bcostm 0:0002c86c2220 277 * @param WriteAddr: EEPROM's internal address to write to.
bcostm 0:0002c86c2220 278 * @param NumByteToWrite: number of bytes to write to the EEPROM.
bcostm 0:0002c86c2220 279 * @retval EEPROM_OK (0) if operation is correctly performed, else return value
bcostm 0:0002c86c2220 280 * different from EEPROM_OK (0) or the timeout user callback.
bcostm 0:0002c86c2220 281 */
bcostm 0:0002c86c2220 282 uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
bcostm 0:0002c86c2220 283 {
bcostm 0:0002c86c2220 284 uint16_t numofpage = 0, numofsingle = 0, count = 0;
bcostm 0:0002c86c2220 285 uint16_t addr = 0;
bcostm 0:0002c86c2220 286 uint8_t dataindex = 0;
bcostm 0:0002c86c2220 287 uint32_t status = EEPROM_OK;
bcostm 0:0002c86c2220 288
bcostm 0:0002c86c2220 289 addr = WriteAddr % EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 290 count = EEPROM_PAGESIZE - addr;
bcostm 0:0002c86c2220 291 numofpage = NumByteToWrite / EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 292 numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 293
bcostm 0:0002c86c2220 294 /* If WriteAddr is EEPROM_PAGESIZE aligned */
bcostm 0:0002c86c2220 295 if(addr == 0)
bcostm 0:0002c86c2220 296 {
bcostm 0:0002c86c2220 297 /* If NumByteToWrite < EEPROM_PAGESIZE */
bcostm 0:0002c86c2220 298 if(numofpage == 0)
bcostm 0:0002c86c2220 299 {
bcostm 0:0002c86c2220 300 /* Store the number of data to be written */
bcostm 0:0002c86c2220 301 dataindex = numofsingle;
bcostm 0:0002c86c2220 302 /* Start writing data */
bcostm 0:0002c86c2220 303 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 304 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 305 {
bcostm 0:0002c86c2220 306 return status;
bcostm 0:0002c86c2220 307 }
bcostm 0:0002c86c2220 308 }
bcostm 0:0002c86c2220 309 /* If NumByteToWrite > EEPROM_PAGESIZE */
bcostm 0:0002c86c2220 310 else
bcostm 0:0002c86c2220 311 {
bcostm 0:0002c86c2220 312 while(numofpage--)
bcostm 0:0002c86c2220 313 {
bcostm 0:0002c86c2220 314 /* Store the number of data to be written */
bcostm 0:0002c86c2220 315 dataindex = EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 316 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 317 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 318 {
bcostm 0:0002c86c2220 319 return status;
bcostm 0:0002c86c2220 320 }
bcostm 0:0002c86c2220 321
bcostm 0:0002c86c2220 322 WriteAddr += EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 323 pBuffer += EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 324 }
bcostm 0:0002c86c2220 325
bcostm 0:0002c86c2220 326 if(numofsingle!=0)
bcostm 0:0002c86c2220 327 {
bcostm 0:0002c86c2220 328 /* Store the number of data to be written */
bcostm 0:0002c86c2220 329 dataindex = numofsingle;
bcostm 0:0002c86c2220 330 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 331 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 332 {
bcostm 0:0002c86c2220 333 return status;
bcostm 0:0002c86c2220 334 }
bcostm 0:0002c86c2220 335 }
bcostm 0:0002c86c2220 336 }
bcostm 0:0002c86c2220 337 }
bcostm 0:0002c86c2220 338 /* If WriteAddr is not EEPROM_PAGESIZE aligned */
bcostm 0:0002c86c2220 339 else
bcostm 0:0002c86c2220 340 {
bcostm 0:0002c86c2220 341 /* If NumByteToWrite < EEPROM_PAGESIZE */
bcostm 0:0002c86c2220 342 if(numofpage== 0)
bcostm 0:0002c86c2220 343 {
bcostm 0:0002c86c2220 344 /* If the number of data to be written is more than the remaining space
bcostm 0:0002c86c2220 345 in the current page: */
bcostm 0:0002c86c2220 346 if(NumByteToWrite > count)
bcostm 0:0002c86c2220 347 {
bcostm 0:0002c86c2220 348 /* Store the number of data to be written */
bcostm 0:0002c86c2220 349 dataindex = count;
bcostm 0:0002c86c2220 350 /* Write the data contained in same page */
bcostm 0:0002c86c2220 351 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 352 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 353 {
bcostm 0:0002c86c2220 354 return status;
bcostm 0:0002c86c2220 355 }
bcostm 0:0002c86c2220 356
bcostm 0:0002c86c2220 357 /* Store the number of data to be written */
bcostm 0:0002c86c2220 358 dataindex = (NumByteToWrite - count);
bcostm 0:0002c86c2220 359 /* Write the remaining data in the following page */
bcostm 0:0002c86c2220 360 status = BSP_EEPROM_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 361 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 362 {
bcostm 0:0002c86c2220 363 return status;
bcostm 0:0002c86c2220 364 }
bcostm 0:0002c86c2220 365 }
bcostm 0:0002c86c2220 366 else
bcostm 0:0002c86c2220 367 {
bcostm 0:0002c86c2220 368 /* Store the number of data to be written */
bcostm 0:0002c86c2220 369 dataindex = numofsingle;
bcostm 0:0002c86c2220 370 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 371 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 372 {
bcostm 0:0002c86c2220 373 return status;
bcostm 0:0002c86c2220 374 }
bcostm 0:0002c86c2220 375 }
bcostm 0:0002c86c2220 376 }
bcostm 0:0002c86c2220 377 /* If NumByteToWrite > EEPROM_PAGESIZE */
bcostm 0:0002c86c2220 378 else
bcostm 0:0002c86c2220 379 {
bcostm 0:0002c86c2220 380 NumByteToWrite -= count;
bcostm 0:0002c86c2220 381 numofpage = NumByteToWrite / EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 382 numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 383
bcostm 0:0002c86c2220 384 if(count != 0)
bcostm 0:0002c86c2220 385 {
bcostm 0:0002c86c2220 386 /* Store the number of data to be written */
bcostm 0:0002c86c2220 387 dataindex = count;
bcostm 0:0002c86c2220 388 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 389 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 390 {
bcostm 0:0002c86c2220 391 return status;
bcostm 0:0002c86c2220 392 }
bcostm 0:0002c86c2220 393 WriteAddr += count;
bcostm 0:0002c86c2220 394 pBuffer += count;
bcostm 0:0002c86c2220 395 }
bcostm 0:0002c86c2220 396
bcostm 0:0002c86c2220 397 while(numofpage--)
bcostm 0:0002c86c2220 398 {
bcostm 0:0002c86c2220 399 /* Store the number of data to be written */
bcostm 0:0002c86c2220 400 dataindex = EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 401 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 402 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 403 {
bcostm 0:0002c86c2220 404 return status;
bcostm 0:0002c86c2220 405 }
bcostm 0:0002c86c2220 406 WriteAddr += EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 407 pBuffer += EEPROM_PAGESIZE;
bcostm 0:0002c86c2220 408 }
bcostm 0:0002c86c2220 409 if(numofsingle != 0)
bcostm 0:0002c86c2220 410 {
bcostm 0:0002c86c2220 411 /* Store the number of data to be written */
bcostm 0:0002c86c2220 412 dataindex = numofsingle;
bcostm 0:0002c86c2220 413 status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
bcostm 0:0002c86c2220 414 if(status != EEPROM_OK)
bcostm 0:0002c86c2220 415 {
bcostm 0:0002c86c2220 416 return status;
bcostm 0:0002c86c2220 417 }
bcostm 0:0002c86c2220 418 }
bcostm 0:0002c86c2220 419 }
bcostm 0:0002c86c2220 420 }
bcostm 0:0002c86c2220 421
bcostm 0:0002c86c2220 422 /* If all operations OK, return EEPROM_OK (0) */
bcostm 0:0002c86c2220 423 return EEPROM_OK;
bcostm 0:0002c86c2220 424 }
bcostm 0:0002c86c2220 425
bcostm 0:0002c86c2220 426 /**
bcostm 0:0002c86c2220 427 * @brief Wait for EEPROM Standby state.
bcostm 0:0002c86c2220 428 *
bcostm 0:0002c86c2220 429 * @note This function allows to wait and check that EEPROM has finished the
bcostm 0:0002c86c2220 430 * last operation. It is mostly used after Write operation: after receiving
bcostm 0:0002c86c2220 431 * the buffer to be written, the EEPROM may need additional time to actually
bcostm 0:0002c86c2220 432 * perform the write operation. During this time, it doesn't answer to
bcostm 0:0002c86c2220 433 * I2C packets addressed to it. Once the write operation is complete
bcostm 0:0002c86c2220 434 * the EEPROM responds to its address.
bcostm 0:0002c86c2220 435 *
bcostm 0:0002c86c2220 436 * @retval EEPROM_OK (0) if operation is correctly performed, else return value
bcostm 0:0002c86c2220 437 * different from EEPROM_OK (0) or the timeout user callback.
bcostm 0:0002c86c2220 438 */
bcostm 0:0002c86c2220 439 uint32_t BSP_EEPROM_WaitEepromStandbyState(void)
bcostm 0:0002c86c2220 440 {
bcostm 0:0002c86c2220 441 /* Check if the maximum allowed number of trials has bee reached */
bcostm 0:0002c86c2220 442 if(EEPROM_IO_IsDeviceReady(EEPROMAddress, EEPROM_MAX_TRIALS) != HAL_OK)
bcostm 0:0002c86c2220 443 {
bcostm 0:0002c86c2220 444 /* If the maximum number of trials has been reached, exit the function */
bcostm 0:0002c86c2220 445 BSP_EEPROM_TIMEOUT_UserCallback();
bcostm 0:0002c86c2220 446 return EEPROM_TIMEOUT;
bcostm 0:0002c86c2220 447 }
bcostm 0:0002c86c2220 448 return EEPROM_OK;
bcostm 0:0002c86c2220 449 }
bcostm 0:0002c86c2220 450
bcostm 0:0002c86c2220 451 /**
bcostm 0:0002c86c2220 452 * @brief Basic management of the timeout situation.
bcostm 0:0002c86c2220 453 */
bcostm 0:0002c86c2220 454 __weak void BSP_EEPROM_TIMEOUT_UserCallback(void)
bcostm 0:0002c86c2220 455 {
bcostm 0:0002c86c2220 456 }
bcostm 0:0002c86c2220 457
bcostm 0:0002c86c2220 458 /**
bcostm 0:0002c86c2220 459 * @}
bcostm 0:0002c86c2220 460 */
bcostm 0:0002c86c2220 461
bcostm 0:0002c86c2220 462 /**
bcostm 0:0002c86c2220 463 * @}
bcostm 0:0002c86c2220 464 */
bcostm 0:0002c86c2220 465
bcostm 0:0002c86c2220 466 /**
bcostm 0:0002c86c2220 467 * @}
bcostm 0:0002c86c2220 468 */
bcostm 0:0002c86c2220 469
bcostm 0:0002c86c2220 470 /**
bcostm 0:0002c86c2220 471 * @}
bcostm 0:0002c86c2220 472 */
bcostm 0:0002c86c2220 473
bcostm 0:0002c86c2220 474 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/