<?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>Kinetis Design Studio中的主题 Re: Hard fault when calling sprintf with floating point numbers from .cpp file</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Hard-fault-when-calling-sprintf-with-floating-point-numbers-from/m-p/726700#M9396</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might be related to your heap/stack allocation (see &lt;A class="link-titled" href="https://mcuoneclipse.com/2014/03/16/freertos-malloc-and-sp-check-with-gnu-tools/" title="https://mcuoneclipse.com/2014/03/16/freertos-malloc-and-sp-check-with-gnu-tools/"&gt;FreeRTOS, malloc() and SP check with GNU Tools | MCU on Eclipse&lt;/A&gt;&amp;nbsp;) as depending on your library usage (newlib or newlib-nano) it will use malloc(), and if the heap is misplaced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I quickly tried to reproduce what you say, but it worked for me. Attached is a project for the FRDM-K64F, just in case you spot the difference to your setup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Jan 2018 09:22:28 GMT</pubDate>
    <dc:creator>BlackNight</dc:creator>
    <dc:date>2018-01-16T09:22:28Z</dc:date>
    <item>
      <title>Hard fault when calling sprintf with floating point numbers from .cpp file</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Hard-fault-when-calling-sprintf-with-floating-point-numbers-from/m-p/726699#M9395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have been having trouble using sprintf for floats.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read all of the posts I could find on the topic and failed to resolve the problem.&lt;/P&gt;&lt;P&gt;I am using KDS 3.2 with processor expert&amp;nbsp;with a K26F processor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The current state of my program is as follows:&lt;/P&gt;&lt;P&gt;when I call&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;sprintf((char*)s,"Event;\t&amp;nbsp; %f\r\n ",1.5);&lt;/PRE&gt;&lt;P&gt;from main.c,&amp;nbsp;It works fine.&lt;/P&gt;&lt;P&gt;The exact call from a .cpp file results in a hard fault.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several other uses of sprintf with integers, without any problems.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note that I have already tried&amp;nbsp;the following (this is the current state of my project):&lt;/P&gt;&lt;P&gt;1. Enlarging the heap and stack.&lt;/P&gt;&lt;P&gt;2. In the cross ARM C++ Linker settings, I checked&lt;/P&gt;&lt;P&gt;"use float with nano printf (-u _printf_float)" and&amp;nbsp;&lt;SPAN&gt;"use float with nano scanf (-u _scanf_float)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. In Cross ARM C Compiler Preprocessor definitions I defined&amp;nbsp;"PRINTF_FLOAT_ENABLE=1"&amp;nbsp; and&amp;nbsp;&amp;nbsp;"SCANF_FLOAT_ENABLE=1".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4. Called&amp;nbsp; the following after startup:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;void vPortEnableVFP(void) {&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* The FPU enable bits are in the CPACR. */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;__asm volatile (&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" ldr.w r0, =0xE000ED88 \n" /* CAPCR, 0xE000ED88 */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" ldr r1, [r0] \n" /* read CAPR */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" orr r1, r1, #(0xf&amp;lt;&amp;lt;20) \n" /* Enable CP10 and CP11 coprocessors */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;" str r1,[r0] \n" /* store to new value back */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;: /* no output */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;: /* no input */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;: "r0","r1" /* clobber */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any further suggestions?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jan 2018 07:52:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Hard-fault-when-calling-sprintf-with-floating-point-numbers-from/m-p/726699#M9395</guid>
      <dc:creator>danielhurowitz</dc:creator>
      <dc:date>2018-01-16T07:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Hard fault when calling sprintf with floating point numbers from .cpp file</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/Hard-fault-when-calling-sprintf-with-floating-point-numbers-from/m-p/726700#M9396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It might be related to your heap/stack allocation (see &lt;A class="link-titled" href="https://mcuoneclipse.com/2014/03/16/freertos-malloc-and-sp-check-with-gnu-tools/" title="https://mcuoneclipse.com/2014/03/16/freertos-malloc-and-sp-check-with-gnu-tools/"&gt;FreeRTOS, malloc() and SP check with GNU Tools | MCU on Eclipse&lt;/A&gt;&amp;nbsp;) as depending on your library usage (newlib or newlib-nano) it will use malloc(), and if the heap is misplaced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I quickly tried to reproduce what you say, but it worked for me. Attached is a project for the FRDM-K64F, just in case you spot the difference to your setup.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jan 2018 09:22:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/Hard-fault-when-calling-sprintf-with-floating-point-numbers-from/m-p/726700#M9396</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2018-01-16T09:22:28Z</dc:date>
    </item>
  </channel>
</rss>

