<?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>LPC MicrocontrollersのトピックRe: optimization problem</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557221#M15345</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by markr on Wed Oct 30 19:40:50 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;I would&amp;nbsp; ;-) &lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.support.code-red-tech.com%2FCodeRedWiki%2FCompilerOptimization%3Fhighlight%3D%2528volatile%2529" rel="nofollow" target="_blank"&gt;http://www.support.code-red-tech.com/CodeRedWiki/CompilerOptimization?highlight=%28volatile%29&lt;/A&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking at the link, all I can say is wow. I've used CCS for TI, GCC for Atmel and MicroChip and IAR for all 3 and never seen anything like this. Sure, the usual problems were a while loop that increments a dummy variable vanishes, or occasionally a repeated increment to a memory mapped I/O may disappear when optimization is turned up. But nothing like this. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, marking color volatile didn't fix the problem. Same behavior. And there were already variables inside the switch that were marked volatile. The only thing that fixes this is turning off _all_ optimization. Even -O1 fails. I'll retry this tomorrow on another vendor's compiler with the same code and see what happens.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've included the entire switch code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - The variables "red_pwm", "blue_pwm" &amp;amp; "green_pwm" were already volatile. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - Adding a pin I/O inside the switch and/or cases didn't help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - Making color volatile didn't help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It only works correctly is optimization is turned off completely. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This leads to another question: How to mark I/O as volatile when all the register structures are already defined in library includes? Especially on a processor like ARM where _all_ I/O is memory mapped?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, I'm using a macro to access the I/O ports:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(I give up, the forum editor eats the example. Its a define using the standard LPC I-O structure)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the problem is memory mapped I/O, shouldn't _all_ I/O be marked as volatile in the libraries? (hint: it's not)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other ideas? This isn't the end of the world, I'm just trying to educate myself on ARM in general and NXP in particular. The LPC8xx looked like a good option for high performance in a small package and low price. It would be nice to use the "house brand" compiler, but problems like this are annoying. I'm glad this isn't a memory limited project on a deadline....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-markr&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 19:58:38 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T19:58:38Z</dc:date>
    <item>
      <title>optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557217#M15341</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by markr on Wed Oct 30 13:13:20 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I've run into a problem that I believe is a compiler optimization problem. I'm using an LPC-812 on a breakout board that does not support either JTAG or SWD, so debugging this has been interesting. I'm using LPCXpresso v6.0.2 Build 151 2013-09-18. The code in question is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;...set-up a bunch of things, including clocks, ISR handles, pins etc, then...
