Hi Abi Abi
This is a brief description about your issue, I'm not sure what's wrong, so could you explain a little more your problem. How did you set this "Flash_SetByteFlash API" that you mentioned?
Accesses to flash memory should be done from RAM. If the FLASH memory is made up of multiple banks it is possible to run code from one bank while programming the other, but as you want to erase all the memory, then you need to make this access from ram
Have a great day,
Jorge Alcala