<?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>topic Re: LPC55s28 SDK USB example are not working with -O2 optimization level in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1817171#M55514</link>
    <description>&lt;P&gt;To be honest, IMHO this is a common occurence.&lt;BR /&gt;Most vendor-supplied free libraries are not fit for aggressive optimisations, and robust commercial deployment. These libraries are churned out in far too much variants and too short timeframe to allow for proper (and costly) testing.&lt;BR /&gt;And in my experience this applies to all other vendors, too.&lt;/P&gt;&lt;P&gt;The "-O2" optimisation is a general setting. You could try to disable certain specific optimisations implied by O2, and see if it works.&lt;BR /&gt;Or you can try to debug the code, which could be quite surprising and confusing with high optimisation.&lt;BR /&gt;One common mistake is for instance the neglect of declaring all variables written to in interrupts as "volatile".&lt;/P&gt;&lt;P&gt;In rare cases high optimisation settings expose compiler bugs, but I think this is rather unlikely in this case.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 06:57:42 GMT</pubDate>
    <dc:creator>frank_m</dc:creator>
    <dc:date>2024-02-28T06:57:42Z</dc:date>
    <item>
      <title>LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1816854#M55512</link>
      <description>&lt;P&gt;Hello, I have an issue with the SDK USB examples code on the LPC55S28 dev board.&lt;/P&gt;&lt;P&gt;The default optimization level on Release builds is set to -Os, and with it, the examples are working fine.&lt;/P&gt;&lt;P&gt;However, when I change the optimization level to -O2 examples stop working. USB FS/HS device can't enumerate.&lt;/P&gt;&lt;P&gt;For demonstration, I took lpcxpresso55s28_dev_hid_generic_freertos, because I have to use RTOS in my application, but I believe this issue applies to bare metal and other USB examples also.&lt;/P&gt;&lt;P&gt;No code changes were made to the example.&lt;/P&gt;&lt;P&gt;All manipulations were done on the latest SDK and MCUXpresso IDE version, all of my board and project settings are attached.&lt;/P&gt;&lt;P&gt;Please help to solve this issue.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2024 21:49:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1816854#M55512</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-02-27T21:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1817171#M55514</link>
      <description>&lt;P&gt;To be honest, IMHO this is a common occurence.&lt;BR /&gt;Most vendor-supplied free libraries are not fit for aggressive optimisations, and robust commercial deployment. These libraries are churned out in far too much variants and too short timeframe to allow for proper (and costly) testing.&lt;BR /&gt;And in my experience this applies to all other vendors, too.&lt;/P&gt;&lt;P&gt;The "-O2" optimisation is a general setting. You could try to disable certain specific optimisations implied by O2, and see if it works.&lt;BR /&gt;Or you can try to debug the code, which could be quite surprising and confusing with high optimisation.&lt;BR /&gt;One common mistake is for instance the neglect of declaring all variables written to in interrupts as "volatile".&lt;/P&gt;&lt;P&gt;In rare cases high optimisation settings expose compiler bugs, but I think this is rather unlikely in this case.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 06:57:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1817171#M55514</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2024-02-28T06:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1817754#M55517</link>
      <description>&lt;P&gt;Hi frank_m&lt;/P&gt;&lt;P&gt;So far most of their examples worked great, which means they tested them. But if all SDK USB examples simply do not work with the -O2, it means they didn't test this case at all, and should look at this problem.&lt;/P&gt;&lt;P&gt;-O2 is not something rare it's a common optimization for production code. My code requires it.&lt;/P&gt;&lt;P&gt;LPC MCUs aren't the cheapest on the market, and many devices are built on these platforms, so decent testing, support, and bug fixing are expected in this case.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 18:13:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1817754#M55517</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-02-28T18:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818427#M55523</link>
      <description>&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&amp;gt; So far most of their examples worked great, which means they tested them. But if all SDK USB examples simply do not work with the -O2, it means they didn't test this case at all, and should look at this problem.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&amp;gt; LPC MCUs aren't the cheapest on the market, and many devices are built on these platforms, so decent testing, support, and bug fixing are expected in this case.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The problem is, what effort can you expect for free ?&lt;BR /&gt;Take the large number different MCUs and variants into account that require support.&lt;BR /&gt;Being involved with safety-related applications and code, efforts for testing, validating and documenting is a multiple of the time required for coding. A few years ago, my company purchased licenses for a safety-certified RT-OS for a six-figure sum - assessing this to be cheaper than developing it ourselves.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&amp;gt; -O2 is not something rare it's a common optimization for production code. My code requires it.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You have two options, I would say.&lt;BR /&gt;The first one is to locate the bug, and try to fix it. This might take some time, effort and experience.&lt;BR /&gt;The second option is to lower the bar. You could reduce the optimisation level to e.g. "-O1". This can be done on file level, and with some effort even on function level.&lt;BR /&gt;Or, you can get into optimisation details.&lt;BR /&gt;As said, "-O1" and "-O2" are just overall settings, that switch a number of individual optimisations on or off. Here the meaning for the GCC :&amp;nbsp;&lt;A href="https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html" target="_blank"&gt;https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html&lt;/A&gt;&lt;BR /&gt;You can try to leave O2 active and explicitly disable individual optimisations until the code works fine.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 07:14:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818427#M55523</guid>
      <dc:creator>frank_m</dc:creator>
      <dc:date>2024-02-29T07:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818682#M55525</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/164333"&gt;@emblink182&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I &lt;/SPAN&gt;&lt;SPAN&gt;tested &lt;/SPAN&gt;&lt;SPAN&gt;lpcxpresso55s28_dev_hid_generic_freertos&lt;/SPAN&gt;&lt;SPAN&gt;, the project with&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;optimization level ' -O2'&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;can not&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have work around, you can try. I change the hig_generit.c &lt;/SPAN&gt;&lt;SPAN&gt;optimization level&lt;/SPAN&gt;&lt;SPAN&gt; to -O0, it can work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Another way&lt;/SPAN&gt;&lt;SPAN&gt;, in hig_generit.c, you can &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#pragma GCC push_options&lt;/P&gt;