while (1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Loop forever */
&amp;nbsp; {
&amp;nbsp; while(!LPC_GPIO_PORT-&amp;gt;W0[ISP_PIN]) ; // wait on ISP button press
&amp;nbsp; while (TimeTick &amp;lt;= change_pwm); //wait for the counter to advance
&amp;nbsp; TimeTick=0;
#ifdef DBG_OUTPUT
&amp;nbsp; printf("R=%3d, G=%3d, B=%3d\n\r",red_pwm,green_pwm,blue_pwm);
#endif
&amp;nbsp; NOTPORT0(PORT0_BIT6); // toggle pin
//&amp;nbsp; printf("%2d",color);
&amp;nbsp; switch (color) {
... several cases: with breaks, a default, then end of the while(1).&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All code from the switch() on-wards does not appear to be getting executed. The switch has several cases, each case has several tests and modifies global variables that are used in ISRs. The end of the switch is the end of the while(1). &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If either printf() shown above is enabled (either enable the #ifdef or remove the comment), the switch operates correctly. If neither one is present, the code in the switch is never executed. If a printf() is placed in _any_ of the case statements, the switch executes and all cases operate correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the processor is not off in the weeds because:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- There are pin toggles in 2 timer ISRs that keep toggling. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- The NOTPORT0 toggles a pin and that pin toggles correctly, so the primary while loop appears to be functioning correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- The pin toggled by the NOTPORT0 stops toggling when the ISP button is pressed (as would be expected) and the ISRs keep running (as also expected and evidenced by pin toggles). And the pin controlled by the NOTPORT0 resumes toggling when the button is released (again as expected.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Everything else appears to be operating correctly, just the entire switch structure is never executed! I chased this for most of a day (debugging w/o a debugger is fun!) until I started changing the optimization.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The project was initially set with size optimization (-Os) I changed to none (-O0), cleaned and rebuilt and it worked. Change it back to size (-Os), clean and rebuild and it doesn't work. There is definitely something bad going on with optimization. (I haven't tried the other levels yet.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Besides the problem noted above, it appears that just changing the optimization level does not cause a re-build of the project. The code remains working or not working, irrespective of the optimization setting. Only if I change the optimization _and_ touch the code (add/delete a space and save) and recompile, does the behavior change. A clean and rebuilt does generate new code and will cause it to work or not work, depending on the state of the code and optimization.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The need to clean and rebuilt when changing optimization is not that surprising and is a minor nuisance. But having optimization remove most of main() is another issue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new to LPCXpresso and ARM in general, but have been using other micro-controlllers and IDEs for years. I'll admit I don't know LPCXpresso well enough to generate assembly and look at the resulting intermediate code. (It took some wrangling to get it to output a hex file for Flash Magic.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts or suggestions would be appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-markr&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557217#M15341</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557218#M15342</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Wed Oct 30 14:12:35 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Is 'color' volatile?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557218#M15342</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:36Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557219#M15343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by markr on Wed Oct 30 14:57:01 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;Is 'color' volatile?&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;no. it's an unsigned int only used in main. It's basically the "state" of the system: its incremented in every case statement, so the next pass around the while loop goes to the next state/switch-case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You're onto an interesting idea. I'll try changing it. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wouldn't expect an optimizer would discard an entire switch structure just because the switch state is only modified inside the switch. Makes state machines hard to implement in SW. :-)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-markr&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557219#M15343</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557220#M15344</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Wed Oct 30 15:11:03 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: markr&lt;/STRONG&gt;&lt;BR /&gt;I wouldn't expect an optimizer would discard an entire switch structure...&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would&amp;nbsp; ;-) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.support.code-red-tech.com%2FCodeRedWiki%2FCompilerOptimization%3Fhighlight%3D%2528volatile%2529" rel="nofollow" target="_blank"&gt;http://www.support.code-red-tech.com/CodeRedWiki/CompilerOptimization?highlight=%28volatile%29&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557220#M15344</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557221#M15345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by markr on Wed Oct 30 19:40:50 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: R2D2&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;I would&amp;nbsp; ;-) &lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.support.code-red-tech.com%2FCodeRedWiki%2FCompilerOptimization%3Fhighlight%3D%2528volatile%2529" rel="nofollow" target="_blank"&gt;http://www.support.code-red-tech.com/CodeRedWiki/CompilerOptimization?highlight=%28volatile%29&lt;/A&gt;&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Looking at the link, all I can say is wow. I've used CCS for TI, GCC for Atmel and MicroChip and IAR for all 3 and never seen anything like this. Sure, the usual problems were a while loop that increments a dummy variable vanishes, or occasionally a repeated increment to a memory mapped I/O may disappear when optimization is turned up. But nothing like this. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Unfortunately, marking color volatile didn't fix the problem. Same behavior. And there were already variables inside the switch that were marked volatile. The only thing that fixes this is turning off _all_ optimization. Even -O1 fails. I'll retry this tomorrow on another vendor's compiler with the same code and see what happens.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've included the entire switch code below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - The variables "red_pwm", "blue_pwm" &amp;amp; "green_pwm" were already volatile. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - Adding a pin I/O inside the switch and/or cases didn't help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; - Making color volatile didn't help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It only works correctly is optimization is turned off completely. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This leads to another question: How to mark I/O as volatile when all the register structures are already defined in library includes? Especially on a processor like ARM where _all_ I/O is memory mapped?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, I'm using a macro to access the I/O ports:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(I give up, the forum editor eats the example. Its a define using the standard LPC I-O structure)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If the problem is memory mapped I/O, shouldn't _all_ I/O be marked as volatile in the libraries? (hint: it's not)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any other ideas? This isn't the end of the world, I'm just trying to educate myself on ARM in general and NXP in particular. The LPC8xx looked like a good option for high performance in a small package and low price. It would be nice to use the "house brand" compiler, but problems like this are annoying. I'm glad this isn't a memory limited project on a deadline....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-markr&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557221#M15345</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557222#M15346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by markr on Wed Oct 30 19:42:07 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;The code mentioned above is below.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-markr&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
while (1)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Loop forever */
&amp;nbsp; {
&amp;nbsp; while(!LPC_GPIO_PORT-&amp;gt;W0[ISP_PIN]) ;// wait if ISP button pressed
&amp;nbsp; while (!TimeTick);
&amp;nbsp; TimeTick=0;
#ifdef DBG_OUTPUT
&amp;nbsp; printf("R=%3d, G=%3d, B=%3d\n\r",red_pwm,green_pwm,blue_pwm);
#endif
//&amp;nbsp; NOTPORT0(PORT0_BIT6);
//&amp;nbsp; printf("%2d",color);
&amp;nbsp; switch (color) {
&amp;nbsp; case 0: //red
&amp;nbsp; if (inc_dec) {
&amp;nbsp;&amp;nbsp; if (++red_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; else if (--red_pwm == 0) {
&amp;nbsp;&amp;nbsp; color++;
&amp;nbsp;&amp;nbsp; inc_dec = TRUE;
&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; break;
&amp;nbsp; case 1: //green
&amp;nbsp; if (inc_dec) {
&amp;nbsp; if (++green_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else if (--green_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; case 2:// blue
&amp;nbsp; if (inc_dec) {
&amp;nbsp; if (++blue_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else if (--blue_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; case 3:// purple
&amp;nbsp; if (inc_dec) {
blue_pwm++;
red_pwm++;
&amp;nbsp; if (blue_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else {
blue_pwm--;
red_pwm--;
&amp;nbsp; if (blue_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; case 4:// yellow?
&amp;nbsp; if (inc_dec) {
green_pwm++;
red_pwm++;
&amp;nbsp; if (green_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else {
green_pwm--;
red_pwm--;
&amp;nbsp; if (green_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; case 5:// orange? blue is too weak
&amp;nbsp; if (inc_dec) {
green_pwm++;
blue_pwm++;
&amp;nbsp; if (green_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else {
green_pwm--;
blue_pwm--;
&amp;nbsp; if (green_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; case 6:// white
&amp;nbsp; if (inc_dec) {
red_pwm++;
green_pwm++;
blue_pwm++;
&amp;nbsp; if (green_pwm &amp;gt;= MAX_PWM) inc_dec = FALSE;
&amp;nbsp; }
&amp;nbsp; else {
red_pwm--;
green_pwm--;
blue_pwm--;
&amp;nbsp; if (green_pwm == 0) {
&amp;nbsp; color++;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; }
&amp;nbsp; }
&amp;nbsp; break;
&amp;nbsp; default:// clean up (should not be necessary)
&amp;nbsp; color = 0;
&amp;nbsp; inc_dec = TRUE;
&amp;nbsp; red_pwm=0;
&amp;nbsp; green_pwm=0;
&amp;nbsp; blue_pwm=0;
&amp;nbsp; }
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557222#M15346</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557223#M15347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by TheFallGuy on Wed Oct 30 20:28:46 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I would suggest that you need to debug this. You said that 'it appears the switch statement is not being executed' but you don't actually know until you debug it. I would suggest&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- in the Release build add the -g3 flag (Maximum debug info)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- disassemble your application so you can see what the code is&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- single step through your code to find out what is really not working. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; It is not easy debugging optimized code (all of the reasons explained the the FAQ you have been pointed at) but you will need to do it. These GCC compilers are very mature, so it is very unlikely to be a compiler problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We can speculate until the cows come home, but that is all we can do - speculate.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regarding use of volatile - the compiler is doing what every other ARM compiler will do when optimizing. It is very very different to the 8/16 bit compilers.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557223#M15347</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557224#M15348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by wmues on Thu Oct 31 00:52:12 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Markr,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if color is used only inside main(), there is no need to make color volatile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But you have 2 while loops at the start of the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- is TimeTick volatile?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Is LPC_GPIO_PORT-&amp;gt;W0[ISP_PIN] volatile?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If not, the compiler might assume that one of those variables is 0 and not changing value, so the rest of the loop is optimized away (unreachable code).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wolfgang&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557224#M15348</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557225#M15349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Dore on Thu Dec 12 02:00:13 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running short of memory in my controller. So I have enabled the optimization level 3 (Release mode) in my LPCXpresso. I am using LPC1114FHI33/302. With this one my code is fitting into the memory. But I will have to look into few concerns.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Is there any special care i have to takecare since I am enabling the optimization?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Is ok to keep the compiler optimization technique?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;- Any inputs on what exactly the optimization does and is it possible for me to take care of them so that I can go without any optimization?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Duraimurugan &lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557225#M15349</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557226#M15350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by lpcxpresso-support on Thu Dec 12 08:28:27 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;First of all, if you are worried about the size of your code, DO NOT use -O3 as it will increase code size (compared with -Os or -O2). This is because -O3 optimization is to do with speed and not size. For example, it will unroll small loops, making the code run faster, but at the cost of increasing the size.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Therefore, I suggest you use -O2 or -Os.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, please read this FAQ:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fsupport.code-red-tech.com%2FCodeRedWiki%2FCompilerOptimization" rel="nofollow" target="_blank"&gt;http://support.code-red-tech.com/CodeRedWiki/CompilerOptimization&lt;/A&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557226#M15350</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557227#M15351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by rocketdawg on Thu Dec 12 09:01:22 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;consider an accessor function to get the variable "color"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;uint32_t color;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;uint32_t GetColor(void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; return color;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;switch(getColor()) { blah blah}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"volatile" may or may not work, (depends on the compiler)&amp;nbsp; but the compiler cannot optimize out a function call.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557227#M15351</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557228#M15352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Dore on Thu Dec 12 09:59:56 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it recommended to use -Os or -O2 (in release mode)? will&amp;nbsp; there be any issues due to this which can affect the actual functionality?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And also if I would like to make the optimization on my own equivalent to the one on O2 or Os setting, how I can move forward on this?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557228#M15352</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557229#M15353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by LabRat on Thu Dec 12 10:55:42 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: Duraimurugan&lt;/STRONG&gt;&lt;BR /&gt;Is it recommended to use ...&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is recommended to use Google:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fgcc.gnu.org%2Fonlinedocs%2Fgcc%2FOptimize-Options.html" rel="nofollow" target="_blank"&gt;http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557229#M15353</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557230#M15354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by lpcxpresso-support on Thu Dec 12 10:57:24 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use -O2 or -Os - it is your choice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Provided you obey the rules (as described in the FAQ that I provided a link to) there will be no issues due to optimization.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Read the Help (Help-&amp;gt;Help contents) for information on all of the optimzations available and which ones are used at each level. Beware: this is for very advanced users only.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557230#M15354</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: optimization problem</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557231#M15355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by R2D2 on Thu Dec 12 11:11:49 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;In general O2 is the better (=faster) choice. If you are short of flash, use Os (= LPCXpresso default release setting).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:58:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/optimization-problem/m-p/557231#M15355</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:58:44Z</dc:date>
    </item>
  </channel>
</rss>

