cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Problem

mafix mafix
Associate II
Posted on September 03, 2017 at 14:38

Hello,

I use HAl_Flash driver on STM32L152RBT6 to read, write and erase internal flash memory(EEPROM).

when i try to write new data to flash, thatbitwise OR with previous value.

(

E.g. at address 0x08007000 pre-save =(int) 5, data =(int) 16 stored-value = (int) 21)

so i need to erase at the specified address before try to store new data on it.

In datasheet clearly explained how can erase

a word (unsigned int ** 4Byte).

Data EEPROM word erase

This operation is used to erase a word in Data EEPROM. To do so:

  • Unlock the Data EEPROM and the FLASH_PECR register
  • Write a word to a valid address in data EEPROM with the value 0x0000 0000
  • This activates an erase phase

code:

uint32_t Address = 0x08007900;
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
*(uint32_t *)Address = (uint32_t) 0x00;
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
�?�?�?�?�?�?

but it doesn't work.

if i set ERASE and PROG bits whole the page(256Byte) will be erased!

SET_BIT(FLASH->PECR, FLASH_PECR_ERASE);
SET_BIT(FLASH->PECR, FLASH_PECR_PROG);�?�?

what can i do for erasing 1 byte or 1 word?

thanks.

#eeprom #flash-erase
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on September 03, 2017 at 18:30

Perhaps you should be using the EEPROM, which is situated at 0x08080000..0x08080FFF ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
Posted on September 03, 2017 at 16:19

HAL_FLASHEx_DATAEEPROM_Unlock()

HAL_FLASHEx_DATAEEPROM_Erase(FLASH_TYPEERASEDATA_WORD,0x08007900);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 03, 2017 at 17:02

Thanks to reply.

Also HAL_FLASHEx_DATAEEPROM_Erase() not erase anything. Just can erase full page but not a word or a byte.

Posted on September 03, 2017 at 18:30

Perhaps you should be using the EEPROM, which is situated at 0x08080000..0x08080FFF ?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 03, 2017 at 19:14

thats right!

only 4KB of internal memory is EEPROM and 128KB is Flash memory.

thanks bro.