Help with Simple Flash Sector Erase

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Help with Simple Flash Sector Erase

跳至解决方案
2,062 次查看
SecondTechCo
Contributor IV


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.

 

 

 

 

 


 

 

标签 (1)
标记 (3)
1 解答
1,315 次查看
kef
Specialist I

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. 

Yes, you need to run your flash routine out of RAM. While FCCF bit is 0, flash array is not readable, but CPU has to read some code to execute. So you launch flash command and CPU runs away.

FSTAT = 0XB0; //Clear all commands error and command in progress flags

You should not clear FCBEF bit at this point. It is attempt to launch flash command! You should clear just ACCERR and PVIOL . (You have two such lines in your code).

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,316 次查看
kef
Specialist I

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. 

Yes, you need to run your flash routine out of RAM. While FCCF bit is 0, flash array is not readable, but CPU has to read some code to execute. So you launch flash command and CPU runs away.

FSTAT = 0XB0; //Clear all commands error and command in progress flags

You should not clear FCBEF bit at this point. It is attempt to launch flash command! You should clear just ACCERR and PVIOL . (You have two such lines in your code).

0 项奖励
回复
1,315 次查看
SecondTechCo
Contributor IV

I will try moving the function over to RAM.  So I need to stay in the function until the FCCF bit is cleared ?

Thank you.

0 项奖励
回复
1,315 次查看
kef
Specialist I

You need to clear FCBEF when executing code in RAM, and not exit to code in flash while FCCF==0.

BTW you also need to care about interrupts. Since flash is not readable while FCCF==0, you can't keep interrupts enabled while erasing/programming flash, unless you move interrupt vectors table and ISR's to RAM.

1,315 次查看
SecondTechCo
Contributor IV

Theis worked out very Well.   Thanks you for the solution.   Moving the function To Ram solved my problems

0 项奖励
回复