Content originally posted in LPCWare by 0xdeadbeef on Sat Nov 30 16:55:40 MST 2013
I had similar issues with the bootloader based on AN10866.
The problem with just jumping into the main system from the bootloader is that the stack pointer is not re-initialized correctly.
While without the boot loader, the 1st dword on the start vector would be automatically used as stack pointer, it is ignored when just jumping to the 2nd dword. So your main program will continue to use the boot stack which in best case wastes space and in worst case could be located at a completely different location and overwrite variables etc.
My project was done with CooCox and the bootloader with Keil, so your code might look different, but before jumping to the main system, you should add something like this:
unsigned int stack_adr = (USER_FLASH_START);
stack_adr = *(unsigned int*)stack_adr;
__MSR_MSP(stack_adr);