A flash block address must be in the erased state before being programmed.

Cumulative programming of bits within a flash block address is not allowed

except for status field updates required in EEPROM emulation applications.

Sure write $1234FFFF, then $12345678 to the same address (without sector erase between two writes) will reduce the lifetime of flash. But also there's no guarantee that write $1234FFFF, then $FFFF5678 won't reduce the health of flash.

I'm working with MCF51QE and with routines form AN3942 (ColdFire V1 Flash Programming Routines).

I'm able to program an erased sector of flash, but I can not seem to re-program an allready programmed sector.

I mean, I load application to MCU and write 0x12345678 to address 0x2000.... Let's say that later when some event happens, i want to replace that value with 0x00112233... When I go check address 0x2000 the old value is still written.

After the first programming I execute Flash_Erase at address 0x2000 but that sector remains written... I assume that when erased value should be 0xFFFFFFFF.... What could be wrong?

More over, both routines Flash_Erase and Flash_ByteProgram return error code 0, so no error over there...

> Let's say that later when some event happens, i want to replace that value with 0x00112233...

Then you have to erase the whole flash BLOCK and then rewrite all the data again, together with your changed value.

EEPROM allows byte erase. FLASH is cheaper than EEPROM because it requires the whole block to be erased.

Just because the routine didn't return an error code doesn't mean it didn't get an error, but it may have bugs that mean the errors aren't checked or aren't reported back. The "normal" address for a flash erase command is the base address of the block. Maybe the function you're using doesn't expect the "wrong address" to be passed in and doesn't check for that condition.

If you want to change individual locations, then you need some "EEPROM Emulation" software that provides functions that seem to allow individual reads and writes, but behind the scenes is storing "master" and "diferences" and is handling block erases and data copies.