Flash Sector Erase Issue

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

Flash Sector Erase Issue

2,088 Views
tafengchung
Contributor II

My MCU is 9S12XEP100() , I try to Erase a part(sector) of Flash. 

when I erase address 0x7A0000, it's ok

but erase address 0x7C0000, program will run out(crash)

//************************************************************************************************************

source code as below : 

PFlash_EraseSector(address){

 while((FSTAT & FSTAT_CCIF_MASK) == 0){
_FEED_COP();
}; 
FSTAT = 0x30; //clear ACCERR and PVIOL

FCCOBIX = 0x00;

FCCOB = 0x0A00 | ((address & 0x007F0000)>>16);

FCCOBIX = 0x01;

FCCOB = (address & 0x0000FFF8);

FSTAT = 0x80; //launch command
while((FSTAT & FSTAT_CCIF_MASK) == 0){
_FEED_COP();
}; //wait for done

if((FSTAT & (FSTAT_ACCERR_MASK | FSTAT_FPVIOL_MASK)) != 0)
return FlashEraseError; //error
else
return noErr; 

}

4 Replies

1,218 Views
tafengchung
Contributor II

How do i verify this function is work?

ex. erase 0x7FF000~0x7FFFFF

0 Kudos
Reply

1,218 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I am not sure I understand you.

When you erase the given area sector by sector and then use command PFLASH_Erase_Verify_Section for entire erased part step by step you will get info about flash status erased/programmed. Simply read the command description in the data sheet.

In the example,I sent to you, there are lines


err = PFLASH_Erase_Verify_Section(0x700000, 4);   //check if 4 words are erased - we will receive ERASED message
err = PFLASH_Program(0x700000, &buffer[0]);  //write some data    
err = PFLASH_Erase_Verify_Section(0x700000, 4);   //check if 4 words are erased - we will receive NON_ERASED message

which use what I has written.

Best regards,

Ladislav

0 Kudos
Reply

1,218 Views
kef2
Senior Contributor V

Ladislav,

  • err = PFLASH_Erase_Verify_Section(0x700000, 4);   //check if 4 words are erased - we will receive ERASED message

Comments are wrong. Not 4 words but 4 phrases. One phrase is 8 bytes long.

Tafeng,

if you wonder why don't you see changes in flash in Hiwave debugger, then the answer is because debugger treats it as read only memory and doesn't update from flash. You need to go IIRC P&E Multilink menu, then debugger memory map, find your flash block of interest and change it to make updated when debugger stops.

Edward

0 Kudos
Reply

1,218 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

the issue I see in the following lines:

while((FSTAT & FSTAT_CCIF_MASK) == 0){
_FEED_COP();
}; //wait for done

There is a rule for command processing: The command must not be executed from the Flash block containing space which is Erased/Written.

Because of this, the part of the code waiting for CCIF is executed out of the RAM to avoid accidental E/W of the bock from which the code is executed.

Plese look into an example XEP100-FLASH-PFLASH-CW51.ZIP which can be found in LAMA's S12XE unofficial examples.

There is function stored in RAM (see module main.c)

//==============================================================================
//PFLASH Send_Command
//==============================================================================
//this function is stored in nonbanked RAM memory. Must be called by JSR
//in C language:
//  {
//    FSTAT_CCIF = 1;         //launch command
//    while(FSTAT_CCIF == 0); //wait for done
//  }
static unsigned char Send_Command[]=
{
  0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x3D
};

The function is then called:

asm JSR Send_Command;   

Moreover, I suggest you to disable interrupts during execution of this critical part.

Note: Of course the CodeWarrior IDE provides also possibility to create critical function directly in the RAM space by means of placement "#pragma CODE_SEG DEFAULT_RAM". The you do not have to use assembler instructions. Moreover, the function can be called in standard way  PFLASH_Send_command(void); .

#pragma CODE_SEG DEFAULT_RAM

PFLASH_Send_command(void)

  {

    asm PSHC                  // store CCR

    DisableInterrupts;         // asm SEI

    FSTAT_CCIF = 1;         //launch command
    while(FSTAT_CCIF == 0); //wait for done

   

    asm PULC                   // restore CCR

  }

#pragma CODE_SEG DEFAULT

As you can see I made small modification and moved interrupts handling from flash command preparation function to this function.

I have attache mentioned example also here.

Best regards,

Ladislav