<?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>LPCXpresso IDE中的主题 problem with float variable</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/problem-with-float-variable/m-p/540825#M7173</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JoeE on Fri Aug 08 12:03:54 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am working with lpc4370 processor (FPv4-SP Soft ABI) and have a strange issue with a floating point variable. Every time when I am asigning a global integer to the local float variable a hard fault error occors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anybody have an explanation for that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the example code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//global variable &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;volatile int32_t g = 200;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void myfunction(void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int32_t a, b;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;float r, t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;r = 1.5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b = 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 1 (works)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;t= r;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 2 (works)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;t = b;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 3 (not working – ending in hard fault handler)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;t= g; // error occurs here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 23:19:05 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T23:19:05Z</dc:date>
    <item>
      <title>problem with float variable</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/problem-with-float-variable/m-p/540825#M7173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by JoeE on Fri Aug 08 12:03:54 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am working with lpc4370 processor (FPv4-SP Soft ABI) and have a strange issue with a floating point variable. Every time when I am asigning a global integer to the local float variable a hard fault error occors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anybody have an explanation for that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the example code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//global variable &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;volatile int32_t g = 200;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;void myfunction(void)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int32_t a, b;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;float r, t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;r = 1.5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b = 100;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 1 (works)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;t= r;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 2 (works)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;t = b;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//example 3 (not working – ending in hard fault handler)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;t= g; // error occurs here&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a = (int32_t) t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:19:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/problem-with-float-variable/m-p/540825#M7173</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: problem with float variable</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/problem-with-float-variable/m-p/540826#M7174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by Pacman on Tue Sep 09 20:53:39 MST 2014&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you find out what caused this ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The difference is most likely that the code was optimized, so that none of the assignments you made were actually in the final binary, since they were unused variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try building the code again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1: Which compiler do you use, GCC ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2: Try turning optimizing off: -O0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3: Try disassembling your code. For instance if using a GNU toolchain: objdump -D file.elf&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4: Try putting 'volatile" in front of all your local variables as well (yes, you can do that, and it will work - but it's only a good idea to do when making tests).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5: If using OpenOCD, you can halt the processor when it reaches the HardFault handler, then you can see the old value of PC and LR; they will point to the return-address, so you can disassemble using 'arm disassemble &amp;lt;address&amp;gt; &amp;lt;length&amp;gt;' and see where it failed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6: Did you build your libraries for the Cortex-M4 with soft floating point support ? -if not, the HardFault is probably on a 32-bit ARM instruction, which was generated in the hope that the microcontroller would be able to run it. ;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 23:19:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/problem-with-float-variable/m-p/540826#M7174</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T23:19:05Z</dc:date>
    </item>
  </channel>
</rss>

