<?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: USB-SD/MMC msc does not work due to compiler optimization.</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1249490#M44366</link>
    <description>&lt;P&gt;Thanks frank !&lt;BR /&gt;I have debugged carefully based on your advice.&lt;BR /&gt;It seems that the following code in main() has been erased by optimization.&lt;/P&gt;&lt;P&gt;*((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;&lt;/P&gt;&lt;P&gt;I rewrote the code below and it worked.&lt;/P&gt;&lt;P&gt;USBFSH-&amp;gt;PORTMODE |= USBFSH_PORTMODE_DEV_ENABLE_MASK;&lt;/P&gt;&lt;P&gt;It was very hard to debug because of the large scope, but I was able to narrow down the problem thanks to the following code I found in the source of startup.&lt;/P&gt;&lt;P&gt;#pragma GCC push_options&lt;BR /&gt;#pragma GCC optimize ("Og")&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;#pragma GCC pop_options&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Mar 2021 08:34:15 GMT</pubDate>
    <dc:creator>yo_ku_</dc:creator>
    <dc:date>2021-03-22T08:34:15Z</dc:date>
    <item>
      <title>USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248455#M44337</link>
      <description>&lt;P&gt;We have EMMC-msc project with target MCU:LPC54S018M MCUXpressoIDE: v11.3.0 SDK:v2.9.0 . It needs the compiler's Optimize Option -O2 for memory footprint and processing speed. But, when I compile it with -O2, this project cannot working. This problem is reproduced by the following NXP sample project.&lt;/P&gt;&lt;P&gt;target board: LPCXpresso54S018M&lt;/P&gt;&lt;P&gt;SDK example:lpcxpresso54s018m_dev_msc_disk_bm (usb example)&lt;/P&gt;&lt;P&gt;Setting: Optimize for more (-O2)&lt;/P&gt;&lt;P&gt;Use SD Card&lt;/P&gt;&lt;P&gt;Could you help us?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 00:31:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248455#M44337</guid>
      <dc:creator>yo_ku_</dc:creator>
      <dc:date>2021-03-19T00:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248673#M44339</link>
      <description>&lt;P&gt;This is most probably a bug on your side. Often, a required "volatile" attribute for variables is omitted, and the compiler intransigently optimizes it out.&lt;/P&gt;&lt;P&gt;E.g. almost everything an interrupt handler touches must be declared volatile, because no static analysis can show the compiler how and when such handlers touch a variable.&lt;/P&gt;&lt;P&gt;You can try debugging and check for routines to return errors, to narrow the code locations down. Debugging highly optimized code can be confusing, though.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 06:46:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248673#M44339</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2021-03-19T06:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248684#M44340</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;This problem is reproduced even with the default NXP sample without my additional code. Therefore, I believe that the omission of the "volatile" attribute you noted may be present in the HAL driver or SDMMC middleware.&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 06:59:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248684#M44340</guid>
      <dc:creator>yo_ku_</dc:creator>
      <dc:date>2021-03-19T06:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248719#M44343</link>
      <description>&lt;P&gt;Which is not really surprising, at least to me.&lt;/P&gt;&lt;P&gt;Free SDKs hardly ever claim commercial fitness, and the examples are polished to a point were the function well, and demonstrate a capability of the MCU/board. You cannot expect a rigorous test like e.g. required for a safety certificate (which is what am I required to do in my dayjob).&lt;/P&gt;&lt;P&gt;If that helps, some competitor's examples and SDKs are considerably worse ...&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 08:02:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248719#M44343</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2021-03-19T08:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248855#M44348</link>
      <description>&lt;P&gt;Yes, I agree with you.&lt;BR /&gt;NXP's IDEs and SDKs, even the free ones, are as good as the paid ones.&lt;BR /&gt;Still, I understand that it is not perfect, and I understand that it is getting better every day.&lt;BR /&gt;So my concern is that I can get help from the community.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 10:32:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248855#M44348</guid>
      <dc:creator>yo_ku_</dc:creator>
      <dc:date>2021-03-19T10:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248876#M44349</link>
      <description>&lt;P&gt;To a limited extend, yes. You are the one having the target hardware, and the source code. And many contributors here are volunteers with their own day jobs, not directly associated with NXP.&lt;/P&gt;&lt;P&gt;I hope you don't do busy-wait loops. But any delays or strictly timed sequences would be candidates as well.&lt;/P&gt;&lt;P&gt;I would start debuggung, and check what fails. E.g. do the USB / filesystem init functions work ? Or the access functions ?&lt;/P&gt;&lt;P&gt;If not, get down to the lower level driver function(s) raising the error.&lt;/P&gt;&lt;P&gt;This is usually as close as you can get with this method.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 11:14:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1248876#M44349</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2021-03-19T11:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1249490#M44366</link>
      <description>&lt;P&gt;Thanks frank !&lt;BR /&gt;I have debugged carefully based on your advice.&lt;BR /&gt;It seems that the following code in main() has been erased by optimization.&lt;/P&gt;&lt;P&gt;*((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;&lt;/P&gt;&lt;P&gt;I rewrote the code below and it worked.&lt;/P&gt;&lt;P&gt;USBFSH-&amp;gt;PORTMODE |= USBFSH_PORTMODE_DEV_ENABLE_MASK;&lt;/P&gt;&lt;P&gt;It was very hard to debug because of the large scope, but I was able to narrow down the problem thanks to the following code I found in the source of startup.&lt;/P&gt;&lt;P&gt;#pragma GCC push_options&lt;BR /&gt;#pragma GCC optimize ("Og")&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;#pragma GCC pop_options&lt;/P&gt;&lt;P&gt;B.R.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 08:34:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1249490#M44366</guid>
      <dc:creator>yo_ku_</dc:creator>
      <dc:date>2021-03-22T08:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: USB-SD/MMC msc does not work due to compiler optimization.</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1249643#M44376</link>
      <description>&lt;P&gt;BTW, an easier approach would be to incrementally either exclude or include one source file to optimisation. In other words, you can override compilation setting for individual sources. If the behavior changes, the is a problem in the module.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Mar 2021 11:38:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/USB-SD-MMC-msc-does-not-work-due-to-compiler-optimization/m-p/1249643#M44376</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2021-03-22T11:38:29Z</dc:date>
    </item>
  </channel>
</rss>

