<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77780/disable-optimization-of-part-of-the-code-through-cmake</link><description>Hi, 
 A simple CMAKE question, somewhat regarding the zephyr build, but pretty essential for someone using JTAG to debug the application: 
 How does one disable optimization (-Os) for just a few files in the zephyr build? 
 
 I quicky tried a few things</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Jul 2021 09:30:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77780/disable-optimization-of-part-of-the-code-through-cmake" /><item><title>RE: Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/thread/321997?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 09:30:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54fc52da-8940-49ff-b09c-d91f09e1998a</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello!&lt;br /&gt;&lt;br /&gt;Good to hear that the solution helped! It depends a bit on what thread is crashing, but I guess this main stack. If so you can use the &lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/CONFIG_MAIN_STACK_SIZE.html?highlight=main%20stack_size#cmdoption-arg-CONFIG_MAIN_STACK_SIZE"&gt;CONFIG_MAIN_STACK_SIZE&lt;/a&gt;&amp;nbsp;to adjust. If that&amp;#39;s not the case you can check the Zephyr.map file in the build folder to find which thread&amp;nbsp;&lt;strong&gt;0x20016a68&lt;/strong&gt; corresponds to and then increase the stack size by using a fitting Kconfig option.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/thread/321965?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 07:45:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2d64963-6c14-4521-a959-fabe5bec557c</guid><dc:creator>Arnout</dc:creator><description>&lt;p&gt;By the way, just for info, I actually -tried running- this code now (asset_tracker from sdk 1.6.0, compiled with -O0)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This crashes at boot now, seems to be a stack overflow. (Makes sense, given the new compilation options).&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t happen to know by heart how to increase the thread stack sizes? :)&lt;/p&gt;
&lt;p&gt;If not, I think I&amp;#39;ll figure this out.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks again&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.6.[00:00:00.214,324] &amp;lt;inf&amp;gt; BH1749: BH1749 initialized
0-rc1-ncs1  ***
[00:00:00.250,915] &amp;lt;inf&amp;gt; asset_tracker: Asset tracker started
[00:00:00.257,141] &amp;lt;inf&amp;gt; watchdog: Watchdog timeout installed. Timeout: 60000
[00:00:00.264,739] &amp;lt;inf&amp;gt; watchdog: Watchdog started
[00:00:00.277,191] &amp;lt;dbg&amp;gt; nrf_cloud_transport.allocate_and_copy_client_id: client_id = nrf-352656101079153
[00:00:00.292,205] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_settings_set: Settings key: p_sesh, size: 4
[00:00:00.301,147] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_settings_set: Read setting val: 1
[00:00:00.313,568] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_topics_populate: accepted_topic: nrf-352656101079153/shadow/get/accepted
[00:00:00.325,012] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_topics_populate: rejected_topic: $aws/things/nrf-352656101079153/shadow/get/rejected
[00:00:00.337,615] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_topics_populate: update_delta_topic: $aws/things/nrf-352656101079153/shadow/update/delta
[00:00:00.350,646] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_topics_populate: update_topic: $aws/things/nrf-352656101079153/shadow/update
[00:00:00.362,518] &amp;lt;dbg&amp;gt; nrf_cloud_transport.nct_topics_populate: shadow_get_topic: $aws/things/nrf-352656101079153/shadow/get
[00:00:00.374,725] &amp;lt;inf&amp;gt; asset_tracker: Connecting to LTE network.
[00:00:00.381,347] &amp;lt;inf&amp;gt; asset_tracker: This may take several minutes.
+CEREG: 2,&amp;quot;0C3D&amp;quot;,&amp;quot;02BF6B05&amp;quot;,7,0,0,&amp;quot;11100000&amp;quot;,&amp;quot;11100000&amp;quot;
[00:00:02.437,744] &amp;lt;err&amp;gt; os: ***** USAGE FAULT *****
[00:00:02.443,359] &amp;lt;err&amp;gt; os:   Stack overflow (context area not valid)
[00:00:02.450,622] &amp;lt;err&amp;gt; os: r0/a1:  0xfdcf20f5  r1/a2:  0x01741200  r2/a3:  0x00000008
[00:00:02.459,381] &amp;lt;err&amp;gt; os: r3/a4:  0x000003e8 r12/ip:  0x0005029c r14/lr:  0x00000003
[00:00:02.468,139] &amp;lt;err&amp;gt; os:  xpsr:  0x00000000
[00:00:02.473,419] &amp;lt;err&amp;gt; os: s[ 0]:  0x00000000  s[ 1]:  0x00000000  s[ 2]:  0x00000000  s[ 3]:  0x00000000
[00:00:02.483,917] &amp;lt;err&amp;gt; os: s[ 4]:  0x00000000  s[ 5]:  0x00000000  s[ 6]:  0x00000000  s[ 7]:  0x00000000
[00:00:02.494,415] &amp;lt;err&amp;gt; os: s[ 8]:  0x00000000  s[ 9]:  0x00000000  s[10]:  0x00000000  s[11]:  0x00000000
[00:00:02.504,913] &amp;lt;err&amp;gt; os: s[12]:  0x00000000  s[13]:  0x00000000  s[14]:  0x00000000  s[15]:  0x00000000
[00:00:02.515,411] &amp;lt;err&amp;gt; os: fpscr:  0x0005029c
[00:00:02.520,660] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00000004
[00:00:02.528,625] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
[00:00:02.536,590] &amp;lt;err&amp;gt; os: Current thread: 0x20016a68 (unknown)
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/thread/321960?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 07:31:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:878cccc0-7313-4903-8829-29a0eaecb338</guid><dc:creator>Arnout</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;Nice! Adding the last 3 lines to the root CMakeList.txt file magically fix it indeed. It adds the -O0 parameter at the end for all app-compiled files, and not for the rest -- exactly what I wanted to do.&lt;/p&gt;
&lt;p&gt;Thanks for the help!&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Arnout&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/thread/321831?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 13:02:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee13990d-7075-4e6c-8b35-2bf051f5abbd</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello, Arnout!&lt;br /&gt;&lt;br /&gt;I&amp;#39;ve asked internally about this, but there seems to be some difficulties with optimization flags passed from CMake as stated in &lt;a href="https://github.com/zephyrproject-rtos/zephyr/issues/18652"&gt;this issue&lt;/a&gt;&amp;nbsp;on the Zephyr RTOS GitHub. Have you tried the &lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/CONFIG_NO_OPTIMIZATIONS.html"&gt;CONFIG_NO_OPTIMIZATIONS&lt;/a&gt; option in prj.conf?&lt;br /&gt;&lt;br /&gt;Edit: a colleague said that they have been using the following solution in a bit different context:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;add_library(set-app-flags INTERFACE)
target_compile_options(set-app-flags INTERFACE -O0)
target_link_libraries(app PRIVATE set-app-flags)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Disable optimization of part of the code through CMAKE</title><link>https://devzone.nordicsemi.com/thread/321358?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 12:44:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d4c51d8-8f26-4b1c-a69d-9f6e5c1ee7d7</guid><dc:creator>Arnout</dc:creator><description>&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/compileoptions.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;(The compile line, split into verticial lines, of e.g. main.c in asset_tracker, when adding t&lt;span&gt;arget_compile_options(app PRIVATE -O0)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>