<?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 Why same code runs at different speed by mbed and KDS? in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329335#M15299</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a ballistics algorithm running in our current product.&amp;nbsp; We plan to put that piece code into K63 later.&amp;nbsp; Then I did a quick preliminary evaluation half year ago by &lt;STRONG&gt;"mbed"&lt;/STRONG&gt; using FRDM-k64F board right after FTF. The speed is great, every computation cycle only takes about &lt;STRONG&gt;2 ms&lt;/STRONG&gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I transplanted that piece of code into a bare metal program by&lt;STRONG&gt; KDS&lt;/STRONG&gt;. Exact same code, every cycle takes about &lt;STRONG&gt;20 ms&lt;/STRONG&gt;. It is about 10 times slower. I also tried the "arm_math.h". There is no difference at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I run my mbed code again. It is still&lt;STRONG&gt; 2 ms&lt;/STRONG&gt;. I changed the float variables to volatile just in case the optimization. I also change the variables during the loop to avoid any optimization.&amp;nbsp; It still holds 2 ms.&amp;nbsp; The time was measured by an oscilloscope by toggle a IO right before and right after the calculation. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I compared the calculation results from both mbed and KDS, the output are exactly same. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the processor setup is :&amp;nbsp; -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone could know what I missed or KDS missed compared to mbed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haizhou&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Dec 2014 19:29:19 GMT</pubDate>
    <dc:creator>haizhouli</dc:creator>
    <dc:date>2014-12-05T19:29:19Z</dc:date>
    <item>
      <title>Why same code runs at different speed by mbed and KDS?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329335#M15299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a ballistics algorithm running in our current product.&amp;nbsp; We plan to put that piece code into K63 later.&amp;nbsp; Then I did a quick preliminary evaluation half year ago by &lt;STRONG&gt;"mbed"&lt;/STRONG&gt; using FRDM-k64F board right after FTF. The speed is great, every computation cycle only takes about &lt;STRONG&gt;2 ms&lt;/STRONG&gt;. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I transplanted that piece of code into a bare metal program by&lt;STRONG&gt; KDS&lt;/STRONG&gt;. Exact same code, every cycle takes about &lt;STRONG&gt;20 ms&lt;/STRONG&gt;. It is about 10 times slower. I also tried the "arm_math.h". There is no difference at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I run my mbed code again. It is still&lt;STRONG&gt; 2 ms&lt;/STRONG&gt;. I changed the float variables to volatile just in case the optimization. I also change the variables during the loop to avoid any optimization.&amp;nbsp; It still holds 2 ms.&amp;nbsp; The time was measured by an oscilloscope by toggle a IO right before and right after the calculation. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I compared the calculation results from both mbed and KDS, the output are exactly same. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the processor setup is :&amp;nbsp; -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone could know what I missed or KDS missed compared to mbed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haizhou&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 19:29:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329335#M15299</guid>
      <dc:creator>haizhouli</dc:creator>
      <dc:date>2014-12-05T19:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why same code runs at different speed by mbed and KDS?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329336#M15300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know anything about the mbed code so this is just a guess.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you running both sets of code at the same clock frequency? Does the mbed environment use the PLL to speed up the CPU. Are you doing the same clock PLL initialization in your KDS code? To run at the full speed the CPU is capable of you need to configure the PLLs on power up. Depending on your crystal and PLL settings the base clock frequency could be 1/10 of what you're expecting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 21:38:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329336#M15300</guid>
      <dc:creator>ndavies</dc:creator>
      <dc:date>2014-12-05T21:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why same code runs at different speed by mbed and KDS?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329337#M15301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Norm,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the reply! Sorry I did not mention the frequency setting in the first post. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have no idea which frequency mbed running at. I bet it is 120MHz because it is really quick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I do know which frequency I set in KDS.&amp;nbsp; I set the&amp;nbsp;&amp;nbsp; SIM-&amp;gt;CLKDIV1 = (uint32_t)0x01440000u and MCG-&amp;gt;C6 = (uint8_t)0x46u.&amp;nbsp; I set the Flexbus CLKOUT pin and used oscilloscope to read it, it was 24MHz. It proves that the core was running at 120 MHz.&amp;nbsp; I even overclocked the C6 to 0x5A to 200MHz to improve the performance. It improved, but it is still slow. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Haizhou&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 22:26:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329337#M15301</guid>
      <dc:creator>haizhouli</dc:creator>
      <dc:date>2014-12-05T22:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why same code runs at different speed by mbed and KDS?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329338#M15302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have you turned on compiler optimizations? Try -O3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Dec 2014 06:43:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329338#M15302</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2014-12-06T06:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why same code runs at different speed by mbed and KDS?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329339#M15303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I did turn on the -O3. with and without this setup, I can achieve about 10% speed increase. Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haizhou&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Dec 2014 20:58:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Why-same-code-runs-at-different-speed-by-mbed-and-KDS/m-p/329339#M15303</guid>
      <dc:creator>haizhouli</dc:creator>
      <dc:date>2014-12-07T20:58:07Z</dc:date>
    </item>
  </channel>
</rss>

