<?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: KL25Z Freedom, PortC, and HardFault in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199347#M2811</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have seen cases where a dangling pointer was writing to the stack, and when the pcr register was restored, it had the T bit cleared, causing a hard fault at the next branch instruction.&lt;/P&gt;&lt;P&gt;It was helpful for me to write a small interrupt handler as described in &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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Dec 2012 04:36:25 GMT</pubDate>
    <dc:creator>BlackNight</dc:creator>
    <dc:date>2012-12-07T04:36:25Z</dc:date>
    <item>
      <title>KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199345#M2809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to configure Port C on the KL25Z on the Freedom board for GPIO and I get a hard fault/exception when I access PORTC-&amp;gt;PCR[0]. Ports A, B, and D don't (seem to) give any problems. I'm using Keil MicroVision 4. Would anyone have any information on what's going on? &lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 01:24:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199345#M2809</guid>
      <dc:creator>alexdean</dc:creator>
      <dc:date>2012-12-06T01:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199346#M2810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a little hard to tell what's going on based upon your description.&amp;nbsp; The ARM Cortex-M0+ Devices Generic User Guide (document DUI0662A) may shed some light, specifically section 2.4 "Fault handling":&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"&lt;SPAN style="color: #0000ff;"&gt;Faults are a subset of exceptions, see Exception model on page 2-16. All faults result in the HardFault exception being taken or cause Lockup if they occur in the NMI or HardFault handler.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;The faults are:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of an SVC instruction at a priority equal or higher than SVCall&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of a BKPT instruction without a debugger attached&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • a system-generated bus error on a load or store&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of an instruction from an XN memory address&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of an instruction from a location for which the system generates a bus fault&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • a system-generated bus error on a vector fetch&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of an Undefined instruction&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • execution of an instruction when not in Thumb-State as a result of the T-bit being previously cleared to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • an attempted load or store to an unaligned address&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;&amp;nbsp; • if the device implements the MPU, an MPU fault because of a privilege violation or an attempt to access an unmanaged region.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recently encountered a HardFault caused by a BLX instruction that was clearing the T-bit.&amp;nbsp; I didn't see anything wrong with my C source code.&amp;nbsp; I found the problem as I single-stepped through the resultant assembly language.&amp;nbsp; I found the cause in section 3.3.2 "Restrictions when using PC or SP" of the same manual:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"&lt;SPAN style="color: #0000ff;"&gt;When you update the PC with a BX, BLX, or POP instruction, bit[0] of any address must be 1 for &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;correct execution. This is because this bit indicates the destination instruction set, and the &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;Cortex-M0+ processor only supports Thumb instructions. When a BL or BLX instruction writes &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;the value of bit[0] into the LR it is automatically assigned the value 1.&lt;/SPAN&gt;&lt;SPAN class="mce_paste_marker"&gt;"&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my case, the destination address for the BLX instruction had its least significant bit cleared, i.e., bit[0] = 0.&amp;nbsp; Sure enough, when the BLX instruction executed I saw the T-bit clear in the Execution Program Status Register (EPSR).&amp;nbsp; As indicated above, this needs to change to bit[0] = 1 to stay in the the Thumb code state.&amp;nbsp; I fixed this by simply incrementing the destination address (which was a pointer variable) prior to the execution of the BLX instruction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if this applies to your particular scenario but I hope that it gives you an idea as to where to look.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Derrick&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 22:21:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199346#M2810</guid>
      <dc:creator>Derrick</dc:creator>
      <dc:date>2012-12-06T22:21:57Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199347#M2811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have seen cases where a dangling pointer was writing to the stack, and when the pcr register was restored, it had the T bit cleared, causing a hard fault at the next branch instruction.&lt;/P&gt;&lt;P&gt;It was helpful for me to write a small interrupt handler as described in &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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Dec 2012 04:36:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199347#M2811</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2012-12-07T04:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199348#M2812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the suggestions. It sounds like a job for ... MicroTraceBuffer-Man! I'll let you know who the villain turns out to be.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Dec 2012 12:00:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199348#M2812</guid>
      <dc:creator>alexdean</dc:creator>
      <dc:date>2012-12-08T12:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199349#M2813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Need to do this or setting PCR registers will generate a hard fault.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // 12.2.9 This enables the clock so you can pin route.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM_SCGC5 |= (SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTC_MASK |&amp;nbsp;&amp;nbsp; SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTE_MASK ); &lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 04:01:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199349#M2813</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2012-12-10T04:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199350#M2814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Jim. That did it!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 20 Dec 2012 23:30:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199350#M2814</guid>
      <dc:creator>alexdean</dc:creator>
      <dc:date>2012-12-20T23:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: KL25Z Freedom, PortC, and HardFault</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199351#M2815</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alex,&lt;/P&gt;&lt;P&gt;Please mark this as the answer so others will see this as solved and hopefully avoid the pain we went through to figure this out....&lt;/P&gt;&lt;P&gt;thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 23:31:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL25Z-Freedom-PortC-and-HardFault/m-p/199351#M2815</guid>
      <dc:creator>JimDon</dc:creator>
      <dc:date>2012-12-22T23:31:34Z</dc:date>
    </item>
  </channel>
</rss>

