AnsweredAssumed Answered

CANNOT erase flash for MPC5748G

Question asked by Larry Li on Jun 7, 2016
Latest reply on Mar 3, 2017 by Dennis Yuan

Dear All,

 

When I use the below test code to erase flash, write flash, then erase flash again, something wrong may occurs.

I could write the data well.

However I CANNOT to erase the flash.

Could someone help me?

 

void bl_flash_test(void)

{

        //unlock mid block 0x00FB_8000 - 0x00FB_FFFF

        C55FMC.LOCK0.R &= 0xFFFFFDFF;

   

        //erase the mid block

        C55FMC.MCR.B.ERS = 1;

        C55FMC.SEL0.R = 0x00000200; //select the mid block

        *(unsigned int*)0x00FB8000 = 0xFFFFFFFF;    //interlock write

        C55FMC.MCR.B.EHV = 1;

        while(C55FMC.MCR.B.DONE == 0);

        C55FMC.MCR.B.EHV = 0;

        C55FMC.MCR.B.ERS = 0;

   

        //program one page in the mid block  This part can work well. Data is wrote to flash.

        C55FMC.MCR.B.PGM = 1;

        *(unsigned int*)0x00FB8000 = 0x11111111;    //interlock write

        *(unsigned int*)0x00FB8004 = 0x22222222;   

        *(unsigned int*)0x00FB8008 = 0x33333333;

        *(unsigned int*)0x00FB800C = 0x44444444;

        *(unsigned int*)0x00FB8010 = 0x55555555;

        *(unsigned int*)0x00FB8014 = 0x66666666;

        *(unsigned int*)0x00FB8018 = 0x77777777;

        *(unsigned int*)0x00FB801C = 0x88888888;              

        C55FMC.MCR.B.EHV = 1;

        while(C55FMC.MCR.B.DONE == 0);

        C55FMC.MCR.B.EHV = 0;

        C55FMC.MCR.B.PGM = 0;

 

 

        //erase the mid block     This part CANNOT work wll. The data after 0x00FB8004 is still store in flash.

        C55FMC.MCR.B.ERS = 1;

        C55FMC.SEL0.R = 0x00000200; //select the mid block

        *(unsigned int*)0x00FB8000 = 0xFFFFFFFF;    //interlock write

        C55FMC.MCR.B.EHV = 1;

        while(C55FMC.MCR.B.DONE == 0);

        C55FMC.MCR.B.EHV = 0;

        C55FMC.MCR.B.ERS = 0;

}

Outcomes