I'm using the KEIL µVision4 .
I select Flash/Erase from the menu. It reply "Full Chip Erase Failed!"
I also tried to call a function in the code I managed to download to the MCU before it got stuck. The function is used to erase a flash sector (see code snipped below). Just before calling execute_flash_command() i changed the FTFL->FCCOB0 to 0x44 (Erase All Blocks).
Result:
FSTAT{CCIF] = 1 (the command is ready)
FSTAT[FPVIOL] = 1 (Flash Protection Violation Flag, not good)
static uint8_t erase_flash_sector(uint32_t address)
{
uint32_t i;
// Clear ACCERR & FPVIOL & RDCOLERR flag in flash status register
FTFL->FSTAT = FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK | FTFL_FSTAT_RDCOLERR_MASK;
FTFL->FCCOB0 = 9;
FTFL->FCCOB1 = address >> 16;
FTFL->FCCOB2 = address >> 8;
FTFL->FCCOB3 = address;
execute_flash_command();
// Check error bits
// Get flash status register value
if(FTFL->FSTAT & (FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK | FTFL_FSTAT_RDCOLERR_MASK | FTFL_FSTAT_MGSTAT0_MASK))
{
// Failed
return 0;
}