why erase flash before writing?
Flash erase sets all bits to 1, so the flash write can either leave the bit alone or switch it to 0. If erase is not performed in advance, a flash write of 1 over a bit that is currently 0 has no effect. ... Bits can only be made '0', so if a byte has a '0' in the wrong place, you'll need to erase.