I am trying to jump from my bootloader to the start of the main app. I modified the linker scripts so that the bootloader is between 0x00400000 (the start of the flash in the Atmel SAM3S4C) and 0x00400FFF . The main app starts at 0x00401000.
The code which I am using is this (in IAR for ARM, v6.3):
I am almost sure the code is correct, but for some reason it ends up triggering a hard fault exception.
Code: Select all
#define FIRMWARE_START_ADDRESS (0x00401000) #define FIRMWARE_RESET_ADDRESS (FIRMWARE_START_ADDRESS + 4) void (*runFirmware)(void) = NULL ; __set_MSP(*(int *)FIRMWARE_START_ADDRESS) ; // offset the start of the vector table (first 6 bits must be zero) // The register containing the offset, from 0x00000000, is at 0xE000ED08 *(int *)0xE000ED08 = FIRMWARE_START_ADDRESS ; // jump to the start of the firmware, casting the address as function pointer // to the start of the firmware runFirmware = (void(*)(void))(FIRMWARE_RESET_ADDRESS) ; runFirmware() ;
Can it be a problem with the addresses ? Using the debugger, I noticed that the reset handler (in the vector table) is at 0x0040AD3D, but the startup function in fact is at 0x0040AD3C (one byte before).
I also tried making the jump to the main() of my application (I found the start address in the linker map file) and it worked. But then it should also work for the function in the reset table, no ?
Any suggestions to what I am doing wrong ?
Nelson Gon\c calves