AnsweredAssumed Answered

STM32L152 issue erasing EEPROM

Question asked by JoeEmerson on Oct 20, 2016
Latest reply on Oct 21, 2016 by ForumSTM32.ForumSTM3

I have the following routine for writing to EEPROM which checks whether the data to be written matches the current EEPROM contents. If there is no match, the EEPROM contents are erased and the new data is written.

    // Enable writing to EEPROM

  // Iterate through data to be written, find where it differs from EEPROM
  // contentsand only re-program where needed
  for ( Index = 0u ; Index < LengthRAM ; ++Index )
    // Check whether contents of EEPROM already match the data to write
    if ( pEEPROM[Index] != pRAM[Index] )
      // Get the address to write to in EEPROM
      uint32_t WordAddress = (uint32_t)&pEEPROM[Index];

      TryCount = 0u ;
      status = FLASH_ERROR_WRP ;
      while ( status != FLASH_COMPLETE ) 
        // Clear flash flags
                             | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR);
        // Erase word in EEPROM
        status = DATA_EEPROM_EraseWord( WordAddress ) ; 
        ++TryCount ;
         // Check that EEPROM has been erased in a reasonable time
        BSP_ASSERT( 10u > TryCount ) ; 
     // Write new data to EEPROM
    status = DATA_EEPROM_ProgramWord( WordAddress, pRAM[Index] ) ;
    BSP_ASSERT( FLASH_COMPLETE == status ) ;

Recently the function DATA_EEPROM_EraseWord()has been returning FLASH_ERROR_PROGRAM on every attempted erase, causing the program to assert a few lines later.

There haven't been any updates to the code responsible for managing the EEPROM, this code was working before, but I have now seen the issue on multiple devices. Is it possible that the EEPROM has been worn out by too may writes? What does the value FLASH_ERROR_PROGRAM signify? Any help would be greatly appreciated.