<?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: compilation with optimisation for size code</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572097#M20871</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Tue Jan 06 23:29:22 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;After looking at the rest of the functions in file timer.c, I found that the only place that you actually perform a read of any of the structure members is in the function timer_expired_task() and that structure member is "state".&amp;nbsp; Therefore it is probably safe to say that only the structure member that needs to be declared volatile within the structure definition is "state".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So the structure definition then becomes&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;/**
 * \struct timer_t
 * \brief défintion de l'objet timer
 */
typedef struct
{
uint16_t count;/*!&amp;lt; valeur du compteur */
uint16_t initVAL;/*!&amp;lt; valeur d'initialisation du compteur */
[color=#f00]volatile[/color] timerState_t state; /*!&amp;lt; état du timer */
optionIT_t option;/*!&amp;lt; option pour le lancement de la fonction associée */
void (*TASK)(void);/*!&amp;lt; pointeur vers la fonction qui sera lancée à expiration du timer */
}timer_t;
&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 22:31:07 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T22:31:07Z</dc:date>
    <item>
      <title>compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572094#M20868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sicotc on Tue Jan 06 09:18:12 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm using LPC11E14 with lpcxpresso V7.4.0 [Build 229]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Without any optimisation code, everything works.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But when I use "optimize for size", the software stop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After searching, I saw a bug in the assembler code, adr=4bc, 'jump to itself" :&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt;&lt;PRE&gt;
000004ac &amp;lt;delay_ms&amp;gt;:
 4ac:b510&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; push{r4, lr}
 4ae:4c06&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrr4, [pc, #24]; (4c8 &amp;lt;delay_ms+0x1c&amp;gt;)
 4b0:1c01&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addsr1, r0, #0
 4b2:1c20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addsr0, r4, #0
 4b4:f7ff fff2 bl49c &amp;lt;timer_reset&amp;gt;
 4b8:7923&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrbr3, [r4, #4]
 4ba:2b02&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cmpr3, #2
 4bc:d000&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; beq.n4c0 &amp;lt;delay_ms+0x14&amp;gt;
 [color=#f33]&lt;STRONG&gt;4be:e7fe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.n4be &amp;lt;delay_ms+0x12&amp;gt;&lt;/STRONG&gt;[/color]
 4c0:2301&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movsr3, #1
 4c2:7123&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; strbr3, [r4, #4]
 4c4:bd10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pop{r4, pc}
 4c6:46c0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nop; (mov r8, r8)
 4c8:10000018 .word0x10000018&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;the source code is :&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class="j-rte-table"&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca" style="border:1px solid black;background-color:#cacaca;"&gt;&lt;PRE&gt;
void delay_ms(uint16_t time)
{ 
timer_reset(&amp;amp; delay_ms_v,time);
while(timer_expired_task(&amp;amp; delay_ms_v)==0)
{
}
}&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;find attached the workspace directory with the simplified project.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In debug mode, it is easy to locate where the code stop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible to have a solution for this problem ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Sicotc&lt;/SPAN&gt;&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-338152" rel="nofollow noopener noreferrer" target="_blank"&gt;workspace_testBUG.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:31:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572094#M20868</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572095#M20869</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 Tue Jan 06 09:24:12 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Make sure you are using the '&lt;/SPAN&gt;&lt;I&gt;volatile&lt;/I&gt;&lt;SPAN&gt;' keyword….&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.lpcware.com%2Fcontent%2Ffaq%2Flpcxpresso%2Fcompiler-optimization" rel="nofollow" target="_blank"&gt;http://www.lpcware.com/content/faq/lpcxpresso/compiler-optimization&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPCXpresso Support&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:31:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572095#M20869</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:05Z</dc:date>
    </item>
    <item>
      <title>Re: compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572096#M20870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sicotc on Tue Jan 06 13:52:48 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks a lot,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;the following code solve the problem :&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;
void delay_ms(uint16_t time)
{
volatile int status=0;
timer_reset(&amp;amp; delay_ms_v,time);
while(!status)
{
status=timer_expired_task(&amp;amp; delay_ms_v);
}
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:31:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572096#M20870</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572097#M20871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Tue Jan 06 23:29:22 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;After looking at the rest of the functions in file timer.c, I found that the only place that you actually perform a read of any of the structure members is in the function timer_expired_task() and that structure member is "state".&amp;nbsp; Therefore it is probably safe to say that only the structure member that needs to be declared volatile within the structure definition is "state".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So the structure definition then becomes&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;/**
 * \struct timer_t
 * \brief défintion de l'objet timer
 */
typedef struct
{
uint16_t count;/*!&amp;lt; valeur du compteur */
uint16_t initVAL;/*!&amp;lt; valeur d'initialisation du compteur */
[color=#f00]volatile[/color] timerState_t state; /*!&amp;lt; état du timer */
optionIT_t option;/*!&amp;lt; option pour le lancement de la fonction associée */
void (*TASK)(void);/*!&amp;lt; pointeur vers la fonction qui sera lancée à expiration du timer */
}timer_t;
&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 22:31:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572097#M20871</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572098#M20872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by larryvc on Tue Jan 06 23:54:24 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: sicotc&lt;/STRONG&gt;&lt;BR /&gt;thanks a lot,&lt;BR /&gt;the following code solve the problem :&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It may have solved the problem, but was it the best option, or even the correct one?&amp;nbsp; Now function delay_ms() is 40 bytes long!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;On top of that the problem was not in function delay_ms().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Because the typedef struct timer_t, and specifically the structure member "state",&amp;nbsp; was not declared volatile the compiler optimizations caused the code to hang in a loop in function timer_expired_task().&amp;nbsp; The optimizations placed "state" in a register and the compiler thought that it did not need to load the value of 'state' any longer because the value was already in a register .&amp;nbsp; Therefore the comparison of "state != timer_task_expired", as far as the compiler could tell, was never going to be triggered and that is why the compiler generated code for the never ending loop at address 4be.&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;4be:e7fe&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.n4be &lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you change the typedef struct timer_t in file timer.h to this&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;
/**
 * \struct timer_t
 * \brief défintion de l'objet timer
 */
[color=#f00]volatile[/color] typedef struct
{
uint16_t count;/*!&amp;lt; valeur du compteur */
uint16_t initVAL;/*!&amp;lt; valeur d'initialisation du compteur */
timerState_t state; /*!&amp;lt; état du timer */
optionIT_t option;/*!&amp;lt; option pour le lancement de la fonction associée */
void (*TASK)(void);/*!&amp;lt; pointeur vers la fonction qui sera lancée à expiration du timer */
}timer_t;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and change function delay_ms in file timer.c to this&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;void delay_ms(uint16_t time)
{
timer_reset(&amp;amp; delay_ms_v,time);
while(!(timer_expired_task(&amp;amp; delay_ms_v)));
}
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then you will have a very efficiently working function delay_ms() that is only 24 bytes long and the code does not hang in function timer_expired_task().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It may be that you only need to make the structure member "state" volatile instead of the entire structure.&amp;nbsp; I will leave that up to you to test.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:31:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572098#M20872</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: compilation with optimisation for size code</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572099#M20873</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by sicotc on Wed Jan 07 05:31:07 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your explanation.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:31:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/compilation-with-optimisation-for-size-code/m-p/572099#M20873</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:31:08Z</dc:date>
    </item>
  </channel>
</rss>

