<?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 bootloader. Execute code in RAM, why? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241759#M6002</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually the flash memory are just allowed to do one thing at a time, either read or write . That is why you need to copy the function to execute the command to RAM, to avoid the "Read-While-Write" violations. Here is an app note that explains why this should be done and addresses the questions you have on ISR handling :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=pdf&amp;amp;WT_ASSET=Documentation" title="http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=pdf&amp;amp;WT_ASSET=Documentation"&gt;http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT…&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Aug 2013 15:32:02 GMT</pubDate>
    <dc:creator>carlos_neri</dc:creator>
    <dc:date>2013-08-09T15:32:02Z</dc:date>
    <item>
      <title>Help with bootloader. Execute code in RAM, why?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241757#M6000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm about to write a bootloader. I have found some example code (AN2295SW).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is a function that is copied to RAM:&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13757891018932612" jivemacro_uid="_13757891018932612"&gt;
&lt;P&gt;void FTFL_Initialization(void)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Word i;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //&amp;nbsp; initialize pointer to ram function&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ExecuteOnStack = (void(*)(void))&amp;amp;buffer[1]; &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //&amp;nbsp; copy function from ROM to RAM&lt;/P&gt;
&lt;P&gt;&amp;nbsp; for(i=0;i&amp;lt;(128+1);i++)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buffer[i] = ((Byte*)ExecuteOnStackStart)[i-1];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //&amp;nbsp; inititalization of flash clock module&lt;/P&gt;
&lt;P&gt;&amp;nbsp; FTFL_INIT_FLASH_CLOCK;&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13757891018837021" jivemacro_uid="_13757891018837021"&gt;
&lt;P&gt;static void ExecuteOnStackStart(void)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //&amp;nbsp; launch a command&lt;/P&gt;
&lt;P&gt;&amp;nbsp; FTFL_FSTAT |= FTFL_FSTAT_CCIF_MASK;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //&amp;nbsp; waiting for the finishing of the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp; while((FTFL_FSTAT&amp;amp;FTFL_FSTAT_CCIF_MASK) != FTFL_FSTAT_CCIF_MASK){};&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why is there a need to copy it to RAM?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it not safe to execute code in flash during a flash command?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens if an interrupt runs from flash during a flash command? Or should I disable all interrupts before any flash command like this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13757891245419027" jivemacro_uid="_13757891245419027" modifiedtitle="true"&gt;
&lt;P&gt;__disable_irq();&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;// launch a command&lt;/P&gt;
&lt;P&gt;FTFL_FSTAT |= FTFL_FSTAT_CCIF_MASK;&lt;/P&gt;
&lt;P&gt;//&amp;nbsp; waiting for the finishing of the command&lt;/P&gt;
&lt;P&gt;while((FTFL_FSTAT&amp;amp;FTFL_FSTAT_CCIF_MASK) != FTFL_FSTAT_CCIF_MASK){};&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;__enable_irq();&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Aug 2013 06:48:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241757#M6000</guid>
      <dc:creator>markosiponen</dc:creator>
      <dc:date>2013-08-06T06:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Help with bootloader. Execute code in RAM, why?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241758#M6001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The things you say are true -- you cannot let anything attempt a 'read' of a flash bank while it is writing.&amp;nbsp; For two-bank parts you can just insure nothing 'runs' from the 'inactive' bank, but it is always just 'safer' to let all flash operations run from RAM.&amp;nbsp; I let my whole bootloader be copied out to RAM, vector table and all, by the IAR linker setup.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Aug 2013 16:31:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241758#M6001</guid>
      <dc:creator>egoodii</dc:creator>
      <dc:date>2013-08-08T16:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with bootloader. Execute code in RAM, why?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241759#M6002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Usually the flash memory are just allowed to do one thing at a time, either read or write . That is why you need to copy the function to execute the command to RAM, to avoid the "Read-While-Write" violations. Here is an app note that explains why this should be done and addresses the questions you have on ISR handling :smileyhappy:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=pdf&amp;amp;WT_ASSET=Documentation" title="http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT_FILE_FORMAT=pdf&amp;amp;WT_ASSET=Documentation"&gt;http://cache.freescale.com/files/32bit/doc/app_note/AN4695.pdf?fpsp=1&amp;amp;WT_TYPE=Application%20Notes&amp;amp;WT_VENDOR=FREESCALE&amp;amp;WT…&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2013 15:32:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Help-with-bootloader-Execute-code-in-RAM-why/m-p/241759#M6002</guid>
      <dc:creator>carlos_neri</dc:creator>
      <dc:date>2013-08-09T15:32:02Z</dc:date>
    </item>
  </channel>
</rss>

