Src/EEPROM_Emul/eeprom_emul.c
EE_Status EE_Format(EE_Erase_type EraseType)
{
  uint32_t page = 0U;

  /* Check if the configuration is 128-bits bank or 2*64-bits bank */
  if (FI_CheckBankConfig() != EE_OK)
  {
    return EE_INVALID_BANK_CFG;
  }
  
#ifdef DUALCORE_FLASH_SHARING
  /* Inform CPU2 about Erase Activity */
  SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
#endif
  
  /* Erase All Pages */
  for (page = START_PAGE; page < (START_PAGE + PAGES_NUMBER); page++)
  {
    /* Check if page erase has to be forced unconditionally (default case) */
    if (EraseType == EE_FORCED_ERASE)
    {
      /* Force page erase independently of its content */
      if (FI_PageErase(page, 1U) != EE_OK)
      {
#ifdef DUALCORE_FLASH_SHARING
        /* Inform CPU2 about end of Erase Activity */
        SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif
        return EE_ERASE_ERROR;
      }
    }
    else /* EraseType == EE_CONDITIONAL_ERASE */
    {
      /* Check if Page is not yet fully erased */
      if (VerifyPageFullyErased(PAGE_ADDRESS(page), PAGE_SIZE) == EE_PAGE_NOTERASED)
      {
        /* Erase the page */
        /* If Erase operation was failed, a Flash error code is returned */
        if (FI_PageErase(page, 1U) != EE_OK)
        {
#ifdef DUALCORE_FLASH_SHARING
          /* Inform CPU2 about end of Erase Activity */
          SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif
          return EE_ERASE_ERROR;
        }
      }
    }
  }
  
  /* To keep their coherency, flush the caches if needed depending on the product */
  FI_CacheFlush();
  
#ifdef DUALCORE_FLASH_SHARING
  /* Inform CPU2 about end of Erase Activity */
  SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif

  /* Set first Page in Active State */
  /* If program operation was failed, a Flash error code is returned */
  if (SetPageState(START_PAGE, STATE_PAGE_ACTIVE) != EE_OK)
  {
    return EE_WRITE_ERROR;
  }

  /* Reset global variables */
  uhNbWrittenElements = (uint16_t)0U;
  ubCurrentActivePage = START_PAGE;
  uwAddressNextWrite = PAGE_HEADER_SIZE; /* Initialize write position just after page header */

  return EE_OK;
}
/**
  * @brief  Erases all flash pages of eeprom emulation, and set first page
  *         header as ACTIVE.
  * @note   This function can be called the very first time eeprom emulation is
  *         used, to prepare flash pages for eeprom emulation with empty eeprom
            variables. It can also be called at any time, to flush all eeprom
  *         variables.
  * @param  EraseType: Type of erase to apply on page requiring to be erased.
  *         This parameter can be one of the following values:
  *          @arg @ref EE_FORCED_ERASE      pages to erase are erased unconditionnally
  *          @arg @ref EE_CONDITIONAL_ERASE pages to erase are erased only if not fully erased
  * @retval EE_Status
  *           - EE_OK: on success
  *           - EE error code: if an error occurs
  */
@brief  Erases all flash pages of eeprom emulation, and set first page
header as ACTIVE.
@note   This function can be called the very first time eeprom emulation is
used, to prepare flash pages for eeprom emulation with empty eeprom
variables. It can also be called at any time, to flush all eeprom
variables.
@param  EraseType: Type of erase to apply on page requiring to be erased.
@brief Erases all flash pages of eeprom emulation and set first page header as ACTIVE . @note This function can be called the very first time eeprom emulation is used to prepare flash pages for eeprom emulation with empty eeprom variables . It can also be called at any time to flush all eeprom variables . @param EraseType : Type of erase to apply on page requiring to be erased .
EE_Status EE_Format(EE_Erase_type EraseType)
{
  uint32_t page = 0U;
  if (FI_CheckBankConfig() != EE_OK)
  {
    return EE_INVALID_BANK_CFG;
  }
#ifdef DUALCORE_FLASH_SHARING
  SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_ON);
