Do you mean you want to erase program flash area not FlexNVM? If yes, please make sure your code is in RAM area not in code flash area.
When erasing or programming a Flash block, the internal charge pump is turned on, and during such time, the memory is not accessible; therefore, you will get errors if you call the Flash erase/write routines from the same memory block that will be erased/written. In order to avoid these issues and like Li mentioned, these routines should be running on RAM, or, if the MCU has dual Flash array, the routines should be running from the other Flash array.
Hope this will be useful for you.
Retrieving data ...