<?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>Compile modules selectively in release vs debug to optimize flash usage in nRF52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79403/compile-modules-selectively-in-release-vs-debug-to-optimize-flash-usage-in-nrf52840</link><description>Hi, 
 
 We use the nRF52840 and have now run out of space using debug mode compilation (using CMake from bash). 
 When we compile in release mode, we get 50% full flash, so that is great. 
 What we want to accomplish now, is to be able to select which</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Sep 2021 14:46:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79403/compile-modules-selectively-in-release-vs-debug-to-optimize-flash-usage-in-nrf52840" /><item><title>RE: Compile modules selectively in release vs debug to optimize flash usage in nRF52840</title><link>https://devzone.nordicsemi.com/thread/328871?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 14:46:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed45bf46-6eb7-4179-aef1-d3e8b39347a3</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Johan,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for updating the case. I did not find this option when looking myself, very good to see that its possible to do this in a portable way!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile modules selectively in release vs debug to optimize flash usage in nRF52840</title><link>https://devzone.nordicsemi.com/thread/328730?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 08:16:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0f477d1-b858-4975-8c98-f3640bcacff1</guid><dc:creator>Johan</dc:creator><description>&lt;p&gt;Ok thanks H&amp;aring;kon.&lt;br /&gt;&lt;br /&gt;I got this from Zephyrs discord channel help on Nordic subjects.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;/p&gt;
&lt;div class="message-2qnXI6 cozyMessage-3V1Y8y groupStart-23k01U wrapper-2a6GCs cozy-3raOZG zalgo-jN1Ica" id="chat-messages-885144128189517844"&gt;
&lt;div class="contents-2mQqc9"&gt;
&lt;div class="markup-2BOw-j messageContent-2qWWxC"&gt;yes, that is possible. You can place dedicated compile options on a Zephyr library (the &lt;code class="inline"&gt;app&lt;/code&gt; library is a Zephyr library). For example in you toplevel CMakeLists.txt file you may do:
&lt;pre&gt;&lt;code class="scrollbarGhostHairline-1mSOM1 scrollbar-3dvm_9 hljs"&gt;find_package(Zephyr ...)
project(my_project)
 
zephyr_library_compile_options(-O0)
target_sources(app ...)&lt;/code&gt;&lt;/pre&gt;
That will make that particular library compile with &lt;code class="inline"&gt;-O0&lt;/code&gt; while the rest of Zephyr compiles with the optimization you have specified in prj.conf / Kconfig&lt;span class="timestamp-3ZCmNB timestampInline-yHQ6fX"&gt;&lt;time datetime="2021-09-08T12:47:07.565Z"&gt;&lt;span class="edited-3sfAzf"&gt;(edited)&lt;/span&gt;&lt;/time&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="buttonContainer-DHceWr"&gt;
&lt;div class="buttons-cl5qTG container-3npvBV isHeader-2dII4U"&gt;
&lt;div class="wrapper-2aW0bm"&gt;
&lt;div class="button-1ZiXG9"&gt;&amp;quot;&lt;/div&gt;
&lt;div class="button-1ZiXG9"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h1 dir="auto"&gt;zephyr/Kconfig.zephyr&lt;/h1&gt;
&lt;p dir="auto"&gt;&lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/main/Kconfig.zephyr#L275-L309" rel="nofollow noopener noreferrer" target="_blank"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/Kconfig.zephyr#L275-L309&lt;/a&gt;&lt;/p&gt;
&lt;h1 dir="auto"&gt;&lt;a class="anchor" id="user-content-docs-latest-choice-optimization-level" href="#docs-latest-choice-optimization-level"&gt;&lt;/a&gt;Docs / Latest &amp;raquo; choice: Optimization level&lt;/h1&gt;
&lt;p dir="auto"&gt;&lt;a href="https://docs.zephyrproject.org/latest/reference/kconfig/choice_536.html" rel="nofollow noopener noreferrer" target="_blank"&gt;https://docs.zephyrproject.org/latest/reference/kconfig/choice_536.html&lt;/a&gt;&lt;/p&gt;
&lt;h1 dir="auto"&gt;&lt;a class="anchor" id="user-content-prjconf" href="#prjconf"&gt;&lt;/a&gt;prj.conf&lt;/h1&gt;
&lt;p dir="auto"&gt;tejlmand &amp;mdash; &lt;br /&gt;When using in prj.conf, remember to put CONFIG_ first, like: CONFIG_SIZE_OPTIMIZATIONS=y&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Compile modules selectively in release vs debug to optimize flash usage in nRF52840</title><link>https://devzone.nordicsemi.com/thread/328611?ContentTypeID=1</link><pubDate>Wed, 08 Sep 2021 12:51:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad49ccb9-85aa-44b8-8215-15908d0ea7a7</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Johan,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;p&gt;For example:&lt;/p&gt;
&lt;p&gt;- zephyr modules -&amp;gt; release compilation&lt;/p&gt;
&lt;p&gt;- nordic modules -&amp;gt; release compilation&lt;/p&gt;
&lt;p&gt;- our application src folder - debug compilation as we need to debug it - or be able to select which folders in that src-folder to compile as debug vs release mode.&lt;/p&gt;[/quote]
&lt;p&gt;The only thing that comes to mind is to force&amp;nbsp;GCC&amp;nbsp;to set a specific optimize level on your sources, via the #pragma directive:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html"&gt;https://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can guard that pragma + push/pop lines with a if defined(some_symbol). Note that this is not a portable solution.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>