<?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: KL82: Can't jump to application from custom bootloader in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231700#M59646</link>
    <description>&lt;P&gt;I figured I was missing the offset of 4 for calling the app.&lt;/P&gt;&lt;P&gt;static void (*go_to_app)(void) = 0;&lt;BR /&gt;go_to_app = (void (*)(void))(START_OF_APPLICATION+4);&lt;BR /&gt;SCB-&amp;gt;VTOR = START_OF_APPLICATION;&lt;BR /&gt;__set_MSP(START_OF_APPLICATION);&lt;BR /&gt;__set_PSP(START_OF_APPLICATION);&lt;BR /&gt;__DSB();&lt;BR /&gt;go_to_app();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One issue is remaining, the application directly hard faults on execution. If I issue an reset from my debugging tool (SEGGER Ozone) it will start the application.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Feb 2021 19:31:21 GMT</pubDate>
    <dc:creator>marcwillem</dc:creator>
    <dc:date>2021-02-16T19:31:21Z</dc:date>
    <item>
      <title>KL82: Can't jump to application from custom bootloader</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231563#M59640</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I needed to implement a custom bootloader, as I am using a MCP2515 CAN Transceiver for flashing.&lt;/P&gt;&lt;P&gt;I can program the device without issue (verified by readback and MCUxpresso Memory Watcher).&lt;BR /&gt;When I jump to the application, I get a hardfault (unknown hard fault at 0x2900B289).&lt;/P&gt;&lt;P&gt;I can see the PC jumping to the application (0x0001 0000), but then it get's stuck somewhere.&lt;BR /&gt;The program is fairly simple but jumps to the hard fault handler immediately after the jump;&lt;/P&gt;&lt;P&gt;If I reset the program via SWD I get another hard fault, this time the PC is at 0F64, which is in my bootloader;&lt;/P&gt;&lt;P&gt;I configured the app in MCUxpresso for the flash to start at 0x00010000 (at C/C++ Build / MCU settings) and enabled position independent code.&lt;/P&gt;&lt;P&gt;This is the code of my application;&lt;/P&gt;&lt;P&gt;uint8_t i=0;&lt;BR /&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt;while (1) i++;&lt;BR /&gt;return 0 ;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I jump to the application&lt;BR /&gt;&lt;BR /&gt;#define START_OF_APPLICATION 0x00010000ul&lt;BR /&gt;static void (*go_to_app)(void) = 0;&lt;BR /&gt;go_to_app = (void (*)(void))(START_OF_APPLICATION);&lt;BR /&gt;SCB-&amp;gt;VTOR = START_OF_APPLICATION;&lt;BR /&gt;__set_MSP(START_OF_APPLICATION);&lt;BR /&gt;__set_PSP(START_OF_APPLICATION);&lt;BR /&gt;go_to_app();&lt;BR /&gt;&lt;BR /&gt;Did I forget anything?&lt;BR /&gt;Do you know why I get the hard fault or how I could debug it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 13:23:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231563#M59640</guid>
      <dc:creator>marcwillem</dc:creator>
      <dc:date>2021-02-16T13:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: KL82: Can't jump to application from custom bootloader</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231700#M59646</link>
      <description>&lt;P&gt;I figured I was missing the offset of 4 for calling the app.&lt;/P&gt;&lt;P&gt;static void (*go_to_app)(void) = 0;&lt;BR /&gt;go_to_app = (void (*)(void))(START_OF_APPLICATION+4);&lt;BR /&gt;SCB-&amp;gt;VTOR = START_OF_APPLICATION;&lt;BR /&gt;__set_MSP(START_OF_APPLICATION);&lt;BR /&gt;__set_PSP(START_OF_APPLICATION);&lt;BR /&gt;__DSB();&lt;BR /&gt;go_to_app();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One issue is remaining, the application directly hard faults on execution. If I issue an reset from my debugging tool (SEGGER Ozone) it will start the application.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 19:31:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231700#M59646</guid>
      <dc:creator>marcwillem</dc:creator>
      <dc:date>2021-02-16T19:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: KL82: Can't jump to application from custom bootloader</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231709#M59647</link>
      <description>&lt;P&gt;I found the solution here:&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/58296733/cortex-m0-jump-to-user-application-failing" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/58296733/cortex-m0-jump-to-user-application-failing&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-meta"&gt;#&lt;SPAN class="hljs-meta-keyword"&gt;define&lt;/SPAN&gt; PROGRAM_VECTOR_TABLE ((uint32_t *) PROGRAM_ADDRESS)&lt;/SPAN&gt;

&lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;void&lt;/SPAN&gt; &lt;SPAN class="hljs-title"&gt;jump_to_app&lt;/SPAN&gt;&lt;SPAN class="hljs-params"&gt;(&lt;SPAN class="hljs-keyword"&gt;void&lt;/SPAN&gt;)&lt;/SPAN&gt;
&lt;/SPAN&gt;{
    &lt;SPAN class="hljs-function"&gt;&lt;SPAN class="hljs-keyword"&gt;static&lt;/SPAN&gt; &lt;SPAN class="hljs-title"&gt;void&lt;/SPAN&gt; &lt;SPAN class="hljs-params"&gt;(*go_to_app)&lt;/SPAN&gt;&lt;SPAN class="hljs-params"&gt;(&lt;SPAN class="hljs-keyword"&gt;void&lt;/SPAN&gt;)&lt;/SPAN&gt; &lt;/SPAN&gt;= &lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;;
    go_to_app = (&lt;SPAN class="hljs-keyword"&gt;void&lt;/SPAN&gt; (*)(&lt;SPAN class="hljs-keyword"&gt;void&lt;/SPAN&gt;))(PROGRAM_VECTOR_TABLE[&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;]);
    SCB-&amp;gt;VTOR = (&lt;SPAN class="hljs-keyword"&gt;uint32_t&lt;/SPAN&gt;)PROGRAM_VECTOR_TABLE;
    __set_MSP(PROGRAM_VECTOR_TABLE[&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;]);
    __set_PSP(PROGRAM_VECTOR_TABLE[&lt;SPAN class="hljs-number"&gt;0&lt;/SPAN&gt;]);
    go_to_app();
}
&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Feb 2021 20:20:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/KL82-Can-t-jump-to-application-from-custom-bootloader/m-p/1231709#M59647</guid>
      <dc:creator>marcwillem</dc:creator>
      <dc:date>2021-02-16T20:20:44Z</dc:date>
    </item>
  </channel>
</rss>

