Jump to bootloader from main application

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

Jump to bootloader from main application

3,519 Views
dawidstysiak
Contributor I


I use LPC1114. I have bootolader at 0x0000 address. I jump from this boolader to main application at 0x1000. This works perfect. Now I have to invoke bootloader from main application. I know that I can use NVIC_SystemReset(), but this software reset changes GPIO pin state. In my case GPIO states should be the same. So I have to invoke bootloader different way. The only possible way is jump to 0x0000 address. My idea:

__disable_irq();

SPI_Disable_Interrupts();

Chip_TIMER_DeInit(LPC_TIMER16_0);

Chip_ADC_DeInit();
SysTick_disable();

LPC_SYSCTL->SYSMEMREMAP = 0x2;  // remap to internal flash

   

LPC_SYSCON->MAINCLKSEL  = 0;   //Internal oscillator

LPC_SYSCON->MAINCLKUEN  = 0;

LPC_SYSCON->MAINCLKUEN  = 1;

for (i=0; i<50000; i++);   //some delay

stackPointer = *(uint32_t*)(0);

  __set_MSP(stackPointer);

user_entry = (USER_ENTRY_PFN)*((uint32_t*)(4));

(user_entry)();

is this correct? I use in bootloader SPI. How can I reset SPI interface to default value?

Labels (1)
0 Kudos
7 Replies

1,511 Views
dawidstysiak
Contributor I

Hi Jingjing,

thank you for your reply.

LPC1114 has Cortex-M0 core. The Cortex-M0 (without plus), does not have the VTOR register.

0 Kudos

1,511 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Dawid,

    You are correct, Cortex M0 doesn't have VTOR, please delete the VTOR relocation, then try again.

  Any question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,511 Views
dawidstysiak
Contributor I

Your code give me Hard fault. My code works but after jump back to main application SysTick interrupt does not work. I don't know why.

I have to change line:

LDR  sp, [r0, #0]    ; Get app stack pointer 

to

stackPointer = *(uint32_t*)(0);
__set_MSP(stackPointer);

due to compiler error.

0 Kudos

1,511 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Dawid,

    Sorry for my later reply!

  The code which I give you is from above Cortex M0+,  because the Cortex M0 don't allow the vector table to be remapped, the vector table is  located in the same area of flash memory as the secondary bootloader, so customer should redirect the functions by themselves.

  Actually, we have an application about it, please refer to AN10995 :LPC1100 secondary bootloader.

page7

pastedImage_0.png

Please redirect the systick handler to your application code.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,511 Views
nileshmotawala
Contributor I

Hi Kerry,

               I read your reply, and it seems to helpful for me, i have same problem as dawidstysiak,

I am using cotex-m3 LPC1788 and want to jump from application code to bootloader code and try to use  your code. 

but it gives me hardfault. 

application code address = 0xA000

and the part of the code i am using :

void boot_jump( uint32_t address )
{
__asm("ldr sp, [r0]"); //Load new stack pointer address
__asm("ldr pc, [r0, #4]"); //Load new program counter address
}

void boot_jump( uint32_t address )
{
__asm("ldr sp, [r0]"); //Load new stack pointer address
__asm("ldr pc, [r0, #4]"); //Load new program counter address
}


void Execute_BootloaderCode( void )
{
unsigned int addr;

__disable_irq();
addr = 0x00000000;
SCB->VTOR = (unsigned int)addr;

boot_jump(addr);

}

0 Kudos

1,511 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Nilesh Motawala,

    Before you want to jump from application code to bootloader code, you must make sure the application code clock mode is the same as the bootloader code.

    Take an example, the bootloader use the internal IRC as the clock source, but your application code is using the external crystal as the clock source, then the clock mode is not the same, when you jump to the bootloader mode, the clock mode will have problem, it will cause some errors.

   So, please modify the clock mode is the same as bootloader mode before you want to go to bootloader code.

 

Wish it helps you!

Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,511 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Dawid,

    Please use this code to jump to bootloader from main application:

__asm void loadPC(int Addr)

{

        LDR  sp, [r0, #0]    ; Get app stack pointer

    LDR  r1, [r0, #4]    ; Get app reset vector

    CPSIE I        ; Enable ints at core

    BX  r1

}

void houseClean(void)

{

    LPC_SYSCON->MAINCLKSEL = 0; //Internal oscillator

}

void executeBootloader(void)

{

    houseClean();

    __disable_irq();

    SCB->VTOR = (unsigned int) 0x0000;

    loadPC(0x0000);

}

When you want to jump to the bootloader, call executeBootloader() function.

If you want to reset SPI interface, please call Chip_SSP_DeInit function before you jump to bootloader.

Wish it helps you!

If you still have question, please let me know!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos