<?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>LPCXpresso IDEのトピックRe: while(1) not eternal</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586498#M27232</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Brinkand on Fri Feb 26 00:57:17 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You very much for the excellent answer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Volatile solved the issue. Everything now works as I intend.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was actually using the default blinky optimization of -O1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jun 2016 00:09:08 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-16T00:09:08Z</dc:date>
    <item>
      <title>while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586494#M27228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Brinkand on Thu Feb 25 07:24:41 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;This keeps bugging me: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
ADC_local_counter = 0;
&amp;nbsp;&amp;nbsp; 

&amp;nbsp; while(1)
&amp;nbsp; {ADC_local_counter++; };
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[COLOR=black][FONT=&amp;amp;quot]ADC_local_counter ends at 1! I would suspect it to keep incrementing during execution, but it only runs once. Any hints?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/FONT][/COLOR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below example works as expected:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[COLOR=black][FONT=&amp;amp;quot]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/FONT][/COLOR]&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;ADC_local_counter = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; while(ADC_local_counter &amp;lt;100)
&amp;nbsp; {ADC_local_counter++; };
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; ADC_local_counter++;
&amp;nbsp; &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;SPAN&gt;ADC_local_counter ends at 101 as expected.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586494#M27228</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:05Z</dc:date>
    </item>
    <item>
      <title>Re: while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586495#M27229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Thu Feb 25 09:35:03 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;What optimisation level are you using? A release build / -O2 ??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What is happening is that the compiler is, quite rightly, optimising the update to your local away, as it has detected that nothing is actually making use of it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try marking your local as "volatile".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note that when you see apparently strange behaviour like this, it can be quite useful to look at the actually code generated. In this case, you will almost certainly see a "branch to self instruction".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For details of how to disassemble whilst debugging, please see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://"&gt;http://lpcxpresso.code-red-tech.com/LPCXpresso/node/28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And for details of how to disassemble whilst building, please see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://"&gt;http://lpcxpresso.code-red-tech.com/LPCXpresso/node/29&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586495#M27229</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586496#M27230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by rkiryanov on Thu Feb 25 11:25:36 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: CodeRedSupport&lt;/STRONG&gt;&lt;BR /&gt;What is happening is that the compiler is, quite rightly, optimising the update to your local away, as it has detected that nothing is actually making use of it!&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you mean that gcc optimized infinite useless loop to "nothing"? It should opmimize to __asm("b ."), but not to "nothing".&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586496#M27230</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586497#M27231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by CodeRedSupport on Thu Feb 25 15:36:05 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;No - I meant that the compiler will optimise out the incrementing of your local variable - as it can see that the code does not make any other use of the variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The while loop itself will remain - encoded as a branch to self - ie a branch to the location of the branch instruction itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to keep the code that increments the variable, then make the variable "volatile". This instructs the compiler that "external factors" may access the variable and will hence prevent the compiler removing the code that increments it within your while(1) loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you look at the main.c that is created by the LPCXpresso Project Wizard, this is exactly what the code this contains does.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CodeRedSupport&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586497#M27231</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586498#M27232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Brinkand on Fri Feb 26 00:57:17 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You very much for the excellent answer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Volatile solved the issue. Everything now works as I intend.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was actually using the default blinky optimization of -O1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586498#M27232</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: while(1) not eternal</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586499#M27233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by bladerunner on Sun Feb 28 05:21:05 MST 2010&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: CodeRedSupport&lt;/STRONG&gt;&lt;BR /&gt;No - I meant that the compiler will optimise out the incrementing of your local variable - as it can see that the code does not make any other use of the variable.&lt;BR /&gt;&lt;BR /&gt;The while loop itself will remain - encoded as a branch to self - ie a branch to the location of the branch instruction itself.&lt;BR /&gt;&lt;BR /&gt;If you want to keep the code that increments the variable, then make the variable "volatile". This instructs the compiler that "external factors" may access the variable and will hence prevent the compiler removing the code that increments it within your while(1) loop.&lt;BR /&gt;&lt;BR /&gt;If you look at the main.c that is created by the LPCXpresso Project Wizard, this is exactly what the code this contains does.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;CodeRedSupport&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, turn off the optimization or use the volatile qualifier. Compiler optimization and embedded controllers are uneasy bedfellows :)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2016 00:09:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/while-1-not-eternal/m-p/586499#M27233</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-16T00:09:08Z</dc:date>
    </item>
  </channel>
</rss>

