mc9s12g128 100pin  erase all eeprom commad

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mc9s12g128 100pin  erase all eeprom commad

Jump to solution
799 Views
张华荣
Contributor II

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

34089_34089.jpgtttt.jpg

Labels (1)
0 Kudos
1 Solution
543 Views
kef2
Senior Contributor IV

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.

View solution in original post

0 Kudos
3 Replies
543 Views
张华荣
Contributor II

Sorry,the MCU is not reset,but the BDM
output ILLEGAL_BP,and the PC jump to a invalid address.

0 Kudos
544 Views
kef2
Senior Contributor IV

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.

0 Kudos
543 Views
张华荣
Contributor II

thanks a lot,i understand!

0 Kudos