Secondary bootloader error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Secondary bootloader error

1,188 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by michaelleekun on Thu Sep 03 13:51:06 MST 2015
I am using a LPCXpresso54102 board (cortex M4 only now) and I am trying to upgrade the user application with the secondary bootloader. It will copy the new binary to the "Sector 1 (0x00008000)" which was downloaded by the old user application to the other sector of flash area.

- Seconday bootloader runs at Sector 0 (0x00000000)

#include "board.h"

typedef void (*USER_ENTRY_PFN)();
#define SBL_SLV_FIRMWARE_START(0x8000)

int main(void)
{
    USER_ENTRY_PFN user_entry;
    user_entry = (USER_ENTRY_PFN)*((uint32_t*)(SBL_SLV_FIRMWARE_START +4));

    /* Generic Initialization */
    Board_Init(); 
    Board_LED_Set(0, TRUE);

    __disable_irq(); 
   SCB->VTOR = SBL_SLV_FIRMWARE_START;
    __enable_irq();

    __set_MSP(SCB->VTOR);//load stackpointer with initial value
    (user_entry)(); 

    /* Loop forever */
while (1) {
__WFI();}

    return 0;
}


I have compiled (using LPCXpresso) the user application changing the start address to 0x8000. This one is working fine with the "AN11610: LPC5410x I2C SPI Secondary Bootloader" which means it should work if my Secondary Bootloader (above codes) is fine. 

But if I run the Secondary Bootloader code, this one does not jump to the user application. The "user_entry" is set to "0x81FD" and the debugger stops working. I am not sure but I am missing something here.

Thank you in advance.
Labels (1)
0 Kudos
5 Replies

882 Views
jpadilla
Community Manager

bump

0 Kudos

882 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cptnproton on Thu May 26 09:18:32 MST 2016
Thank you! Thank you! Thank you! Thank you! :)

I've been struggling with getting a secondary bootloader for an LPC1769 working for almost a week, using AN10866 as the basis, and looking at every thread I could find on secondary bootloaders for a cortex M3. The bootloader would correctly jump to the application, but none of the interrupt routines in the main app would work. Adding the "__enable_irq()" line in the bootloader made the main application's interrupt handlers work. As msepp asks, I have no idea why this should be necessary. It's not in any of the samples I've encountered.
0 Kudos

882 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mysepp on Fri Apr 22 07:46:58 MST 2016
Question aside: Why __enable_irq() before jump? I think it is correct, but why does it not work without it? What happens then
or different to the way, when IRQs are enabled?
Application is (I assume) installing its own interrupts handlers and also enables them when everything is setup and it is needed.
Second question: Shall app then disable interrupts as one of it first steps?
0 Kudos

882 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by frankeggink on Fri Apr 22 07:32:07 MST 2016
Hi,

This should work.
Bootloader is located at location 0x0 in memory.
Application is located at location 0x8000 (sector 1)


/*--------------------------------------------------------------------------------*/
/* bootloader config */
typedef void (*USER_ENTRY_PFN)();
#define SBL_SLV_FIRMWARE_START(0x8000)
USER_ENTRY_PFN user_entry;


/* Call bootloader */
__disable_irq();
SCB->VTOR = SBL_SLV_FIRMWARE_START;
__enable_irq();
//__set_MSP(SCB->VTOR);//load stackpointer with initial value
__set_MSP(*(uint32_t *)SBL_SLV_FIRMWARE_START);
(user_entry)();
/*--------------------------------------------------------------------------------*/

Best Regards,

Frank Eggink
0 Kudos

882 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by whitecoe on Fri Sep 04 01:02:16 MST 2015

Quote: michaelleekun

    __set_MSP(SCB->VTOR);//load stackpointer with initial value



Well that certain looks broken to me. You want something like:

__set_MSP((uint32_t *)SBL_SLV_FIRMWARE_START);


i.e. the contents of the first address of the image, not the address itself.

HTH!
0 Kudos