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?
Hi Jingjing,
thank you for your reply.
LPC1114 has Cortex-M0 core. The Cortex-M0 (without plus), does not have the VTOR register.
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!
-----------------------------------------------------------------------------------------------------------------------
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.
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
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!
-----------------------------------------------------------------------------------------------------------------------
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);
}
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!
-----------------------------------------------------------------------------------------------------------------------
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!
-----------------------------------------------------------------------------------------------------------------------