9 years, 1 month ago.

Internal eeprom life concern for STM32L152RE

I am trying to understand how writes to the internal eeprom occur and how that impacts product life.

Does the chip support true single byte writes or is it really implementing word writes with 3 bytes of a word are being overwritten with the existing values. My concern is that if it is really implementing word writes life of a single byte location could be as short as 300K / 4.

I tried to figure this out from available code and STs site but was not able to get the answer.

The other reason for asking is I am running into difficulty writing floats to this memory. I can easily implement bytes writes for all 4 bytes of a float but if word writes will actually be implemented for each byte I would be shorten life by a factor of 4 with this approach each time a value changes.

Any code to write floats to eeprom would be most appreciated

EDIT: If someone else is having a problem saving as a float this is what I ended up implementing

HAL_StatusTypeDef writeEEPROMFloat(uint32_t address, float data)
   {
   HAL_StatusTypeDef  status;
   address = address + EEPROM_BASE_ADDR;
   if (address >= EEPROM_END_ADDR)
      { //big problem trying to write past the existing eeprom memory
      return((HAL_StatusTypeDef) FLASH_FAILED);
      }
   //save the float bit image into an unsigned int
   unsigned int fasidata = *(unsigned int*)&data;
   __disable_irq();  //turn off interupts
   HAL_FLASHEx_DATAEEPROM_Unlock();  //Unprotect the EEPROM to allow writing
   status = HAL_FLASHEx_DATAEEPROM_Program(TYPEPROGRAMDATA_WORD, address,fasidata);
   HAL_FLASHEx_DATAEEPROM_Lock();  // Reprotect the EEPROM
   __enable_irq();   //turn on interrupts 
     
   return status;
   }

If someone else has aq\ better way of doing the float to unsigned int conversion please let me know but this works well for now.

Question relating to:

1 Answer

9 years, 1 month ago.

I think your method of converting to unsigned int is the best one there is for such purposes. And for lifetime I would be really surprised if a function to write a word, would 4 times do a word-write.