STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f769i_discovery_eeprom.c
Go to the documentation of this file.
1 
88 /* Includes ------------------------------------------------------------------*/
90 
128 __IO uint16_t EEPROMAddress = 0;
154 uint32_t BSP_EEPROM_Init(void)
155 {
156  /* I2C Initialization */
157  EEPROM_IO_Init();
158 
159  /* Select the EEPROM address for A01 and check if OK */
162  {
163  /* Select the EEPROM address for A02 and check if OK */
166  {
167  return EEPROM_FAIL;
168  }
169  }
170  return EEPROM_OK;
171 }
172 
177 uint8_t BSP_EEPROM_DeInit(void)
178 {
179  /* I2C won't be disabled because common to other functionalities */
180  return EEPROM_OK;
181 }
182 
198 uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
199 {
200  uint32_t buffersize = *NumByteToRead;
201 
202  /* Set the pointer to the Number of data to be read. This pointer will be used
203  by the DMA Transfer Completer interrupt Handler in order to reset the
204  variable to 0. User should check on this variable in order to know if the
205  DMA transfer has been complete or not. */
206  EEPROMDataRead = *NumByteToRead;
207 
208  if(EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK)
209  {
211  return EEPROM_FAIL;
212  }
213 
214  /* If all operations OK, return EEPROM_OK (0) */
215  return EEPROM_OK;
216 }
217 
245 uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
246 {
247  uint32_t buffersize = *NumByteToWrite;
248  uint32_t status = EEPROM_OK;
249 
250  /* Set the pointer to the Number of data to be written. This pointer will be used
251  by the DMA Transfer Completer interrupt Handler in order to reset the
252  variable to 0. User should check on this variable in order to know if the
253  DMA transfer has been complete or not. */
254  EEPROMDataWrite = *NumByteToWrite;
255 
256  if(EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK)
257  {
259  status = EEPROM_FAIL;
260  }
261 
263  {
264  return EEPROM_FAIL;
265  }
266 
267  /* If all operations OK, return EEPROM_OK (0) */
268  return status;
269 }
270 
280 uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
281 {
282  uint16_t numofpage = 0, numofsingle = 0, count = 0;
283  uint16_t addr = 0;
284  uint8_t dataindex = 0;
285  uint32_t status = EEPROM_OK;
286 
287  addr = WriteAddr % EEPROM_PAGESIZE;
288  count = EEPROM_PAGESIZE - addr;
289  numofpage = NumByteToWrite / EEPROM_PAGESIZE;
290  numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
291 
292  /* If WriteAddr is EEPROM_PAGESIZE aligned */
293  if(addr == 0)
294  {
295  /* If NumByteToWrite < EEPROM_PAGESIZE */
296  if(numofpage == 0)
297  {
298  /* Store the number of data to be written */
299  dataindex = numofsingle;
300  /* Start writing data */
301  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
302  if(status != EEPROM_OK)
303  {
304  return status;
305  }
306  }
307  /* If NumByteToWrite > EEPROM_PAGESIZE */
308  else
309  {
310  while(numofpage--)
311  {
312  /* Store the number of data to be written */
313  dataindex = EEPROM_PAGESIZE;
314  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
315  if(status != EEPROM_OK)
316  {
317  return status;
318  }
319 
320  WriteAddr += EEPROM_PAGESIZE;
321  pBuffer += EEPROM_PAGESIZE;
322  }
323 
324  if(numofsingle!=0)
325  {
326  /* Store the number of data to be written */
327  dataindex = numofsingle;
328  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
329  if(status != EEPROM_OK)
330  {
331  return status;
332  }
333  }
334  }
335  }
336  /* If WriteAddr is not EEPROM_PAGESIZE aligned */
337  else
338  {
339  /* If NumByteToWrite < EEPROM_PAGESIZE */
340  if(numofpage== 0)
341  {
342  /* If the number of data to be written is more than the remaining space
343  in the current page: */
344  if(NumByteToWrite > count)
345  {
346  /* Store the number of data to be written */
347  dataindex = count;
348  /* Write the data contained in same page */
349  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
350  if(status != EEPROM_OK)
351  {
352  return status;
353  }
354 
355  /* Store the number of data to be written */
356  dataindex = (NumByteToWrite - count);
357  /* Write the remaining data in the following page */
358  status = BSP_EEPROM_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&dataindex));
359  if(status != EEPROM_OK)
360  {
361  return status;
362  }
363  }
364  else
365  {
366  /* Store the number of data to be written */
367  dataindex = numofsingle;
368  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
369  if(status != EEPROM_OK)
370  {
371  return status;
372  }
373  }
374  }
375  /* If NumByteToWrite > EEPROM_PAGESIZE */
376  else
377  {
378  NumByteToWrite -= count;
379  numofpage = NumByteToWrite / EEPROM_PAGESIZE;
380  numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
381 
382  if(count != 0)
383  {
384  /* Store the number of data to be written */
385  dataindex = count;
386  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
387  if(status != EEPROM_OK)
388  {
389  return status;
390  }
391  WriteAddr += count;
392  pBuffer += count;
393  }
394 
395  while(numofpage--)
396  {
397  /* Store the number of data to be written */
398  dataindex = EEPROM_PAGESIZE;
399  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
400  if(status != EEPROM_OK)
401  {
402  return status;
403  }
404  WriteAddr += EEPROM_PAGESIZE;
405  pBuffer += EEPROM_PAGESIZE;
406  }
407  if(numofsingle != 0)
408  {
409  /* Store the number of data to be written */
410  dataindex = numofsingle;
411  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
412  if(status != EEPROM_OK)
413  {
414  return status;
415  }
416  }
417  }
418  }
419 
420  /* If all operations OK, return EEPROM_OK (0) */
421  return EEPROM_OK;
422 }
423 
438 {
439  /* Check if the maximum allowed number of trials has bee reached */
441  {
442  /* If the maximum number of trials has been reached, exit the function */
444  return EEPROM_TIMEOUT;
445  }
446  return EEPROM_OK;
447 }
448 
454 {
455 }
456 
473 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void EEPROM_IO_Init(void)
Initializes peripherals used by the I2C EEPROM driver.
uint32_t BSP_EEPROM_Init(void)
Initializes peripherals used by the I2C EEPROM driver.
#define EEPROM_I2C_ADDRESS_A01
EEPROM I2C Slave address 1.
uint32_t BSP_EEPROM_WritePage(uint8_t *pBuffer, uint16_t WriteAddr, uint8_t *NumByteToWrite)
Writes more than one byte to the EEPROM with a single WRITE cycle.
#define EEPROM_I2C_ADDRESS_A02
EEPROM I2C Slave address 2.
uint32_t BSP_EEPROM_ReadBuffer(uint8_t *pBuffer, uint16_t ReadAddr, uint16_t *NumByteToRead)
Reads a block of data from the EEPROM.
__IO uint8_t EEPROMDataWrite
__IO uint16_t EEPROMDataRead
uint32_t BSP_EEPROM_WaitEepromStandbyState(void)
Wait for EEPROM Standby state.
uint8_t BSP_EEPROM_DeInit(void)
DeInitializes the EEPROM.
#define __IO
Definition: core_cm0.h:213
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Checks if target device is ready for communication.
HAL_StatusTypeDef EEPROM_IO_ReadData(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pBuffer, uint32_t BufferSize)
Read data from I2C EEPROM driver in using DMA channel.
#define EEPROM_PAGESIZE
#define EEPROM_OK
uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
Writes buffer of data to the I2C EEPROM.
__weak void BSP_EEPROM_TIMEOUT_UserCallback(void)
Basic management of the timeout situation.
__IO uint16_t EEPROMAddress
HAL_StatusTypeDef EEPROM_IO_WriteData(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pBuffer, uint32_t BufferSize)
Write data to I2C EEPROM driver in using DMA channel.
#define EEPROM_MAX_TRIALS
This file contains all the functions prototypes for the stm32f769i_discovery_eeprom.c firmware driver.
#define EEPROM_TIMEOUT
#define EEPROM_FAIL