<?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: Debugging Hard Fault in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535468#M11004</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by martinmckee on Thu Dec 27 11:51:12 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Spot on.&amp;nbsp; I was actually planning to make sure that the manager always returned aligned structs ( I had some of the framework in place in fact ) but everything had been working so well... Anyway, I did the last little bit of work to ensure aligned allocations and everything is working just as it should.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got side tracked by the fact that it had been working correctly before ( stupid really ).&amp;nbsp; The addition of the new version of the call caused more data to be allocated which, of course, shifted things to a non-aligned boundary.&amp;nbsp; Glad it's working again -- and glad that I've managed to learn ( or, rather, be reminded of ) something useful... pay attention to alignment!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin Jay McKee&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 19:38:02 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T19:38:02Z</dc:date>
    <item>
      <title>Debugging Hard Fault</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535466#M11002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by martinmckee on Wed Dec 26 23:35:30 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Okay, full disclosure, I'm quite new to 32-bit microcontrollers in general ( used to AVR 8-bit ) and to ARM Cortex-M0 in particular.&amp;nbsp; One thing that means is that I have not had to deal with exceptions ( or faults ) before.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The issue I'm having is that I have some code that implements a cooperative task handling API.&amp;nbsp; Everything was going fine until I added another, more complicated, version of a function.&amp;nbsp; The two earlier versions I implemented worked just fine.&amp;nbsp; Calling the third seems to trigger a Hard Fault.&amp;nbsp; But, here's the bit I don't understand.&amp;nbsp; The Hard Fault is triggered within a function that I am calling that does the bulk of the work.&amp;nbsp; This function is identical for all three implementations, it simply takes different parameters ( created by the calling functions ).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The struct being operated upon is declared as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;typedef struct COOP_TASK {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// Control Members&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bool enabled;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;coop_task_priority_t priority;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;uint8_t id;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// Event Members&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;coop_event_function_t event;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void * event_data;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;coop_size_t event_data_size;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// Task Implementation Members&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;coop_task_function_t func;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void * task_data;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;coop_size_t task_data_size;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;// Task List&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;//&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;struct COOP_TASK * next_task;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;} coop_task_t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the code that triggers the Fault looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;enabled = true;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;priority = _priority;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;id = tasker_system.next_id;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;event_data = _event_data; // This line triggers it...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;event = _event;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;func = _func;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;task_data = _task_data;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;task-&amp;gt;next_task = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The task memory is allocated by a pool manager which seems to be working just fine.&amp;nbsp; When I step through and trap the instruction that actually causes the fault it ends up being:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;str r2, [ r3, #8 ]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Where r3 correctly holds the base address of the structure( 0x100002b ) and the computed offset access address is ( 0x1000033 ).&amp;nbsp; Obviously there is an unaligned access happening, but the question is, why?&amp;nbsp; This is all code generated by the compiler that is acting up, and the other two calls to the function are working just fine ( alone or with this last version of the call ). For what it's worth, this all happens the same way ( with the same addresses ) with or without optimization ( O0, O2, or Os ).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm out of ideas.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin Jay McKee&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:38:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535466#M11002</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging Hard Fault</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535467#M11003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by wmues on Thu Dec 27 09:18:23 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Your pool manager should only allocate task structs that are aligned at int boundaries.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you post the code of the pool manager, we might be able to help you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:38:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535467#M11003</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Debugging Hard Fault</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535468#M11004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by martinmckee on Thu Dec 27 11:51:12 MST 2012&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Spot on.&amp;nbsp; I was actually planning to make sure that the manager always returned aligned structs ( I had some of the framework in place in fact ) but everything had been working so well... Anyway, I did the last little bit of work to ensure aligned allocations and everything is working just as it should.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got side tracked by the fact that it had been working correctly before ( stupid really ).&amp;nbsp; The addition of the new version of the call caused more data to be allocated which, of course, shifted things to a non-aligned boundary.&amp;nbsp; Glad it's working again -- and glad that I've managed to learn ( or, rather, be reminded of ) something useful... pay attention to alignment!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin Jay McKee&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 19:38:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Debugging-Hard-Fault/m-p/535468#M11004</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T19:38:02Z</dc:date>
    </item>
  </channel>
</rss>

