<?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>S12 / MagniV MicrocontrollersのトピックRe: unable to write data to program flash memory</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156956#M4742</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not familiar with 56F, but I guess it is the same like in other MCU's. On S08, S12, CF flash is not readable while it is being programmed. This means you can't run code from flash while you are erasing/programming flash. Part of erase/program code should be copied to RAM and executed from there. This may explain why you are able to program data flash and not able to program program flash.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Aug 2011 15:12:46 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2011-08-10T15:12:46Z</dc:date>
    <item>
      <title>unable to write data to program flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156955#M4741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using 56F8345 and want to test how security method works. Before writing back door key&amp;nbsp; to FM configuration field, I just want to create a function to write data to flash memory.&lt;/P&gt;&lt;P&gt;I&amp;nbsp; wrote a function according to 56f8300 peripheral user manual&amp;nbsp;. It is&amp;nbsp;&amp;nbsp;able to write data to Data_flash memory since I could see value changes in debug mode. However, it seems not work for program flash memory.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code for writing data to program flash (&amp;nbsp;&amp;nbsp;to write data to data flash , only need change address and bits in register FMCR):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define data_space&amp;nbsp; 1&lt;BR /&gt;#define prog_space&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define data_flash_address&amp;nbsp;&amp;nbsp;&amp;nbsp; (*((volatile word *)0x00001000))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // pick up one data flash memory unit for&amp;nbsp;writing test&lt;/P&gt;&lt;P&gt;#define prog_flash_address&amp;nbsp;&amp;nbsp;&amp;nbsp; (*((volatile word *)0x0000FE00))&amp;nbsp;&amp;nbsp;&amp;nbsp; // pick up one prog flash memory unit for&amp;nbsp;writing test&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//create a function to do write on program flash memory&lt;/P&gt;&lt;P&gt;void write_on_progflash( void);&lt;/P&gt;&lt;P&gt;void write_on_progflash( void)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //first check the FMCLKD, if it's not written, no further operation&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if(FMCLKD &amp;amp;0x0080)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm(nop); //FMCLKD is written&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMCLKD =0x0032;&amp;nbsp; //DIV=50 PDIV=0&amp;nbsp; then FMCLKD =20Mhz/2/51=196KHZ&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; // select data flash&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMCR =(FMCR &amp;amp; 0x0fffc)| prog_space ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMCR &amp;amp;=0x0FFDF ;//Clear KEYACC bit to disable Security Key Writing&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //test LOCK bit on FMCR&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if(FMCR&amp;amp;0x400)&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ; // LOCK is set, so no way to change FMPORT&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMPROT =0 ; //make the flash space be able to be written&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //check the status of FMUSTAT, CBEIF is set?&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while ((FMUSTAT &amp;amp;0x0080)==0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&amp;nbsp;&amp;nbsp; //CBEIF is 0, buffer is full&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //now flash is ready for operation&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //Before writing data to flash, erase first&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; prog_flash_address =0;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMCMD = 0x040; //page erase command&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; FMUSTAT |=0x080; //set up CBEIF&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //check any error happens?&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if(FMUSTAT &amp;amp; 0x0030)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&amp;nbsp;&amp;nbsp; // error happens&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; // no error? check erase finished or not&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while((FMUSTAT &amp;amp; 0x0c0)!=0xc0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//ok, now able to write&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prog_flash_address =99;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;FMCMD =0x020;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; FMUSTAT |=0x080; //set up CBEIF&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; //check any error happens?&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if(FMUSTAT &amp;amp; 0x0030)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return;&amp;nbsp;&amp;nbsp; // error happens&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; // no error? check erase finished or not&lt;BR /&gt;&amp;nbsp;&amp;nbsp; while((FMUSTAT &amp;amp; 0x0c0)!=0xc0)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; asm(nop);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas, thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Aug 2011 20:43:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156955#M4741</guid>
      <dc:creator>Gaoya</dc:creator>
      <dc:date>2011-08-08T20:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: unable to write data to program flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156956#M4742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not familiar with 56F, but I guess it is the same like in other MCU's. On S08, S12, CF flash is not readable while it is being programmed. This means you can't run code from flash while you are erasing/programming flash. Part of erase/program code should be copied to RAM and executed from there. This may explain why you are able to program data flash and not able to program program flash.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Aug 2011 15:12:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156956#M4742</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2011-08-10T15:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: unable to write data to program flash memory</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156957#M4743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kef,&lt;/P&gt;&lt;P&gt;Thank you for reply.&lt;/P&gt;&lt;P&gt;I also thought the program should run at RAM when program/erase need to be done at program flash memory. But so far I could not find any application notes related to&amp;nbsp;running part of program in RAM and documentation of ELF linker in targeting MC56f83XX is not so clear. &amp;nbsp;Do you know&amp;nbsp; are there some example and reference?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Aug 2011 21:24:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/unable-to-write-data-to-program-flash-memory/m-p/156957#M4743</guid>
      <dc:creator>Gaoya</dc:creator>
      <dc:date>2011-08-11T21:24:53Z</dc:date>
    </item>
  </channel>
</rss>

