<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>HardFault only from bootloader</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/29703/hardfault-only-from-bootloader</link><description> 
Hello, 

 
I have am issue where my main application runs fine when I start
it directly from the uVision IDE but when it is &amp;#39;jumped&amp;#39; to from my
bootloader I get a HardFault. 

 
The only info on the hardfault is that it is &amp;quot;Forced&amp;quot; all other
fault registers</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/147743?ContentTypeID=1</link><pubDate>Fri, 28 Oct 2011 08:16:01 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a851a12c-a378-4c1c-ac6a-a52c11c54d1a</guid><dc:creator>@Marc Crandall</dc:creator><description>&lt;p&gt;&lt;p&gt;
I tried that first but the pending bits in the NVIC still seemed
to cause an issue when the C library was initializing.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/146771?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2011 23:08:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d04ea366-c9e7-4d20-b475-c5dbdf8ca1fa</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Of stop the interrupt source, of course.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/145209?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2011 21:45:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4abc6780-5817-4794-88fb-645c019919e9</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think it would be enough to switch to privileged mode via a SVC
and to call &amp;quot;__disable_irq()&amp;quot; before the jump.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/143042?ContentTypeID=1</link><pubDate>Thu, 27 Oct 2011 12:10:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:048d1540-111f-4535-ac64-caa0718b3c5c</guid><dc:creator>@Marc Crandall</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello,&lt;/p&gt;

&lt;p&gt;
In case someone else encounters this issue I found my problem.&lt;/p&gt;

&lt;p&gt;
It had to do with pending interrupts when I jumped to the main
application. These caused faults as the system had not been
initialized.&lt;/p&gt;

&lt;p&gt;
I change my boot_jump to the following:&lt;/p&gt;

&lt;pre&gt;
void NVIC_DeInit(void)
{
    uint8_t tmp;

    /* Disable all interrupts */
    NVIC-&amp;gt;ICER[0] = 0xFFFFFFFF;
    NVIC-&amp;gt;ICER[1] = 0x00000001;
    /* Clear all pending interrupts */
    NVIC-&amp;gt;ICPR[0] = 0xFFFFFFFF;
    NVIC-&amp;gt;ICPR[1] = 0x00000001;

    /* Clear all interrupt priority */
    for (tmp = 0; tmp &amp;lt; 32; tmp++) {
        NVIC-&amp;gt;IP[tmp] = 0x00;
    }
}

void NVIC_SCBDeInit(void)
{
    uint8_t tmp;

    SCB-&amp;gt;ICSR = 0x0A000000;
    SCB-&amp;gt;VTOR = 0x00000000;
    SCB-&amp;gt;AIRCR = 0x05FA0000;
    SCB-&amp;gt;SCR = 0x00000000;
    SCB-&amp;gt;CCR = 0x00000000;

    for (tmp = 0; tmp &amp;lt; 32; tmp++) {
        SCB-&amp;gt;SHP[tmp] = 0x00;
    }

    SCB-&amp;gt;SHCSR = 0x00000000;
    SCB-&amp;gt;CFSR = 0xFFFFFFFF;
    SCB-&amp;gt;HFSR = 0xFFFFFFFF;
    SCB-&amp;gt;DFSR = 0xFFFFFFFF;
}

void NVIC_SetVTOR(uint32_t offset)
{
    //SCB-&amp;gt;VTOR  = (offset &amp;amp; NVIC_VTOR_MASK);
    SCB-&amp;gt;VTOR  = offset;
}


__asm void boot_jump( uint32_t address )
{
   LDR SP, [R0]         ;Load new stack pointer address
   LDR PC, [R0, #4]     ;Load new program counter address
}

void execute_user_code(void)
{

    NVIC_DeInit();
    NVIC_SCBDeInit();
    NVIC_SetVTOR(USER_FLASH_START);
    boot_jump(USER_FLASH_START);
}

&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/140090?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:44:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4cf2890a-1f45-4694-a333-1e60b00b91eb</guid><dc:creator>@Marc Crandall</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thank you Tamir.&lt;/p&gt;

&lt;p&gt;
I may have to do this, it will be a long an tedious process.&lt;/p&gt;

&lt;p&gt;
M&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/136643?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:41:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5c3e20fb-1138-4fe4-8929-f4ecc9415f29</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t know. Why don&amp;#39;t either show them, or remove them all and
add one by one until a failure occurs...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/127167?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:22:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:da3dec0a-f2df-47ab-b2af-d5ed0f63c23d</guid><dc:creator>@Marc Crandall</dc:creator><description>&lt;p&gt;&lt;p&gt;
If I use a really simple main application it does not fail. In
other words&lt;br /&gt;
if the main app looks like:&lt;/p&gt;

&lt;pre&gt;
int main()
{

   printf(&amp;quot;test&amp;quot;);
   while(1);
}
&lt;/pre&gt;

&lt;p&gt;
The boot loader correctly jumps to this app.&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m not sure what that means. What settings in my &amp;#39;real&amp;#39; app could
cause a fault in the C library initialization?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/119523?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:16:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:736945af-f80a-473d-9b67-8b00ff8ed22e</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Does it also fail if you empty the application entirely?&lt;br /&gt;
Are you sure the application does not set the CRP flag? That can
cause problems, though not likely the one you have.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/105414?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:13:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1f13081c-d863-4276-a585-3398b5b77d4a</guid><dc:creator>@Marc Crandall</dc:creator><description>&lt;p&gt;&lt;p&gt;
My application starts at 0x4000.&lt;/p&gt;

&lt;p&gt;
I don&amp;#39;t think the jump address is the problem because the SysInit
function of the main app gets executed.&lt;/p&gt;

&lt;p&gt;
The HardFault happens in the __main somewhere?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/91280?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:10:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:078e049e-c970-4a5a-9c63-2e68e92a3112</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Where does your application start?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: HardFault only from bootloader</title><link>https://community.arm.com/thread/59989?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2011 08:09:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2e380dde-668c-4189-a7f4-9026558a22ff</guid><dc:creator>Tamiryan Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think you need to jump to an uneven address:&lt;/p&gt;

&lt;pre&gt;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, MAIN_BOOT_START_SECTOR);
&lt;/pre&gt;

&lt;p&gt;
where&lt;/p&gt;

&lt;pre&gt;
void NVIC_SetVectorTable(DWORD NVIC_VectTab, DWORD Offset)
{
    NVIC_VECT_TABLE = NVIC_VectTab | (Offset &amp;amp; 0x1FFFFF80);
}
&lt;/pre&gt;

&lt;p&gt;
and&lt;/p&gt;

&lt;pre&gt;
#define MAIN_BOOT_START_SECTOR  1
&lt;/pre&gt;

&lt;p&gt;
I hope this helps...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>