hardfault when lpc1788 bootloader jumps to user application

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by shoeloader on Tue Jun 10 07:41:36 MST 2014
I've written a bootloader for the lpc1788.
The bootloader successfully reads an image from a sd-card during startup and loads it in the flash memory when the version, length or crc differs from the image currently in flash.
The problem is when I call the user code using a function pointer the microcontroller gets a hardfault error.
This is how I store the code in flash:
  [*]the bootloader is stored in address 0 to 0x5000(sector 0 to 4)
  [*]meta data about image in flash is stored at address 0x5000(sector 5)
  [*]user application is only 1440 bytes and blinks an led(no interrupts) and is stored from address 0x6000(sector 6)
  [*]flash is written in blocks of 4kiB and is padded with zeros so a flash signature can be calculated(this works as well)
  [*]start and size of flash has been properly entered in keil

Before I call the user code I disable the systick timer. No other peripherals are enabled. This is how I call the user code:

typedef void (*user_code_pointer_type)(void);

void run_user_code(void){
  user_code_pointer_type user_code_entry;
  //user_code_entry = (user_code_pointer_type)((uint32_t*)(user_start_sector_address + 4));//causes invstate at 0x6004
  user_code_entry = (user_code_pointer_type)(user_start_sector_address|1);//causes impreciserr at 0x6006
  //user_code_entry = (user_code_pointer_type)(user_start_sector_address);//causes invstate at 0x6000
  //NVIC_SetVTOR(user_start_sector_address);//hardfault handler of user code is called instead

I've tried disabling interrupts, moving interrupt vectors, moving vectors to ram and other things. Nothing works. What am I doing wrong?