<?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>Kinetis Design StudioのトピックRe: Problem with code geting optimized out</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454180#M4640</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Zhang,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Adding the asm("nop") between each line of code took care of the problem. Since this code is executed only during initialization, the added instructions don't bother me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was the easiest solution for my case, but I have to wonder if others aren't seeing the same kind of thing since the code is right out of the KSDK pin_mux.c module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Jul 2015 19:50:12 GMT</pubDate>
    <dc:creator>davepfaltzgraff</dc:creator>
    <dc:date>2015-07-06T19:50:12Z</dc:date>
    <item>
      <title>Problem with code geting optimized out</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454177#M4637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to debug an SPI implementation and found that in the pin_mux_SPI() routine where the code is:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* PORTD_PCR4 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,4u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* PORTD_PCR5 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,5u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* PORTD_PCR6 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,6u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* PORTD_PCR7 */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,7u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Only the first PORT_HAL_SetMuXMode insatance is executed. It appears that the remaining lines get optimized out. I tested this by setting the optimization level to None and all the lines get executed.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a setting that would allow me to say "Don't optimize this section"?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More importantly, can the compiler be fixed?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My environment is for the FRDM-K22F board and KDS version 3.0.0 with KSDK version 1.2.0 running on Windows 7.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 19:08:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454177#M4637</guid>
      <dc:creator>davepfaltzgraff</dc:creator>
      <dc:date>2015-07-05T19:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with code geting optimized out</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454178#M4638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please try if one of below solution can help:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Solution 1:&lt;/P&gt;&lt;P&gt;Use "KEEP" command to force the linker to&amp;nbsp; &lt;EM&gt;not&lt;/EM&gt;&amp;nbsp; dead strip the unused symbols in the specified section in ld or lcf file.&lt;/P&gt;&lt;P class="section"&gt;&lt;STRONG&gt;Syntax&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="codeblock"&gt;&lt;SPAN class="resultofText"&gt;&lt;SPAN class="resultofText"&gt;KEEP&lt;/SPAN&gt;(*(sectionType))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P class="section"&gt;&lt;A name="ADS130linker331__wp970158" shape="rect" target="_blank"&gt;&lt;/A&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;&lt;/P&gt;&lt;P class="fignone"&gt;&lt;SPAN class="figcap"&gt;&amp;nbsp; &lt;SPAN class="resultofText"&gt;&lt;SPAN class="resultofText"&gt;KEEP&lt;/SPAN&gt; Directive Usage&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="codeblock"&gt;GROUP : { .text (TEXT) : {}&amp;nbsp; .mycode (TEXT) : {&lt;SPAN class="resultofText"&gt;&lt;SPAN class="resultofText"&gt;KEEP&lt;/SPAN&gt;(*(.mycode))}&amp;nbsp; ...}


&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Solution2:&lt;/P&gt;&lt;P&gt;if you use GCC compiler, insert&lt;/P&gt;&lt;P&gt;asm ("nop");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to the repetition functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,4u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;asm ("nop");&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_SetMuxMode(PORTD,5u,kPortMuxAlt7);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt; asm ("nop");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;see how does it work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Zhang Jun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 02:33:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454178#M4638</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2015-07-06T02:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with code geting optimized out</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454179#M4639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;gt; Is there a setting that would allow me to say "Don't optimize this section"?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the optimize attribute to compile a particular function at a different optimization level: &lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;A href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes" title="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes"&gt;Common Function Attributes - Using the GNU Compiler Collection (GCC)&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;gt; More importantly, can the compiler be fixed?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;The toolchain in KDS 3.0.0 is provided by the GCC ARM Embedded project. They encourage you to first ask a question on their launchpad page then file a bug: &lt;A href="https://launchpad.net/gcc-arm-embedded" title="https://launchpad.net/gcc-arm-embedded"&gt;GCC ARM Embedded in Launchpad&lt;/A&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Without a test case it's difficult to say, but sometimes functions/macros like those you quote are inlined and have very simple bodies &lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;(x |= 0xf00 for example) &lt;/SPAN&gt;, as such the compiler is able to combine all four apparent function calls into a single sequence of instructions. The result is that if you try and step over them in a debugger it appears only the first is executed, when in fact all four are executed at the same time. If that's what you're observing, it would be worth checking the state of the target after this block of code, to see if it has executed correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Hope that helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Joe&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 09:25:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454179#M4639</guid>
      <dc:creator>joeseymour</dc:creator>
      <dc:date>2015-07-06T09:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with code geting optimized out</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454180#M4640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Zhang,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Adding the asm("nop") between each line of code took care of the problem. Since this code is executed only during initialization, the added instructions don't bother me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This was the easiest solution for my case, but I have to wonder if others aren't seeing the same kind of thing since the code is right out of the KSDK pin_mux.c module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 19:50:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Problem-with-code-geting-optimized-out/m-p/454180#M4640</guid>
      <dc:creator>davepfaltzgraff</dc:creator>
      <dc:date>2015-07-06T19:50:12Z</dc:date>
    </item>
  </channel>
</rss>