#endif
  for (page = START_PAGE; page < (START_PAGE + PAGES_NUMBER); page++)
  {
    if (EraseType == EE_FORCED_ERASE)
    {
      if (FI_PageErase(page, 1U) != EE_OK)
      {
#ifdef DUALCORE_FLASH_SHARING
        SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif
        return EE_ERASE_ERROR;
      }
    }
    else 
    {
      if (VerifyPageFullyErased(PAGE_ADDRESS(page), PAGE_SIZE) == EE_PAGE_NOTERASED)
      {
        if (FI_PageErase(page, 1U) != EE_OK)
        {
#ifdef DUALCORE_FLASH_SHARING
          SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif
          return EE_ERASE_ERROR;
        }
      }
    }
  }
  FI_CacheFlush();
#ifdef DUALCORE_FLASH_SHARING
  SHCI_C2_FLASH_EraseActivity(ERASE_ACTIVITY_OFF);
#endif
  if (SetPageState(START_PAGE, STATE_PAGE_ACTIVE) != EE_OK)
  {
    return EE_WRITE_ERROR;
  }
  uhNbWrittenElements = (uint16_t)0U;
  ubCurrentActivePage = START_PAGE;
  uwAddressNextWrite = PAGE_HEADER_SIZE; 
  return EE_OK;
}
EE_Status EE_Format ( EE_Erase_type EraseType ) { uint32_t page = 0U ; if ( FI_CheckBankConfig ( ) != EE_OK ) { return EE_INVALID_BANK_CFG ; } #ifdef DUALCORE_FLASH_SHARING SHCI_C2_FLASH_EraseActivity ( ERASE_ACTIVITY_ON ) ; #endif for ( page = START_PAGE ; page < ( START_PAGE + PAGES_NUMBER ) ; page ++ ) { if ( EraseType == EE_FORCED_ERASE ) { if ( FI_PageErase ( page , 1U ) != EE_OK ) { #ifdef DUALCORE_FLASH_SHARING SHCI_C2_FLASH_EraseActivity ( ERASE_ACTIVITY_OFF ) ; #endif return EE_ERASE_ERROR ; } } else { if ( VerifyPageFullyErased ( PAGE_ADDRESS ( page ) , PAGE_SIZE ) == EE_PAGE_NOTERASED ) { if ( FI_PageErase ( page , 1U ) != EE_OK ) { #ifdef DUALCORE_FLASH_SHARING SHCI_C2_FLASH_EraseActivity ( ERASE_ACTIVITY_OFF ) ; #endif return EE_ERASE_ERROR ; } } } } FI_CacheFlush ( ) ; #ifdef DUALCORE_FLASH_SHARING SHCI_C2_FLASH_EraseActivity ( ERASE_ACTIVITY_OFF ) ; #endif if ( SetPageState ( START_PAGE , STATE_PAGE_ACTIVE ) != EE_OK ) { return EE_WRITE_ERROR ; } uhNbWrittenElements = ( uint16_t ) 0U ; ubCurrentActivePage = START_PAGE ; uwAddressNextWrite = PAGE_HEADER_SIZE ; return EE_OK ; }
@brief  Erases all flash pages of eeprom emulation, and set first page
         header as ACTIVE.
@brief Erases all flash pages of eeprom emulation and set first page header as ACTIVE .
/* Check if the configuration is 128-bits bank or 2*64-bits bank */ /* Inform CPU2 about Erase Activity */ /* Erase All Pages */ /* Check if page erase has to be forced unconditionally (default case) */ /* Force page erase independently of its content */ /* Inform CPU2 about end of Erase Activity */ /* EraseType == EE_CONDITIONAL_ERASE */ /* Check if Page is not yet fully erased */ /* Erase the page */ /* If Erase operation was failed, a Flash error code is returned */ /* Inform CPU2 about end of Erase Activity */ /* To keep their coherency, flush the caches if needed depending on the product */ /* Inform CPU2 about end of Erase Activity */ /* Set first Page in Active State */ /* If program operation was failed, a Flash error code is returned */ /* Reset global variables */ /* Initialize write position just after page header */