<?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>Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9826/is-it-normal-that-this-function-takes-7kb-of-code-size</link><description>Hello,
I am programming nRF51 on Keil. My app uses BLE with softdevice S130, PWM, and I2C communication with two sensors. Also RTT for debugging. 
 I have already reached the limit code size of Keil with free license, 32kB.
I am using Optimization</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Oct 2015 12:17:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9826/is-it-normal-that-this-function-takes-7kb-of-code-size" /><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36473?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2015 12:17:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d39f5fc0-e099-4764-acdd-59b7924d67b3</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Glad to hear that! I&amp;#39;m using the latest ARM EABI GCC toolchain (4.9 2015q3) without problems and it works even with &lt;code&gt;-Os&lt;/code&gt; optimizations which is giving very good results in terms of code size. One more fro me then: using any float or non 2^ arithemtic in embedded app usually signs bad design and lack of understanding of such constrained system. All transformations should be one on the other side (unless you design extremely cost sensitive solution and ARM Cortex-M0 is your more powerful side;).&lt;/p&gt;
&lt;p&gt;Cheers Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36472?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2015 11:51:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79c6f48d-5ef9-49f0-a53c-1b742e6210a9</guid><dc:creator>Luis</dc:creator><description>&lt;p&gt;Answering myself from info on comments:
Yes, it is normal that this code, without optimization, takes almost 7Kb of code space.
Many other files were linked due to using floats, pow(), etc.&lt;/p&gt;
&lt;p&gt;If you face something similar do what endnode suggests:
&amp;quot;To the code size analysis: the usual (and probably the only &amp;quot;right&amp;quot; way) is to compile project twice, once with this new code and second time without. Then compare MAP files (or some equivalent produced by Keil) and you will clearly see where your magic 7kB come from.&amp;quot;&lt;/p&gt;
&lt;p&gt;What I did to compile my larger code was to install Eclipse+GCC and now I use that as my development environment. Very happy so far.  Followed this tutorial: &lt;a href="https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36471?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2015 11:47:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c18a38b8-77a4-4ace-810b-a0f9006fa0c0</guid><dc:creator>Luis</dc:creator><description>&lt;p&gt;Thank you for your comments.
I tried cygwin but found it difficult (I am 100% beginner on this things). So finally I followed this tutorial &lt;a href="https://devzone.nordicsemi.com/tutorials/7/development-with-gcc-and-eclipse/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt; and installed Eclipse + GCC. Very happy so far. :)
I will of course reduce float operations, but I need some. Also my nRF51 is all the processing power I have, since I am building an standalone robot and need those calculations for autocontrol.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36470?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2015 13:01:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0755cb30-50fc-4125-82b5-b106d356881b</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;Well you can use GCC from command line (e.g. by cygwin) just for compilation, don&amp;#39;t need to enter Eclipse nightmare (unless you love it;). To the code size analysis: the usual (and probably the only &amp;quot;right&amp;quot; way) is to compile project twice, once with this new code and second time without. Then compare MAP files (or some equivalent produced by Keil) and you will clearly see where your magic 7kB come from.&lt;/p&gt;
&lt;p&gt;Cheers Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36469?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2015 12:59:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a3db12d-38ca-4458-b17b-366c3fcc6eb8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Using double arithmetic on a Cortex M0 means a whole heap of math libraries are going to be pulled in to emulate floating point. If you look at your map file you should see all the stuff you&amp;#39;ve caused to be linked.&lt;/p&gt;
&lt;p&gt;Is this calculation you need to do on the device, can&amp;#39;t you send raw data and calculate on the other side where all the processing power is?&lt;/p&gt;
&lt;p&gt;I see you have sprintf() in there too, that&amp;#39;s another load of code. It&amp;#39;s less if you link with the nano-C library, I don&amp;#39;t know how to do that with Keil, or if it does it anyway.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36468?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2015 12:57:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6f32165-2265-4387-9650-cc4ccee68176</guid><dc:creator>Luis</dc:creator><description>&lt;p&gt;Thanks endnode.
I will surely consider migrating to GCC Eclipse.
It is true that this the only place I use pow so far, so that adds size, but twi functions were already used for the other sensor, so I believe they were already added to the initial 28kB...
Let&amp;#39;s assume pow takes 2kB, is it normal that the rest consumes 5kB? (not taking into account twi functions which I think are already included before)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is it normal that this function takes 7kB of code size?</title><link>https://devzone.nordicsemi.com/thread/36467?ContentTypeID=1</link><pubDate>Tue, 20 Oct 2015 12:48:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6de0b2e-140d-476c-89d8-238fe4435ddf</guid><dc:creator>endnode</dc:creator><description>&lt;p&gt;From what I see you use e.g. function &lt;code&gt;pow(...)&lt;/code&gt; which can include one or two kB itself from Keil lib (if this is the only place you call it). It also can easily be that some other function calls in this code are first and only one occurrence in your app and then they cause including whole modules (e.g. &lt;code&gt;twi_write_single2(...)&lt;/code&gt; ?). By refactoring you might come back under 32kB but in general I&amp;#39;d say you are close to the point where you either need paid Keil license or set-up your project with GCC where you are unlimited (and e.g. for me even the best optimizations &lt;code&gt;O3&lt;/code&gt; and &lt;code&gt;Os&lt;/code&gt; work, resulting code size is getting closer to Keil products - IAR is still better but that&amp;#39;s another story and investment).&lt;/p&gt;
&lt;p&gt;Cheers Jan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>