Jump from bootloader to actual firmware

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by DennisFrie on Wed Sep 24 15:37:41 MST 2014
Hi guys
I'm using a secondary bootloader on my LPC1549, but keep getting a hardfault error, when calling the main firmware.

The bootloader is placed in flash address 0x00 and the main firmware is loaded to 0x2000.

Atm. I'm testing with a very basic sketch, where the "bootloader" just calls the main-firmware.

This is what I'm doing atm:

// Start by disabling interrupts, before changing interrupt vectors

// Set vector table offset
SCB->VTOR = 0x2000; // Note, can be anded with max allowed address, 0x3FFFFF80

// Create pointer to new program address
void (*code_ptr)(void) = (void (*)(void))0x2000;

// Call firmware at address 0x2000 (from pointer above)

Looking at application note AN10866 for LPC17xx, the program counter and stack pointer is changed, but I'm not sure if the vector table offset is enough on LPC15xx.
Trying to change the stack using the code below, my LPC dev. board crashses completely

asm volatile("ldr r0, =0x2000"); // Point to top stack
asm volatile("ldr r0, [r0]");
asm volatile("mov sp, r0");

asm volatile("ldr r0, =0x2004"); // Point to Reset handler
asm volatile("ldr r0, [r0]");
asm volatile("mov pc, r0");

I've tried
__set_MSP(*(__IO uint32_t*)0x2000); and call 0x2004 instead, but same result

Any good hints as to what I'm missing here?

When compiling the primary firmware, the compiler is set to use start from address 0x2000.

Without the updated vector table, I keep getting a hardfault-error (0x13C). With the updated vector table it ends at 0x213C (same hardfault vector, just with the offset).