Hi,
I am not sure how you program the FOPT field? Are you using a debugger or a software driver to program the flash?
If you are using a debugger, then I know that IAR does not allow writes to the flash configuration field by default. They did this in order to reduce the risk of customers accidentally securing devices.
If you are using a software driver, then you should make sure that you erase the sector before attempting to program the flash configuration field. Because the security field has an erased bit in it, the whole sector has to be erased and then the flash configuraton field including the FOPT and security settings can be programmed.