<?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>CodeWarrior for MCU中的主题 volatile access optimized away (CW10.1 Kinetis)</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/volatile-access-optimized-away-CW10-1-Kinetis/m-p/175462#M5670</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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I compiled the following C++ function with CW 10.1 for Kinetis and found what I believe to be a volatile optimization bug.&lt;/P&gt;&lt;PRE&gt;void DebugResetFTM0Status(){&amp;nbsp; volatile uint32* pReg = &amp;amp;FTM0_STATUS;&amp;nbsp; *pReg = *pReg &amp;amp; 0;}&lt;/PRE&gt;&lt;P&gt;I expect the assembly code to read the FTM register and write back a 0. The Freescale FlexTimer has interrupt flags with a "write 0 after reading 1" reset protocol, so I really care for the read. If I want reads and writes optimized away, I leave out the "volatile".&lt;/P&gt;&lt;P&gt;The disassembly (from the debugger) shows that the C++ compiler optimized the volatile read-write combination away.&lt;/P&gt;&lt;PRE&gt;00010120:&amp;nbsp;&amp;nbsp; movw r5,#0x805000010124:&amp;nbsp;&amp;nbsp; movt r5,#0x400300010128:&amp;nbsp;&amp;nbsp; movs r0,#00001012a:&amp;nbsp;&amp;nbsp; str r0,[r5,#0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Blind store of 0 into the FTM register!; followed by an uninteresting epilogue, ldm this, add sp that.&lt;/PRE&gt;&lt;P&gt;Version info: CodeWarrior for MCU Version: 10.1 Build Id:110204, with whatever C++ compiler that brings along. I compiled for the K60 derivate on the TWR K60 board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings, KA&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:24:02 GMT</pubDate>
    <dc:creator>konrada</dc:creator>
    <dc:date>2020-10-29T09:24:02Z</dc:date>
    <item>
      <title>volatile access optimized away (CW10.1 Kinetis)</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/volatile-access-optimized-away-CW10-1-Kinetis/m-p/175462#M5670</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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I compiled the following C++ function with CW 10.1 for Kinetis and found what I believe to be a volatile optimization bug.&lt;/P&gt;&lt;PRE&gt;void DebugResetFTM0Status(){&amp;nbsp; volatile uint32* pReg = &amp;amp;FTM0_STATUS;&amp;nbsp; *pReg = *pReg &amp;amp; 0;}&lt;/PRE&gt;&lt;P&gt;I expect the assembly code to read the FTM register and write back a 0. The Freescale FlexTimer has interrupt flags with a "write 0 after reading 1" reset protocol, so I really care for the read. If I want reads and writes optimized away, I leave out the "volatile".&lt;/P&gt;&lt;P&gt;The disassembly (from the debugger) shows that the C++ compiler optimized the volatile read-write combination away.&lt;/P&gt;&lt;PRE&gt;00010120:&amp;nbsp;&amp;nbsp; movw r5,#0x805000010124:&amp;nbsp;&amp;nbsp; movt r5,#0x400300010128:&amp;nbsp;&amp;nbsp; movs r0,#00001012a:&amp;nbsp;&amp;nbsp; str r0,[r5,#0]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; Blind store of 0 into the FTM register!; followed by an uninteresting epilogue, ldm this, add sp that.&lt;/PRE&gt;&lt;P&gt;Version info: CodeWarrior for MCU Version: 10.1 Build Id:110204, with whatever C++ compiler that brings along. I compiled for the K60 derivate on the TWR K60 board.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings, KA&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:24:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/volatile-access-optimized-away-CW10-1-Kinetis/m-p/175462#M5670</guid>
      <dc:creator>konrada</dc:creator>
      <dc:date>2020-10-29T09:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: volatile access optimized away (CW10.1 Kinetis)</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/volatile-access-optimized-away-CW10-1-Kinetis/m-p/175463#M5671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please file an on-line service request for this problem. Click &lt;A href="https://www.freescale.com/webapp/servicerequest.create_SR.framework" rel="nofollow" target="_self"&gt;here&lt;/A&gt; to go the the service request page.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Oct 2011 18:47:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/volatile-access-optimized-away-CW10-1-Kinetis/m-p/175463#M5671</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2011-10-20T18:47:56Z</dc:date>
    </item>
  </channel>
</rss>

