<?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: mc9s12xdt512 mcu &amp; flash initialiation in S12 / MagniV Microcontrollers</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704784#M14607</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It seems that "Flash_Init" operants needs the oscillator frequency in kHz and tbus in nanosecond.&lt;/P&gt;&lt;P&gt;So, for 16MHz oscillator and&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;PLL frequency of 29.49MHz we have the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;29.49MHz / 2 = 14.745MHz bus frequence&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1/14.745MHz =67.8ns (it will be rounded to 68)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;So, the call to Flash_Init should be as follow&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Flash_Init(16000, 68)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Oct 2017 09:14:06 GMT</pubDate>
    <dc:creator>Eric_t</dc:creator>
    <dc:date>2017-10-13T09:14:06Z</dc:date>
    <item>
      <title>mc9s12xdt512 mcu &amp; flash initialiation</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704783#M14606</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Hi!&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;I have download from NXP, a demo example project for programming the internal flash memory of&amp;nbsp;XD256 controllers.&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;The project that I download is "SW-XD256-FLASH-E_W-v1_0-CW45"&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;I have attached the project.&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Since the project refers to XD256 controllers, assume that the project is also valid for mc9s12xdt512 controller.&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;I have made a try and the project works just fine with &lt;SPAN&gt;mc9s12xdt512 controller.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;The problem that I am facing, is that it is not clear what is the correct frequency that I should enter in&amp;nbsp;"Flash_Init" routine.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; color: #51626f; background-color: #ffffff; border: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;SPAN&gt;"Flash_Init" routine.&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//==============================================================================&lt;BR /&gt;// Function Name: Flash_Init&lt;BR /&gt;// Description : Initialize Flash NVM for HCS12 by programming FCLKDIV based on &lt;BR /&gt;// passed oscillator frequency, then uprotect the array, and finally ensure PVIOL&lt;BR /&gt;// and ACCERR are cleared by writing to them.&lt;BR /&gt;//==============================================================================&lt;BR /&gt;UBYTE Flash_Init(unsigned long oscclk, unsigned long tbus) // [kHz,ns]&lt;BR /&gt;{&lt;BR /&gt; unsigned long fclk_val;&lt;BR /&gt; unsigned long temp;&lt;/P&gt;&lt;P&gt;if(tbus &amp;gt; 1000L) return PROGRAM_ERASE_IMPOSSIBLE; // tbus &amp;gt; 1us (1000ns) (page 35 S12FTS256KV2.pdf )&lt;BR /&gt; temp = (oscclk*1000) % 8;&lt;BR /&gt; fclk_val = (oscclk * (5000UL+tbus)) / 1000000UL;&lt;/P&gt;&lt;P&gt;if (oscclk &amp;gt;= 12800UL)&lt;BR /&gt; { fclk_val = fclk_val / 8;&lt;BR /&gt; if(temp) { fclk_val = fclk_val - 1; } // oscclk % 8 is not an integer&lt;BR /&gt; FCLKDIV = (unsigned char) (fclk_val | 0x40);&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; { if(temp) { fclk_val = (fclk_val-1); } // oscclk % 8 is not an integer&lt;BR /&gt; FCLKDIV = (unsigned char) fclk_val;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;// test computed parameters&lt;BR /&gt; if (oscclk &amp;gt;= 12800L) {temp = 8UL*1000000UL*(1+FCLKDIV&amp;amp;0x3F) / oscclk + tbus;}&lt;BR /&gt; else {temp = 1000000UL*(1+FCLKDIV&amp;amp;0x3F) / oscclk + tbus; } &lt;BR /&gt; temp = temp / 1000;&lt;BR /&gt; if(temp &amp;lt; 5UL) return PROGRAM_ERASE_IMPOSSIBLE; &lt;BR /&gt; FSTAT= 0x30;&lt;BR /&gt;}&lt;BR /&gt;//==============================================================================&lt;BR /&gt;//==============================================================================&lt;BR /&gt;//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;the main calls it as follow&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;//----------------------------------------&lt;BR /&gt; //initialization of FLASH module&lt;BR /&gt; //----------------------------------------&lt;BR /&gt; err = Flash_Init(16000,125); // Oscillator clock = 16 000 kHz&lt;BR /&gt; // Bus clock = 8MHz =&amp;gt; tbus=125ns&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;My project uses 16MHz oscillator clock,&amp;nbsp;PLL 29.49MHz (bus clock 14.74MHz)&lt;/P&gt;&lt;P&gt;I assume that the operant of "Flash_Init" should be the PLL clock and not the oscillator clock.&lt;/P&gt;&lt;P&gt;I assume that I have to call the&amp;nbsp;&lt;SPAN&gt;"Flash_Init" as follow:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Flash_Init(&lt;SPAN&gt;29490&lt;/SPAN&gt;, &lt;SPAN&gt;68&lt;/SPAN&gt;);&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Could anyone confirm that the above flash initialization is correct?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Attachment has been moved to: &lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-338633"&gt;SW-XD256-FLASH-E_W-v1_0-CW45.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Oct 2017 09:06:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704783#M14606</guid>
      <dc:creator>Eric_t</dc:creator>
      <dc:date>2017-10-12T09:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: mc9s12xdt512 mcu &amp; flash initialiation</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704784#M14607</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;It seems that "Flash_Init" operants needs the oscillator frequency in kHz and tbus in nanosecond.&lt;/P&gt;&lt;P&gt;So, for 16MHz oscillator and&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;PLL frequency of 29.49MHz we have the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;29.49MHz / 2 = 14.745MHz bus frequence&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;1/14.745MHz =67.8ns (it will be rounded to 68)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;So, the call to Flash_Init should be as follow&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Flash_Init(16000, 68)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Oct 2017 09:14:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704784#M14607</guid>
      <dc:creator>Eric_t</dc:creator>
      <dc:date>2017-10-13T09:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: mc9s12xdt512 mcu &amp; flash initialiation</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704785#M14608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;this is my code. I have not wanted to calculate it again and again so I added the calculation to SW.&lt;/P&gt;&lt;P&gt;The routine follows calculation steps. Of course you can exclude it and substitute by direct writing of FCLKDIV register.&lt;/P&gt;&lt;P&gt;The function describes what to put as a parameters:&lt;/P&gt;&lt;P&gt;UBYTE Flash_Init(unsigned long oscclk, unsigned long tbus) // [kHz,ns]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use "My project uses 16MHz oscillator clock,&amp;nbsp;PLL 29.49MHz (bus clock 14.74MHz)"&lt;/P&gt;&lt;P&gt;then&lt;/P&gt;&lt;P&gt;Flash_Init(16000, 68) // [kHz,ns]&lt;/P&gt;&lt;P&gt;So I confirm previous answer.&lt;/P&gt;&lt;P&gt;The result of calculation should be 74 [0x4A]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it is eenough to write FCLKDIV=0x4A&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Moreover I have attached example codes plus calculator which can help you in the future.&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Ladislav&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Oct 2017 12:07:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/mc9s12xdt512-mcu-amp-flash-initialiation/m-p/704785#M14608</guid>
      <dc:creator>lama</dc:creator>
      <dc:date>2017-10-13T12:07:14Z</dc:date>
    </item>
  </channel>
</rss>

