AnsweredAssumed Answered

Help with Simple Flash Sector Erase

Question asked by William Nicholson on Sep 26, 2012
Latest reply on Oct 12, 2012 by William Nicholson


I am writing a simple Flash sector erase for MCF series.  The program is below.  It runs fine when I single step through it and I can see on the cyclone pro that the proper locations in memory get erased so i beleive this tells me that I have FCDIV set up right and am exectuing the flash commands properly.    FCDIV ( clock 24 mHZ, FCDIV = 0x4C or FCDIV =0x4F)  is setup before entering the function and I have verfied it several times.  When I try to just run the function instead of single step, it somehow jumps out to a memory location ( 0x400c2700 ) I dont recognize at all.  It has nothing to do with the looping as far as I can see because I have tried to just erase one sector and again same results.  The flash erase function is located in memory in flash below the range that I am trying to erase.  The execution chain is attached.

 

1) Can any one point me in the right direction ?

 

2) I see on several examples including ones done by freescale that they use memcpy or another method to execute the sector flash erase out of RAM memory.   Not sure if this is the reason I am having problems.  Why do they execute out of flash ?  Is that somehow related to the problem I have.

 

void EraseFlash(void)
{
unsigned long TempLong;
TempLong = 0x1200;
FSTAT = 0XB0; //Clear all commands error and command in progress flags
while (TempLong < 0x20000) // 128 k
{
  if (FSTAT_FCCF == 1) // Command is complete
  {
   *(unsigned long *) TempLong = 0x55; // Write any byte
   FCMD = 0x40; // Sector erase of 1k of data;
   FSTAT = 0x80;
   while (FSTAT_FCCF == 0) // Wait for command to complete
   {
    asm
    {
     nop;
    }
   }
   TempLong = TempLong + 0x400;
  }

  if ((FSTAT_FACCERR == 1) || (FSTAT_FPVIOL == 1))
  {
   FSTAT = 0xB0;
  }
}

}

 

Thank you for the input.

 

 

 

 

 


 

 

Outcomes