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, that bitwise 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
uint32_t Address = 0x08007900;
*(uint32_t *)Address = (uint32_t) 0x00;
but it doesn't work.
if i set ERASE and PROG bits whole the page(256 Byte) will be erased!
what can i do for erasing 1 byte or 1 word?