1) Code flash operations are blocking, unlike Data Flash operations which can run in the background.
2) When you are using the Flash module and you have Code Flash programming enabled, the Flash API functions and anything they may call are placed into RAM by the linker.
3) You cannot read ROM (Code Flash) while a Code Flash programming/erase function is in progress. If you do your application will crash.
4) Since Code Flash operations are blocking, you may run from ROM, as your application will be blocked until the operation completes- so there are scenarios where you can make this work.
5) However if you execute a Code Flash operation, a write for example, and you get an interrupt that vectors to a ROM address, you will crash.
6) Similarly in a multithreaded environment you could see the same problem.
7) The following approach to writing to Flash could work, (or you could relocate your vector table to RAM).
a) Disable interrupts
b) Execute a code flash operation
8) But remember, this statement is always true: If you read ROM (Code Flash) while the Flash is in Programming/Erase mode (ie. a Code Flash operation is in progress), your application will crash.