When I call the below function,the all eeprom(0x400-0x13FF) is erased and the MCU reset.Please help me.
void Eep_EraseAllEeprom(void)
{
FSTAT =0x30U; /*Before launching a command, the ACCERR and FPVIOL bits in the FSTAT registermust be clear*/
FCCOBIX = 0x00U;
FCCOB = 0x0900U; /*the Erase flash block command is 0x09*/
CCOBIX++;
FCCOB = 0x0400;
FSTAT =0x80U; /*FSTAT register (to launch command)Clear CCIF 0x80*/
}
the Init function is below:
void Eep_Init(void)
{
CLKDIV_FDIVLCK = 0x01U;
FCLKDIV_FDIV = 0x18U;
FCNFG_CCIE =0x00U;
FCNFG_IGNSF = 0x00U;
FCNFG_FDFD = 0x01U;
FCNFG_FSFD = 0x01U;
FERCNFG_DFDIE = 0x00U;
FERCNFG_SFDIE = 0x00U;
FSTAT_CCIF = 0x01U;
FSTAT_ACCERR = 0x01U;
FSTAT_FPVIOL = 0x01U;
FERSTAT_DFDIF = 0x01U;
FERSTAT_SFDIF = 0x01U;
DFPROT_DPOPEN = 0x01U; /*disable protection*/
DFPROT_DPS = 0x00U;
}
the Erase flash block is below
已解决! 转到解答。
Erase block command is one of Mass Erase commands. And if you look at 29.4.5 Allowed Simultaneous P-Flash and EEPROM Operations, you may notice that P-flash simultaneous Read from P-flash and Mass Erase EEPROM is not allowed. Effect of this is that P-flash is not readable while Mass Erase command is applied to EEPROM block. CPU is unable to read code (and interrupt vectors) from P-flash and runs away. You need to either use sector erase command and iterate with it over entire EEPROM array, or move parts of your code from P-flash to RAM.
Erase block command is one of Mass Erase commands. And if you look at 29.4.5 Allowed Simultaneous P-Flash and EEPROM Operations, you may notice that P-flash simultaneous Read from P-flash and Mass Erase EEPROM is not allowed. Effect of this is that P-flash is not readable while Mass Erase command is applied to EEPROM block. CPU is unable to read code (and interrupt vectors) from P-flash and runs away. You need to either use sector erase command and iterate with it over entire EEPROM array, or move parts of your code from P-flash to RAM.