<?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>LPC MicrocontrollersのトピックRe: LPC546xx Hardfault handling in the bootloader</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038558#M40416</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But after system reset, I won't be able to capture the HardFault information&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Dec 2019 18:11:29 GMT</pubDate>
    <dc:creator>terence_kong</dc:creator>
    <dc:date>2019-12-13T18:11:29Z</dc:date>
    <item>
      <title>LPC546xx Hardfault handling in the bootloader</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038556#M40414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi NXP,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to implement hardfault handling in the boot loader only.&lt;/P&gt;&lt;P&gt;I have a boot loader which will execute the main application after boot, and I want to implement the hardFault_Handler only in the boot loader.&amp;nbsp; So when there is a hardfault error happened in the main application, it will jump to the boot loader and execute the HardFault_Handler in the boot loader.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when there is a hardfault happened in the main application, seems the program will be stuck in the main application and can never jump to the boot loader.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the HardFault Handler I put in the boot loader, it works fine if I put it in both the boot loader and main application.&lt;/P&gt;&lt;P&gt;It doesn't work if I replace the main application HardFault Handler with a function jump.&lt;/P&gt;&lt;P&gt;Does the boot loader and the main application have to have their own hardfault handler??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void HardFault_Handler(void)&lt;BR /&gt;{&lt;BR /&gt;#if(0)&lt;BR /&gt; __asm volatile&lt;BR /&gt; (&lt;BR /&gt; " tst lr, #4 \n"&lt;BR /&gt; " ite eq \n"&lt;BR /&gt; " mrseq r0, msp \n"&lt;BR /&gt; " mrsne r0, psp \n"&lt;BR /&gt; //Load the instruction that triggered had fault&lt;BR /&gt; " ldr r1, [r0, #24] \n"&lt;BR /&gt; " ldr r2, handler2_address_const \n"&lt;BR /&gt; " bx r2 \n"&lt;BR /&gt; " handler2_address_const: .word prvGetRegistersFromStack \n"&lt;BR /&gt; );&lt;BR /&gt;#endif&lt;BR /&gt; __asm( ".syntax unified\n"&lt;BR /&gt; // Check which stack is in use&lt;BR /&gt; "MOVS R0, #4 \n"&lt;BR /&gt; "MOV R1, LR \n"&lt;BR /&gt; "TST R0, R1 \n"&lt;BR /&gt; "BEQ _MSP \n"&lt;BR /&gt; "MRS R0, PSP \n"&lt;BR /&gt; "B _process \n"&lt;BR /&gt; "_MSP: \n"&lt;BR /&gt; "MRS R0, MSP \n"&lt;BR /&gt; // Load the instruction that triggered hard fault&lt;BR /&gt; "_process: \n"&lt;BR /&gt; "LDR R1,[R0,#24] \n"&lt;BR /&gt; "LDRH R2,[r1] \n"&lt;BR /&gt; // Semihosting instruction is "BKPT 0xAB" (0xBEAB)&lt;BR /&gt; "LDR R3,=0xBEAB \n"&lt;BR /&gt; "CMP R2,R3 \n"&lt;BR /&gt; "BEQ _semihost_return \n"&lt;BR /&gt; // Wasn't semihosting instruction so enter registers dump&lt;BR /&gt; //"B . \n" //enter inifinte loop&lt;BR /&gt; " ldr r2, handler2_address_const \n"&lt;BR /&gt; " bx r2 \n"&lt;BR /&gt; " handler2_address_const: .word prvGetRegistersFromStack \n"&lt;BR /&gt; // Was semihosting instruction, so adjust location to&lt;BR /&gt; // return to by 1 instruction (2 bytes), then exit function&lt;BR /&gt; "_semihost_return: \n"&lt;BR /&gt; "ADDS R1,#2 \n"&lt;BR /&gt; "STR R1,[R0,#24] \n"&lt;BR /&gt; // Set a return value from semihosting operation.&lt;BR /&gt; // 32 is slightly arbitrary, but appears to allow most&lt;BR /&gt; // C Library IO functions sitting on top of semihosting to&lt;BR /&gt; // continue to operate to some degree&lt;BR /&gt; "MOVS R1,#32 \n"&lt;BR /&gt; "STR R1,[ R0,#0 ] \n" // R0 is at location 0 on stack&lt;BR /&gt; // Return from hard fault handler to application&lt;BR /&gt; "BX LR \n"&lt;BR /&gt; ".syntax divided\n") ;&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Dec 2019 21:29:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038556#M40414</guid>
      <dc:creator>terence_kong</dc:creator>
      <dc:date>2019-12-12T21:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: LPC546xx Hardfault handling in the bootloader</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038557#M40415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Terence,&lt;/P&gt;&lt;P&gt;I think the HardFault is a general exception, you can run code in the ISR.&lt;/P&gt;&lt;P&gt;I see that you want to execute the bootloader code once&amp;nbsp; the hardfault exception heppens, in the case, I suggest you reset the system by using the NVIC_SystemReset() function in CMSIS, which can set the SYSRESETREQ bit in NVIC-&amp;gt;AIRCR register.&lt;/P&gt;&lt;P&gt;BTW, you can enable watchdog in the main() function, but in the void HardFault_Handler(void), do not feed the watchdog by disabling the Timer which feeds dog. In this way, the watchdog Reset will happen.&lt;/P&gt;&lt;P&gt;Hope it can help you&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;XiangJun Rong&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Dec 2019 05:37:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038557#M40415</guid>
      <dc:creator>xiangjun_rong</dc:creator>
      <dc:date>2019-12-13T05:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: LPC546xx Hardfault handling in the bootloader</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038558#M40416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But after system reset, I won't be able to capture the HardFault information&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Dec 2019 18:11:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC546xx-Hardfault-handling-in-the-bootloader/m-p/1038558#M40416</guid>
      <dc:creator>terence_kong</dc:creator>
      <dc:date>2019-12-13T18:11:29Z</dc:date>
    </item>
  </channel>
</rss>

