<?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 Re: Tracking down Hard Faults in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265173#M8484</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An there is this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/message/315205"&gt;Re: KL25 Freedom Board HardFaults, un-used interrupts and finding out&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Apr 2013 20:21:08 GMT</pubDate>
    <dc:creator>JimDon</dc:creator>
    <dc:date>2013-04-12T20:21:08Z</dc:date>
    <item>
      <title>Tracking down Hard Faults</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265172#M8483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hard faults can be a pain to track down, especially if they are intermittent and don't happen consistently in the same location. A Hard Fault is an ARM Cortex exception, and the ARM M0 Generic User Guide lists the following sources for a hard fault:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Faults are a subset of exceptions, see Exception model on page 2-19. All faults result in&lt;/P&gt;&lt;P&gt;the HardFault exception being taken or cause lockup if they occur in the NMI or&lt;/P&gt;&lt;P&gt;HardFault handler. The faults are:&lt;/P&gt;&lt;UL&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of an SVC instruction at a priority equal or higher than SVCall&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of a BKPT instruction without a debugger attached&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;a system-generated bus error on a load or store&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of an instruction from an XN memory address&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of an instruction from a location for which the system generates a bus&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;fault&lt;/P&gt;&lt;UL&gt;&lt;LI type="ul"&gt;&lt;P&gt;a system-generated bus error on a vector fetch&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of an Undefined instruction&lt;/P&gt;&lt;/LI&gt;&lt;LI type="ul"&gt;&lt;P&gt;execution of an instruction when not in Thumb-State as a result of the T-bit being&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;previously cleared to 0&lt;/P&gt;&lt;UL&gt;&lt;LI type="ul"&gt;&lt;P&gt;an attempted load or store to an unaligned address.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I find usually a hard fault is caused by a bus error or unaligned address. Bus errors in Kinetis are usually accessing an invalid address (usually from a bad pointer), or accessing a peripheral register before the clock gate is enabled. In either case, the bus stalls out with no response, triggering a hard fault.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Debugging hard faults is a common issue in ARM cores, and if you Google the issue, you will find several guides and tips available for help finding the root cause of the hard fault, including this appnote below from Keil, although it is targeted at M3 and M4 cores:&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.keil.com%2Fappnotes%2Ffiles%2Fapnt209.pdf" rel="nofollow" target="_blank"&gt;http://www.keil.com/appnotes/files/apnt209.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IAR also has a macro to help with their debugger.&amp;nbsp; Here's more details, with some tips for diagnosing hard faults:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://www.iar.com/support/tech-notes/debugger/debugging-a-hardfault-on-cortex-m/" title="https://www.iar.com/support/tech-notes/debugger/debugging-a-hardfault-on-cortex-m/"&gt;IAR Debugging a HardFault on Cortex-M&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From NXP, our software expert Erich has a blog site, where he has posted some good information on tracking down hard faults. This link describes a hard fault handler he implemented to find the PC location of where the hard fault occurred:&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fmcuoneclipse.com%2F2012%2F11%2F24%2Fdebugging-hard-faults-on-arm-cortex-m%2F" rel="nofollow" target="_blank"&gt;http://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;He also has a post on automating the GDB debugger to run a script with the hard fault details, which can be used within the Kinetis Design Studio (KDS) IDE:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://mcuoneclipse.com/2015/07/05/debugging-arm-cortex-m-hard-faults-with-gdb-custom-command/" title="https://mcuoneclipse.com/2015/07/05/debugging-arm-cortex-m-hard-faults-with-gdb-custom-command/"&gt;Debugging ARM Cortex-M Hard Faults with GDB Custom Command | MCU on Eclipse&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then he discusses how to use the Micro Trace Buffer in the M0+ core to get more visibility in the execution history leading up to the hard fault&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fmcuoneclipse.com%2F2013%2F01%2F13%2Fdebugging-arm-cortex-m0-hard-fault-with-mtb-trace%2F" rel="nofollow" target="_blank"&gt;http://mcuoneclipse.com/2013/01/13/debugging-arm-cortex-m0-hard-fault-with-mtb-trace/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For legacy users using Processor Expert, he even wrapped his handler in a Processor Expert component&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fmcuoneclipse.com%2F2012%2F12%2F28%2Fa-processor-expert-component-to-help-with-hard-faults%2F" rel="nofollow" target="_blank"&gt;http://mcuoneclipse.com/2012/12/28/a-processor-expert-component-to-help-with-hard-faults/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 19:01:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265172#M8483</guid>
      <dc:creator>dereksnell</dc:creator>
      <dc:date>2013-04-12T19:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Tracking down Hard Faults</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265173#M8484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An there is this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/message/315205"&gt;Re: KL25 Freedom Board HardFaults, un-used interrupts and finding out&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Apr 2013 20:21:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265173#M8484</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2013-04-12T20:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: Tracking down Hard Faults</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265174#M8485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am attempting to recreate the solution from the &lt;A href="http://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/" title="http://mcuoneclipse.com/2012/11/24/debugging-hard-faults-on-arm-cortex-m/"&gt;Debugging Hard Faults on ARM Cortex-M | MCU on Eclipse&lt;/A&gt; link.&amp;nbsp; I get "illegal operand" errors for the assembly code.&amp;nbsp; What do I need to do to be able to compile this for a Kinetis K60 using Codewarrior 10.5?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also attempted to use the PE component from the next link and get a&amp;nbsp; "&lt;SPAN style="text-decoration: underline;"&gt;Freescale&lt;/SPAN&gt; ARM/&lt;SPAN style="text-decoration: underline;"&gt;Kinetis&lt;/SPAN&gt; compiler is NOT supported! Only ARM &lt;SPAN style="text-decoration: underline;"&gt;gcc&lt;/SPAN&gt; is supported." error.&amp;nbsp; How can this error be corrected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would greatly appreciate any help that you can provide.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 23:27:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265174#M8485</guid>
      <dc:creator>bruced</dc:creator>
      <dc:date>2013-10-21T23:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Tracking down Hard Faults</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265175#M8486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bruce,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you found, the example code provided from Erich on his blog is for the GCC compiler.&amp;nbsp; But I used the code below and was able to build it fine with the Freescale compiler in CodeWarrior v10.5:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="c++" __jive_macro_name="code" class="jive_text_macro _jivemacro_uid_13824779530979120 jive_macro_code" jivemacro_uid="_13824779530979120" modifiedtitle="true"&gt;
&lt;P&gt;asm(&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " movs r0,#4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " movs r1, lr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " tst r0, r1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " beq _MSP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " mrs r0, psp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " b _HALT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; "_MSP:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " mrs r0, msp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; "_HALT:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " ldr r1,[r0,#20]&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " bkpt #0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n"&lt;/P&gt;
&lt;P&gt;);&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Oct 2013 21:40:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265175#M8486</guid>
      <dc:creator>dereksnell</dc:creator>
      <dc:date>2013-10-22T21:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Tracking down Hard Faults</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265176#M8487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The latest version of the HardFault Processor Expert component works with Keil, IAR, GCC and (legacy) Freescale ARM compiler. Attached is the component.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Oct 2013 09:06:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Tracking-down-Hard-Faults/m-p/265176#M8487</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2013-10-23T09:06:02Z</dc:date>
    </item>
  </channel>
</rss>