&lt;P&gt;#pragma GCC optimize ("O2")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;main{}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#pragma GCC pop_options&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;It also can work.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And I will report this issue to our SDK team&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Hang&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 10:29:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818682#M55525</guid>
      <dc:creator>Harry_Zhang</dc:creator>
      <dc:date>2024-02-29T10:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB examples are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818961#M55529</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/229957"&gt;@Harry_Zhang&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the search direction, I found the solution. It turned out that this bug was reported previously back in 2021, by&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/76479"&gt;@cgarcia&lt;/a&gt;&amp;nbsp;in &lt;A href="https://community.nxp.com/t5/LPC-Microcontrollers/LPC55xx-SDK-usb-driver-not-working-with-compiling-optimization/m-p/1817761/emcs_t/S2h8ZW1haWx8dG9waWNfc3Vic2NyaXB0aW9ufExUNjRGSENWMkRRTVZVfDE4MTc3NjF8U1VCU0NSSVBUSU9OU3xoSw#M55518" target="_self"&gt;this post&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But his fix wasn't added in the SDK for some reason.&lt;/P&gt;&lt;P&gt;Please add it, cause all of the USB examples have the same issue for HS and FS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;#if (defined USB_DEVICE_CONFIG_LPCIP3511HS) &amp;amp;&amp;amp; (USB_DEVICE_CONFIG_LPCIP3511HS)
    CLOCK_EnableClock(kCLOCK_Usbh1);
    /* Put PHY powerdown under software control */
    volatile uint32_t registerAddress = USBHSH_BASE + 0x50; // TODO: Add
    *((uint32_t *)(registerAddress)) = USBHSH_PORTMODE_SW_PDCOM_MASK; // TODO: Add 
    //TODO: REMOVE *((uint32_t *)(USBHSH_BASE + 0x50)) = USBHSH_PORTMODE_SW_PDCOM_MASK;
    /* According to reference mannual, device mode setting has to be set by access usb host register */
    *((uint32_t *)(registerAddress)) |= USBHSH_PORTMODE_DEV_ENABLE_MASK; // TODO: Add
    //TODO: REMOVE *((uint32_t *)(USBHSH_BASE + 0x50)) |= USBHSH_PORTMODE_DEV_ENABLE_MASK;
    /* enable usb1 host clock */
    CLOCK_DisableClock(kCLOCK_Usbh1);
