<?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 Adding floating point support for printf() and scanf() to your project in Kinetis Design Studio</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Adding-floating-point-support-for-printf-and-scanf-to-your/m-p/620948#M7937</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-weight: normal;"&gt;Note: this is a "howto" question and answer&amp;nbsp;rather than a real question, given because it may be helpful to others.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; font-weight: normal;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Description of the Problem:&lt;/STRONG&gt; printf("%f", 2.0) doesn't print anything, nor does it give any errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jan 2017 19:13:38 GMT</pubDate>
    <dc:creator>robertpoor</dc:creator>
    <dc:date>2017-01-16T19:13:38Z</dc:date>
    <item>
      <title>Adding floating point support for printf() and scanf() to your project</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Adding-floating-point-support-for-printf-and-scanf-to-your/m-p/620948#M7937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-weight: normal;"&gt;Note: this is a "howto" question and answer&amp;nbsp;rather than a real question, given because it may be helpful to others.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px; font-weight: normal;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Description of the Problem:&lt;/STRONG&gt; printf("%f", 2.0) doesn't print anything, nor does it give any errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 19:13:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Adding-floating-point-support-for-printf-and-scanf-to-your/m-p/620948#M7937</guid>
      <dc:creator>robertpoor</dc:creator>
      <dc:date>2017-01-16T19:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding floating point support for printf() and scanf() to your project</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Adding-floating-point-support-for-printf-and-scanf-to-your/m-p/620949#M7938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Note: this is a "howto"&amp;nbsp;response rather than a genuine question, given because it may be helpful to others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Disclaimer: The information here has been cobbled together from several sources and experimentation. &amp;nbsp;It works for my environment (KDS 3.2.0 running under Mac OSX 10.12.2, Cross ARM C compiler), but details may be different for your environment.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Description of the Problem:&lt;/STRONG&gt; printf("%f", 2.0) doesn't print anything.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reason:&lt;/STRONG&gt; The Cross ARM C compiler (and linker) do not provide support for printing and scanning floating point numbers&amp;nbsp;by default.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution:&lt;/STRONG&gt; You can add support to the Cross ARM C compiler for printing and scanning floating point numbers (and doubles) as follows.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-top: 0pt; margin-bottom: 0pt;"&gt;&lt;/P&gt;&lt;OL style="padding: 0px 0px 0px 30px;"&gt;&lt;LI style="margin: 0.2em 0px;"&gt;In KDS, under the &lt;STRONG&gt;Project&lt;/STRONG&gt; menu item, click on &lt;STRONG&gt;Properties&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Expand the &lt;STRONG&gt;C/C++ Build&lt;/STRONG&gt; item in the left hand column&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click on &lt;STRONG&gt;C/C++ Build Settings&lt;/STRONG&gt; in the left hand column&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click on &lt;STRONG&gt;[Tool Settings]&lt;/STRONG&gt; tab in the right hand panel&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Expand the &lt;STRONG&gt;Cross Arm C Compiler&lt;/STRONG&gt; item&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click on &lt;STRONG&gt;Cross Arm C Compiler / Preprocessor&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;In the &lt;STRONG&gt;Defined Symbols (-D)&lt;/STRONG&gt; panel, click on the &lt;STRONG&gt;+&lt;/STRONG&gt; icon&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;In the dialog panel that appears, type "&lt;STRONG&gt;PRINTF_FLOAT_ENABLE=1&lt;/STRONG&gt;" and &lt;STRONG&gt;[OKAY]&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click on the &lt;STRONG&gt;+&lt;/STRONG&gt; icon again&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;In the dialog panel that appears, type "&lt;STRONG&gt;SCANF_FLOAT_ENABLE=1&lt;/STRONG&gt;" and &lt;STRONG&gt;[OKAY]&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click &lt;STRONG&gt;[Apply]&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Expand the &lt;STRONG&gt;Cross Arm C++ Linker&lt;/STRONG&gt; item&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click on &lt;STRONG&gt;Cross Arm C++ Linker / Miscellaneous&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;In the right hand panel, enable the two check boxes labeled "&lt;STRONG&gt;Use float with nano printf (-u _printf_float)&lt;/STRONG&gt;" and "&lt;STRONG&gt;Use float with nano scanf (-u _scanf_float)&lt;/STRONG&gt;".&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click &lt;STRONG&gt;[Apply]&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI style="margin: 0.2em 0px;"&gt;Click &lt;STRONG&gt;[OK]&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can test that printf() works with floats by creating a project based on&amp;nbsp;the "Hello World" demo application and modifying it as follows:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;#include&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;"fsl_device_registers.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;#include&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;"fsl_debug_console.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;#include&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;"board.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;#include&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;"pin_mux.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;#include&lt;/SPAN&gt;&lt;SPAN class=""&gt; &lt;/SPAN&gt;"clock_config.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;int&lt;/SPAN&gt; main(&lt;SPAN class=""&gt;void&lt;/SPAN&gt;)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;char&lt;/SPAN&gt; ch;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;double&lt;/SPAN&gt; val;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;BOARD_InitPins();&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;BOARD_BootClockRUN();&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;BOARD_InitDebugConsole();&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;val = 0.01;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;for&lt;/SPAN&gt; (&lt;SPAN class=""&gt;int&lt;/SPAN&gt; i=0; i&amp;lt;5; i++) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;PRINTF(&lt;SPAN class=""&gt;"&lt;/SPAN&gt;&lt;SPAN class=""&gt;val&lt;/SPAN&gt;&lt;SPAN class=""&gt; = %f\n"&lt;/SPAN&gt;, val);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;val *= 10.0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN class=""&gt;while&lt;/SPAN&gt; (1)&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;ch = GETCHAR();&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;PUTCHAR(ch);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;&lt;SPAN class=""&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If all goes well, you should see this printed on the console:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro" style="background: none #f6f6f6; border-left: 2px solid #cccccc; margin: 10px 0px; padding: 10px 20px;"&gt;&lt;P&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;val = 0.010000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;val = 0.100000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;val = 1.000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;val = 10.000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: terminal, monaco, monospace;"&gt;val = 100.000000&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 21:14:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Adding-floating-point-support-for-printf-and-scanf-to-your/m-p/620949#M7938</guid>
      <dc:creator>robertpoor</dc:creator>
      <dc:date>2017-01-16T21:14:38Z</dc:date>
    </item>
  </channel>
</rss>

