MC9s12G64 P-Flash trouble with reading and writing There has been an error erasing the 0x4000 address

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

MC9s12G64 P-Flash trouble with reading and writing There has been an error erasing the 0x4000 address

588 Views
songxiangli
Contributor I

MC9s12G64 P-Flash trouble with reading and writing。There has been an error erasing the P-Flash 0x4000 address,

The code reads as follows:

void EEPROM_Erase(unsigned long ADDR18)
{
while(FSTAT_CCIF==0);
if(FSTAT_ACCERR) //判断并清除标志位;
FSTAT_ACCERR=1;
if(FSTAT_FPVIOL) //判断并清除标志位;
FSTAT_FPVIOL=1;

FCCOBIX_CCOBIX=0x00;
FCCOB = 0x0A00;             //  Erase P-Flash Sector
FCCOBIX_CCOBIX=0x01;
FCCOB = (unsigned int)ADDR18; //写入低16位的地址
FSTAT_CCIF=1; //启动执行命令
while(FSTAT_CCIF==0); //等待执行完成
}

Run to FSTAT_CCIF=1 , happen  ACCERR = 1  。。。

How to do?

Thank YOU!!!

Labels (1)
Tags (2)
0 Kudos
1 Reply

356 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

it looks like you are performing the code read on the block of flash which is E/W. There is a rule that the code is not allowed to run out of the flash which is E/W. because of this the loop which waits for CCIF must be place in different memory.

I would like to suggest you to look at the code:

//==============================================================================
//PFLASH Send_Command / Send_Command2
//==============================================================================
//this function has to be stored in RAM memory
//the main code in C language is:
//  {
//    DisableInterrupts;      //start critical section
//    FSTAT_CCIF = 1;         //launch command
//    while(FSTAT_CCIF == 0); //wait for done
//    EnableInterrupts;       //end critical section
//  }
//Option1: we could define code in RAM as variable array with disassembled code.
static unsigned char Send_Command[]=
{
  0x14, 0x10, 0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x10, 0xEF, 0x3D
};
//Option2: we could define code in RAM as C code and use #pragmas for placement it into RAM segment (see prm file).
#pragma CODE_SEG __NEAR_SEG MY_RAM
void Send_Command2(void)
{
   DisableInterrupts;      //start critical section
   FSTAT_CCIF = 1;         //launch command
   while(FSTAT_CCIF == 0); //wait for done
   EnableInterrupts;       //end critical section
}
#pragma CODE_SEG DEFAULT

which is a part of the project G240-Flash-CW51 which can be found in the https://community.nxp.com/docs/DOC-93792 

Best regards,

Ladislav

0 Kudos