<?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: KL25 Freedom Board HardFaults, un-used interrupts and finding out in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25-Freedom-Board-HardFaults-un-used-interrupts-and-finding-out/m-p/253849#M7364</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jim,&lt;/P&gt;&lt;P&gt;thanks for sharing!&lt;/P&gt;&lt;P&gt;On the same topic, and as well for Processor Expert:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&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;&lt;/LI&gt;&lt;LI&gt;&lt;A href="http://mcuoneclipse.com/2012/12/28/a-processor-expert-component-to-help-with-hard-faults/" title="http://mcuoneclipse.com/2012/12/28/a-processor-expert-component-to-help-with-hard-faults/"&gt;A Processor Expert Component to Help with Hard Faults | MCU on Eclipse&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 09 Feb 2013 06:47:12 GMT</pubDate>
    <dc:creator>BlackNight</dc:creator>
    <dc:date>2013-02-09T06:47:12Z</dc:date>
    <item>
      <title>KL25 Freedom Board HardFaults, un-used interrupts and finding out</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25-Freedom-Board-HardFaults-un-used-interrupts-and-finding-out/m-p/253848#M7363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have seen a number of questions concerning these matters and have had these issues myself, so I came up with some handy code for bare board projects.&lt;/P&gt;&lt;P&gt;This code replaces the Default_Handler in kinetis_sysinit.c. There is probably a slicker way to do this,&amp;nbsp; but this is how I did it. All improvements welcome.&lt;/P&gt;&lt;P&gt;It also illustrates how to suppress a warning in GCC.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
/*
 *&amp;nbsp; Default_Handler_Helper
 * Stack contains:
 * R0, R1, R2, R3, R12, R14, the pc and xPSR
 *&amp;nbsp; 
 *&amp;nbsp; vIPSR is the interrupt number.
 */ 
void Default_Handler_Helper(uint32_t * svc_args,uint32_t vIPSR)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // The pc might trace back to the instruction on a hardfault.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // If you jumped to data, it might not.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; volatile uint32_t pc = ((uint32_t)svc_args[6]);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; __asm("bkpt");

}
#pragma GCC diagnostic pop
/*
 * Default_Handler() Replacement.
 * naked means no "C" prologue or epilogue.
 * Set up the SP and IPSR registers as function parameters.
 */
void __attribute__ ((naked)) Default_Handler()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; asm volatile (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "MRS R0, MSP\n"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Pass the SP in as the first "C" argument.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "MRS R1, IPSR\n"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Pass in IPSR as the second "C" argument.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "B Default_Handler_Helper\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );
}

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To test it:&lt;/P&gt;&lt;PRE&gt;&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; *((char *) main) = 0;&amp;nbsp; // Cause a hard fault by writing to Flash.
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you get to the break point in the Default_Handler_Helper function, take the value of the PC, go to the Debugger Shell, type "bp &amp;lt;the value of pc&amp;gt;" and then click on the break point in the break point window to see the line of code causing the hard fault. (there is probably a better way to do this, but this how I did it).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next, to test un-handled interrupts:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp; SCB_ICSR |= SCB_ICSR_PENDSVSET_MASK;&amp;nbsp; // Cause a PendSV interrupt.
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you get to the break point in the help function, vIPSR will be 14, the interrupt number of the PendSV interrupt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or cause an NMI:&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SCB_ICSR |= SCB_ICSR_NMIPENDSET_MASK;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you get into the Default_Handler_Helper you are done. The program will not continue, but at least now you know....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 02:40:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25-Freedom-Board-HardFaults-un-used-interrupts-and-finding-out/m-p/253848#M7363</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2013-02-09T02:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: KL25 Freedom Board HardFaults, un-used interrupts and finding out</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25-Freedom-Board-HardFaults-un-used-interrupts-and-finding-out/m-p/253849#M7364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jim,&lt;/P&gt;&lt;P&gt;thanks for sharing!&lt;/P&gt;&lt;P&gt;On the same topic, and as well for Processor Expert:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&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;&lt;/LI&gt;&lt;LI&gt;&lt;A href="http://mcuoneclipse.com/2012/12/28/a-processor-expert-component-to-help-with-hard-faults/" title="http://mcuoneclipse.com/2012/12/28/a-processor-expert-component-to-help-with-hard-faults/"&gt;A Processor Expert Component to Help with Hard Faults | MCU on Eclipse&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 09 Feb 2013 06:47:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25-Freedom-Board-HardFaults-un-used-interrupts-and-finding-out/m-p/253849#M7364</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2013-02-09T06:47:12Z</dc:date>
    </item>
  </channel>
</rss>