#endif
#if (defined USB_DEVICE_CONFIG_LPCIP3511FS) &amp;amp;&amp;amp; (USB_DEVICE_CONFIG_LPCIP3511FS)
    POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*&amp;lt; Turn on USB Phy */
    CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false);
    CLOCK_AttachClk(kFRO_HF_to_USB0_CLK);
    /* enable usb0 host clock */
    CLOCK_EnableClock(kCLOCK_Usbhsl0);
    /*According to reference mannual, device mode setting has to be set by access usb host register */
    //TODO: REMOVE*((uint32_t *)(USBFSH_BASE + 0x5C)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK;
    volatile uint32_t registerAddress = USBFSH_BASE + 0x5C; // TODO: Add
    *((uint32_t *)(registerAddress)) |= USBFSH_PORTMODE_DEV_ENABLE_MASK; // TODO: Add
    /* disable usb0 host clock */
    CLOCK_DisableClock(kCLOCK_Usbhsl0);
#endif&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 18:45:15 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1818961#M55529</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-02-29T18:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865478#M56033</link>
      <description>&lt;P&gt;Hello, Greetings.&lt;BR /&gt;I need to optimize my project at the O3 level for LPC5516 board, which uses HS-USB.&lt;BR /&gt;The fact that USB is not identified in the device manager after O3 and O2 optimization indicates that USB is not working.&lt;BR /&gt;Please assist with helping me resolve this issue.&lt;/P&gt;</description>
      <pubDate>Tue, 14 May 2024 14:15:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865478#M56033</guid>
      <dc:creator>Swetha123</dc:creator>
      <dc:date>2024-05-14T14:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865605#M56036</link>
      <description>Hi Swetha123, have you tried the solution code posted on this topic?</description>
      <pubDate>Tue, 14 May 2024 17:46:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865605#M56036</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-05-14T17:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865899#M56042</link>
      <description>&lt;P&gt;Hello, emblink182. I appreciate your speedy response.&lt;BR /&gt;We tried the recommended solution but saw no progress.&lt;BR /&gt;Even using the SDK "lpcxpresso55s16_dev_cdc_vcom_freertos" with O3 and O2 optimization did not work.&lt;BR /&gt;SDK Version: 2.14.0.&lt;BR /&gt;Manifest version: 3.13.0.&lt;BR /&gt;IDE version: MCUXpresso IDE 11.8.0 [Build 1165] [2023-07-26]&lt;BR /&gt;I've attached the source file for reference.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 04:52:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1865899#M56042</guid>
      <dc:creator>Swetha123</dc:creator>
      <dc:date>2024-05-15T04:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1866533#M56053</link>
      <description>&lt;P&gt;Hi Swetha123, I don't have a 55s16 board so I can't debug your project. But looks like there is a typo in the code, please check the screenshots attached. I tried the same modifications on my 55s28 board and they worked fine with -O2 and -O3.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 19:15:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1866533#M56053</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-05-15T19:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1869363#M56107</link>
      <description>&lt;P&gt;Hello, emblink182&lt;/P&gt;&lt;P&gt;Apologies for the delayed response. After correcting the typo once more, we were able to run the USB SDK at the O2 level, but the O3 level is still not functioning.&lt;BR /&gt;The same piece of solution was patched to the project where HS-USB operates, however it still fails in O2 and O3.&lt;/P&gt;&lt;P&gt;However, in the project, we discovered that USB began to function at the O2 level when the usb initialization function was called from the main accessible in the USB source file "virtual_com.c", but failed when the usb initialization function was called from the main produced in our project.&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2024 05:18:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1869363#M56107</guid>
      <dc:creator>Swetha123</dc:creator>
      <dc:date>2024-05-21T05:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: LPC55s28 SDK USB example are not working with -O2 optimization level</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1870128#M56117</link>
      <description>Hi Swetha123, I think it's something related to your specific project because my 55s28 board has the same USB hardware and uses the same SDK driver as yours 5516. Try to narrow down the search by using the technique suggested in this topic. Apply these preprocessor directives to suspected files or functions.&lt;BR /&gt;&lt;BR /&gt;#pragma GCC push_options&lt;BR /&gt;&lt;BR /&gt;#pragma&amp;nbsp;GCC optimize ("O0")&lt;BR /&gt;&lt;BR /&gt;#pragma GCC pop_options</description>
      <pubDate>Wed, 22 May 2024 01:47:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC55s28-SDK-USB-example-are-not-working-with-O2-optimization/m-p/1870128#M56117</guid>
      <dc:creator>emblink182</dc:creator>
      <dc:date>2024-05-22T01:47:58Z</dc:date>
    </item>
  </channel>
</rss>

