AnsweredAssumed Answered

[P-Flash] Erase and Write to PFlash will occur ILLEGAL_BP in MC9S12XS128

Question asked by Pogo Lin on Sep 28, 2011
Latest reply on Sep 28, 2011 by Pogo Lin

I've tried to erase and write data to PFlash, but it will occur ILLEGAL_BP. The following list is my test environment.


MCU: MC9S12XS128

IDE : CodeWarrior IDE version 5.9.0 Build 2836

BDM: TBDML

 

Here is my Code

void PFlash_Write(word *ptr){    unsigned char i;    while((FSTAT & FSTAT_CCIF_MASK) == 0);  //wait if command in progress    FSTAT = 0x30;       //clear ACCERR and PVIOL    FCCOBIX = 0x00;    FCCOB = 0x067E;     //program 0x7E0000    FCCOBIX = 0x01;    FCCOB = 0x0000;    for(i=2; i<6; i++)  //fill data (4 words) to FCCOB register    {        FCCOBIX = i;        FCCOB = *ptr;        ptr++;    }    FSTAT = 0x80;       //launch command    while((FSTAT & FSTAT_CCIF_MASK) == 0);  //wait for done}/******************************************************************************/void PFlash_Erase(void){    while((FSTAT & FSTAT_CCIF_MASK) == 0);  //wait if command in progress    FSTAT = 0x30;       //clear ACCERR and PVIOL    FCCOBIX = 0x00;    FCCOB = 0x0A7E;     //erase 0x7E0000    FCCOBIX = 0x01;    FCCOB = 0x0000;    FSTAT = 0x80;       //launch command    while((FSTAT & FSTAT_CCIF_MASK) == 0);  //wait for done}void main{    unsigned short u16Data[4];    for( ;     {        ....        if( getkey() == 'w' )        {            u16Data[0] = 100;            u16Data[1] = 110;            u16Data[2] = 120;            u16Data[3] = 130;            DisableInterrupts;            PFlash_Erase();            PFlash_Write(u16Data);            EnableInterrupts;        }    }}

 Could you have any suggestion for me to solve this problem? Thanks a lot.

 

 

Regards,

Pogo

Outcomes