cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 issue erasing EEPROM

s0071904
Associate II
Posted on October 20, 2016 at 11:13

Hi,

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

  DATA_EEPROM_Unlock();

  // 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_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR

                             | 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.

#eeprom #stm32l152
1 REPLY 1
slimen
Senior
Posted on October 21, 2016 at 15:38

Hello,

Could you please provide details about your environment ? What compiler and debugger are you using? 

Regards