<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with Simple Flash Sector Erase in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200931#M7548</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to clear FCBEF when executing code in RAM, and not exit to code in flash while FCCF==0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Sep 2012 07:21:55 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2012-09-27T07:21:55Z</dc:date>
    <item>
      <title>Help with Simple Flash Sector Erase</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200928#M7545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am writing a simple Flash sector erase for MCF series.&amp;nbsp; The program is below.&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;&amp;nbsp; FCDIV ( clock 24 mHZ, FCDIV = 0x4C or FCDIV =0x4F)&amp;nbsp; is setup before entering the function and I have verfied it several times.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; The flash erase function is located in memory in flash below the range that I am trying to erase.&amp;nbsp; The execution chain is attached.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Can any one point me in the right direction ?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&amp;nbsp; Not sure if this is the reason I am having problems.&amp;nbsp; Why do they execute out of flash ?&amp;nbsp; Is that somehow related to the problem I have.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void EraseFlash(void)&lt;BR /&gt;{&lt;BR /&gt; unsigned long TempLong;&lt;BR /&gt; TempLong = 0x1200;&lt;BR /&gt; FSTAT = 0XB0; //Clear all commands error and command in progress flags&lt;BR /&gt; while (TempLong &amp;lt; 0x20000) // 128 k&lt;BR /&gt; {&lt;BR /&gt;&amp;nbsp; if (FSTAT_FCCF == 1) // Command is complete&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; *(unsigned long *) TempLong = 0x55; // Write any byte&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FCMD = 0x40; // Sector erase of 1k of data; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; FSTAT = 0x80;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while (FSTAT_FCCF == 0) // Wait for command to complete&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nop;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; TempLong = TempLong + 0x400;&lt;BR /&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ((FSTAT_FACCERR == 1) || (FSTAT_FPVIOL == 1))&lt;BR /&gt;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FSTAT = 0xB0;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the input.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt; &amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 15:33:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200928#M7545</guid>
      <dc:creator>SecondTechCo</dc:creator>
      <dc:date>2012-09-26T15:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Simple Flash Sector Erase</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200929#M7546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&amp;nbsp; Not sure if this is the reason I am having problems.&amp;nbsp; &lt;/P&gt;
&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;/P&gt;

&lt;/BLOCKQUOTE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;
&lt;P&gt;FSTAT = 0XB0; //Clear all commands error and command in progress flags&lt;/P&gt;

&lt;/BLOCKQUOTE&gt;&lt;P&gt;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).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 18:17:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200929#M7546</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-09-26T18:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Simple Flash Sector Erase</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200930#M7547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I will try moving the function over to RAM.&amp;nbsp; So I need to stay in the function until the FCCF bit is cleared ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 26 Sep 2012 19:24:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200930#M7547</guid>
      <dc:creator>SecondTechCo</dc:creator>
      <dc:date>2012-09-26T19:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Simple Flash Sector Erase</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200931#M7548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to clear FCBEF when executing code in RAM, and not exit to code in flash while FCCF==0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Sep 2012 07:21:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200931#M7548</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2012-09-27T07:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Simple Flash Sector Erase</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200932#M7549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Theis worked out very Well.&amp;nbsp;&amp;nbsp; Thanks you for the solution.&amp;nbsp;&amp;nbsp; Moving the function To Ram solved my problems&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 20:06:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-Simple-Flash-Sector-Erase/m-p/200932#M7549</guid>
      <dc:creator>SecondTechCo</dc:creator>
      <dc:date>2012-10-12T20:06:06Z</dc:date>
    </item>
  </channel>
</rss>

