Hello,
If you do have Flash programming routines inside your MCU, your ERASE function is maybe called.
There is a way to prevent this by securing your Flash, but it doesn't solve the root of the issue and could produce other un-desired behaviour.
Is it the whole Flash being erased or an area in particular ?
May be your code runs away and starts the erase routine. Try and put a special instruction to stop the MCU at start of routine if you can reproduce the issue.
Cheers,
Alban.