stm32f769i_discovery_eeprom.c
Go to the documentation of this file.
1 
87 /* Dependencies
88 - stm32f769i_discovery.c
89 EndDependencies */
90 
91 /* Includes ------------------------------------------------------------------*/
93 
131 __IO uint16_t EEPROMAddress = 0;
157 uint32_t BSP_EEPROM_Init(void)
158 {
159  /* I2C Initialization */
160  EEPROM_IO_Init();
161 
162  /* Select the EEPROM address for A01 and check if OK */
165  {
166  /* Select the EEPROM address for A02 and check if OK */
169  {
170  return EEPROM_FAIL;
171  }
172  }
173  return EEPROM_OK;
174 }
175 
180 uint8_t BSP_EEPROM_DeInit(void)
181 {
182  /* I2C won't be disabled because common to other functionalities */
183  return EEPROM_OK;
184 }
185 
201 uint32_t BSP_EEPROM_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t* NumByteToRead)
202 {
203  uint32_t buffersize = *NumByteToRead;
204 
205  /* Set the pointer to the Number of data to be read. This pointer will be used
206  by the DMA Transfer Completer interrupt Handler in order to reset the
207  variable to 0. User should check on this variable in order to know if the
208  DMA transfer has been complete or not. */
209  EEPROMDataRead = *NumByteToRead;
210 
211  if(EEPROM_IO_ReadData(EEPROMAddress, ReadAddr, pBuffer, buffersize) != HAL_OK)
212  {
214  return EEPROM_FAIL;
215  }
216 
217  /* If all operations OK, return EEPROM_OK (0) */
218  return EEPROM_OK;
219 }
220 
248 uint32_t BSP_EEPROM_WritePage(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t* NumByteToWrite)
249 {
250  uint32_t buffersize = *NumByteToWrite;
251  uint32_t status = EEPROM_OK;
252 
253  /* Set the pointer to the Number of data to be written. This pointer will be used
254  by the DMA Transfer Completer interrupt Handler in order to reset the
255  variable to 0. User should check on this variable in order to know if the
256  DMA transfer has been complete or not. */
257  EEPROMDataWrite = *NumByteToWrite;
258 
259  if(EEPROM_IO_WriteData(EEPROMAddress, WriteAddr, pBuffer, buffersize) != HAL_OK)
260  {
262  status = EEPROM_FAIL;
263  }
264 
266  {
267  return EEPROM_FAIL;
268  }
269 
270  /* If all operations OK, return EEPROM_OK (0) */
271  return status;
272 }
273 
283 uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
284 {
285  uint16_t numofpage = 0, numofsingle = 0, count = 0;
286  uint16_t addr = 0;
287  uint8_t dataindex = 0;
288  uint32_t status = EEPROM_OK;
289 
290  addr = WriteAddr % EEPROM_PAGESIZE;
291  count = EEPROM_PAGESIZE - addr;
292  numofpage = NumByteToWrite / EEPROM_PAGESIZE;
293  numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
294 
295  /* If WriteAddr is EEPROM_PAGESIZE aligned */
296  if(addr == 0)
297  {
298  /* If NumByteToWrite < EEPROM_PAGESIZE */
299  if(numofpage == 0)
300  {
301  /* Store the number of data to be written */
302  dataindex = numofsingle;
303  /* Start writing data */
304  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
305  if(status != EEPROM_OK)
306  {
307  return status;
308  }
309  }
310  /* If NumByteToWrite > EEPROM_PAGESIZE */
311  else
312  {
313  while(numofpage--)
314  {
315  /* Store the number of data to be written */
316  dataindex = EEPROM_PAGESIZE;
317  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
318  if(status != EEPROM_OK)
319  {
320  return status;
321  }
322 
323  WriteAddr += EEPROM_PAGESIZE;
324  pBuffer += EEPROM_PAGESIZE;
325  }
326 
327  if(numofsingle!=0)
328  {
329  /* Store the number of data to be written */
330  dataindex = numofsingle;
331  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
332  if(status != EEPROM_OK)
333  {
334  return status;
335  }
336  }
337  }
338  }
339  /* If WriteAddr is not EEPROM_PAGESIZE aligned */
340  else
341  {
342  /* If NumByteToWrite < EEPROM_PAGESIZE */
343  if(numofpage== 0)
344  {
345  /* If the number of data to be written is more than the remaining space
346  in the current page: */
347  if(NumByteToWrite > count)
348  {
349  /* Store the number of data to be written */
350  dataindex = count;
351  /* Write the data contained in same page */
352  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
353  if(status != EEPROM_OK)
354  {
355  return status;
356  }
357 
358  /* Store the number of data to be written */
359  dataindex = (NumByteToWrite - count);
360  /* Write the remaining data in the following page */
361  status = BSP_EEPROM_WritePage((uint8_t*)(pBuffer + count), (WriteAddr + count), (uint8_t*)(&dataindex));
362  if(status != EEPROM_OK)
363  {
364  return status;
365  }
366  }
367  else
368  {
369  /* Store the number of data to be written */
370  dataindex = numofsingle;
371  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
372  if(status != EEPROM_OK)
373  {
374  return status;
375  }
376  }
377  }
378  /* If NumByteToWrite > EEPROM_PAGESIZE */
379  else
380  {
381  NumByteToWrite -= count;
382  numofpage = NumByteToWrite / EEPROM_PAGESIZE;
383  numofsingle = NumByteToWrite % EEPROM_PAGESIZE;
384 
385  if(count != 0)
386  {
387  /* Store the number of data to be written */
388  dataindex = count;
389  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
390  if(status != EEPROM_OK)
391  {
392  return status;
393  }
394  WriteAddr += count;
395  pBuffer += count;
396  }
397 
398  while(numofpage--)
399  {
400  /* Store the number of data to be written */
401  dataindex = EEPROM_PAGESIZE;
402  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
403  if(status != EEPROM_OK)
404  {
405  return status;
406  }
407  WriteAddr += EEPROM_PAGESIZE;
408  pBuffer += EEPROM_PAGESIZE;
409  }
410  if(numofsingle != 0)
411  {
412  /* Store the number of data to be written */
413  dataindex = numofsingle;
414  status = BSP_EEPROM_WritePage(pBuffer, WriteAddr, (uint8_t*)(&dataindex));
415  if(status != EEPROM_OK)
416  {
417  return status;
418  }
419  }
420  }
421  }
422 
423  /* If all operations OK, return EEPROM_OK (0) */
424  return EEPROM_OK;
425 }
426 
441 {
442  /* Check if the maximum allowed number of trials has bee reached */
444  {
445  /* If the maximum number of trials has been reached, exit the function */
447  return EEPROM_TIMEOUT;
448  }
449  return EEPROM_OK;
450 }
451 
457 {
458 }
459 
476 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
EEPROMDataRead
__IO uint16_t EEPROMDataRead
Definition: stm32f769i_discovery_eeprom.c:132
EEPROMDataWrite
__IO uint8_t EEPROMDataWrite
Definition: stm32f769i_discovery_eeprom.c:133
EEPROM_I2C_ADDRESS_A02
#define EEPROM_I2C_ADDRESS_A02
EEPROM I2C Slave address 2.
Definition: stm32469i_discovery.h:249
BSP_EEPROM_WritePage
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.
Definition: stm32f769i_discovery_eeprom.c:248
EEPROM_IO_Init
void EEPROM_IO_Init(void)
Initializes peripherals used by the I2C EEPROM driver.
Definition: stm32469i_discovery.c:793
EEPROM_IO_WriteData
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.
Definition: stm32469i_discovery.c:806
EEPROMAddress
__IO uint16_t EEPROMAddress
Definition: stm32f769i_discovery_eeprom.c:131
BSP_EEPROM_WriteBuffer
uint32_t BSP_EEPROM_WriteBuffer(uint8_t *pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
Writes buffer of data to the I2C EEPROM.
Definition: stm32f769i_discovery_eeprom.c:283
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
BSP_EEPROM_TIMEOUT_UserCallback
__weak void BSP_EEPROM_TIMEOUT_UserCallback(void)
Basic management of the timeout situation.
Definition: stm32f769i_discovery_eeprom.c:456
EEPROM_TIMEOUT
#define EEPROM_TIMEOUT
Definition: stm32f769i_discovery_eeprom.h:81
count
size_t count
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/tests/test_common/ma_test_common.c:31
EEPROM_OK
#define EEPROM_OK
Definition: stm32f769i_discovery_eeprom.h:79
EEPROM_I2C_ADDRESS_A01
#define EEPROM_I2C_ADDRESS_A01
EEPROM I2C Slave address 1.
Definition: stm32469i_discovery.h:244
EEPROM_IO_IsDeviceReady
HAL_StatusTypeDef EEPROM_IO_IsDeviceReady(uint16_t DevAddress, uint32_t Trials)
Checks if target device is ready for communication.
Definition: stm32469i_discovery.c:831
BSP_EEPROM_DeInit
uint8_t BSP_EEPROM_DeInit(void)
DeInitializes the EEPROM.
Definition: stm32f769i_discovery_eeprom.c:180
stm32f769i_discovery_eeprom.h
This file contains all the functions prototypes for the stm32f769i_discovery_eeprom....
EEPROM_IO_ReadData
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.
Definition: stm32469i_discovery.c:819
BSP_EEPROM_WaitEepromStandbyState
uint32_t BSP_EEPROM_WaitEepromStandbyState(void)
Wait for EEPROM Standby state.
Definition: stm32f769i_discovery_eeprom.c:440
BSP_EEPROM_Init
uint32_t BSP_EEPROM_Init(void)
Initializes peripherals used by the I2C EEPROM driver.
Definition: stm32f769i_discovery_eeprom.c:157
BSP_EEPROM_ReadBuffer
uint32_t BSP_EEPROM_ReadBuffer(uint8_t *pBuffer, uint16_t ReadAddr, uint16_t *NumByteToRead)
Reads a block of data from the EEPROM.
Definition: stm32f769i_discovery_eeprom.c:201
EEPROM_FAIL
#define EEPROM_FAIL
Definition: stm32f769i_discovery_eeprom.h:80
EEPROM_PAGESIZE
#define EEPROM_PAGESIZE
Definition: stm32f769i_discovery_eeprom.h:72
EEPROM_MAX_TRIALS
#define EEPROM_MAX_TRIALS
Definition: stm32f769i_discovery_eeprom.h:77


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:53