<?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: LPC11U68 HardFault on pc-relative ldr in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759354#M30618</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found one fix by reducing the clock rate.&amp;nbsp; That led to a suggestion to increase the FLASHTIM value, as for anything over 40MHz the LPC11U68 needs 3 clocks instead of 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So anyone else who runs into this, and is running at the default of 48MHz:&lt;/P&gt;&lt;P&gt;Chip_FMC_SetFLASHAccess(FLASHTIM_3CLK_CPU);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fixed the problem for me, hopefully this will help someone else.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 16 Mar 2018 22:43:12 GMT</pubDate>
    <dc:creator>dfenger</dc:creator>
    <dc:date>2018-03-16T22:43:12Z</dc:date>
    <item>
      <title>LPC11U68 HardFault on pc-relative ldr</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759351#M30615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using MCUXpresso IDE to develop for the LPC11U68, currently using a&amp;nbsp;OM13058 LPCXpresso Board, Rev C2 as the development target.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I keep running into HardFaults when the compiler generates a "ldr r3, [pc, #20]" instruction at an address that's not a power of 4.&amp;nbsp; It seems to assume that the CPU will round down to the nearest power of 4, but that's not what I'm seeing in the debugger.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A representative dissasembly from USB_IRQHandler (taken directly from the usbd_rom_hid_generic project in LPCOpen for the LPC116x):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;71 if ( LPC_USB-&amp;gt;DEVCMDSTAT &amp;amp; USB_SETUP_RCVD ) { /* if setup packet is received */&lt;BR /&gt;00000452: ldr r3, [r3, #0]&lt;BR /&gt;00000454: lsls r3, r3, #23&lt;BR /&gt;00000456: bpl.n 0x460 &amp;lt;USB_IRQHandler+20&amp;gt;&lt;BR /&gt; 72 addr[2] &amp;amp;= ~BUF_ACTIVE; /* clear EP0_IN ACTIVE bit*/&lt;BR /&gt;00000458: ldr r3, [r2, #8]&lt;BR /&gt;0000045a: lsls r3, r3, #1&lt;BR /&gt;0000045c: lsrs r3, r3, #1&lt;BR /&gt;0000045e: str r3, [r2, #8]&lt;/P&gt;&lt;P&gt;74 USBD_API-&amp;gt;hw-&amp;gt;ISR(g_hUsb);&lt;BR /&gt;00000460: ldr r3, [pc, #16] ; (0x474 &amp;lt;USB_IRQHandler+40&amp;gt;)&lt;BR /&gt;00000462: ldr r2, [pc, #20] ; (0x478 &amp;lt;USB_IRQHandler+44&amp;gt;)&lt;BR /&gt;00000464: ldr r3, [r3, #0]&lt;BR /&gt;00000466: ldr r0, [r2, #0]&lt;BR /&gt;00000468: ldr r3, [r3, #0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;0x474 contains 0x10000320.&amp;nbsp; 0x478 contains 0x1000130.&amp;nbsp; So it all looks okay...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the instruction at 462 loads garbage into r2 (0x68db681b), which causes the instruction in 0x466 to HardFault.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hunting around for the 'random' data, I see it's living at 0x468.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried compiling the code with -mno-unaligned-access, but it doesn't seem to help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obviously, I'm doing something terribly wrong, because if this issue was common nobody would be able to run anything on the LPC11U68 at all.&amp;nbsp; Worse, some of the time, I can get some builds to run, but I have no idea why.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other cases I've seen make seems to be related to a branch instruction or other jump happening shortly before the ldr.&amp;nbsp; I've included some context to show where that would be the case, here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Mar 2018 18:03:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759351#M30615</guid>
      <dc:creator>dfenger</dc:creator>
      <dc:date>2018-03-14T18:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: LPC11U68 HardFault on pc-relative ldr</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759352#M30616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As a workaround, it seems that adding&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;asm volatile("dsb" : : : "memory");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;before the vulnerable instruction fixes the problem.&amp;nbsp; Possibly overkill, maybe just a nop is required... but adding a data synchronization barrier gets the PC back into a consistent state.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not my first choice of a fix, I'd prefer to have the compiler do this.&amp;nbsp; But at least it lets me move forward until I figure out how to make the compiler do it for me...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: Unfortunately, the above doesn't work.&amp;nbsp; It only worked because I'd set a breakpoint on the line to see if it had changed the disassembly notably. So shortly after a breakpoint, it works.&amp;nbsp; But I couldn't get any combo of synchronization barriers (or a bunch in a row) to clear up the issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Mar 2018 18:10:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759352#M30616</guid>
      <dc:creator>dfenger</dc:creator>
      <dc:date>2018-03-14T18:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: LPC11U68 HardFault on pc-relative ldr</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759353#M30617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did have a little more luck with asm volatile("cmp r3,r3;" : : : "memory");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is, it just pushes the issue into harder and harder to find places.&amp;nbsp; Ones where the spurious load doesn't HardFault immediately, but causes some kind of knock-on effect that end up crashing later.&amp;nbsp; (And it worries me that by being only 2 byes long, it might be 'fixing' the problem by pushing the offending load back to a divisible-by-4 address.)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Mar 2018 20:58:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759353#M30617</guid>
      <dc:creator>dfenger</dc:creator>
      <dc:date>2018-03-15T20:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: LPC11U68 HardFault on pc-relative ldr</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759354#M30618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I found one fix by reducing the clock rate.&amp;nbsp; That led to a suggestion to increase the FLASHTIM value, as for anything over 40MHz the LPC11U68 needs 3 clocks instead of 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So anyone else who runs into this, and is running at the default of 48MHz:&lt;/P&gt;&lt;P&gt;Chip_FMC_SetFLASHAccess(FLASHTIM_3CLK_CPU);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fixed the problem for me, hopefully this will help someone else.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Mar 2018 22:43:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC11U68-HardFault-on-pc-relative-ldr/m-p/759354#M30618</guid>
      <dc:creator>dfenger</dc:creator>
      <dc:date>2018-03-16T22:43:12Z</dc:date>
    </item>
  </channel>
</rss>

