Hey folks, I'm trying to jump from a boot-loader into an application. So far (with the help of folks on here) I've:
void run_program(void)
{
uint32_t runProgramAddress;
// Manual Entry Point
runProgramAddress = 0x00020000;
runProgram = (void (*) (void))runProgramAddress;
runProgram();
}
0x20000 is the location of the program that works when flashed independently. I've also tried using the address 0x20410 to go into the .text section, and 0x20454 to go to .text.main section (according to the corresponding .map file)
In all the above cases, the program seems to hang and it gets caught at WDOG_EWM_IRQ_Handler() at 0x450. Is there anything I need to do prior to making the jump, or any special assembly commands I should be using?
Thanks!
10/11/17 Update:
I've also tried re-writing the jump function as the following:
typedef int(*FuncPtr)();
FuncPtr Fseg_Main = (FuncPtr) BOOTLOADER_ADDRESS;
Fseg_Main();
and dabbled with some _asm commands to manually set the SP to the new address and the PC to the address incremented by 4, but still no luck. In another ARM example, the SCB Vector Table Offset Register had to be modified before the jump - going to look into modifying it.
Solved! Go to Solution.
Looking at the disassembly, jumping to a *local* function this way also failed, but just calling the function worked. Calling the function used branch instruction BL, while indirectly calling an address used BLX.
Behold.. the answer is in the ARM Cortex-M4 Generic User Guide, section 3.10.1, verse 14:
Rm (i.e. R3 in my case) Is a Register that indicates an address to branch to. Bit[0] of the value in Rm must be 1, but the address to branch to is created by changing bit[0] to 0.
So.. had to jump to 0x455 if I wanted to get to 0x454
Looking at the disassembly, jumping to a *local* function this way also failed, but just calling the function worked. Calling the function used branch instruction BL, while indirectly calling an address used BLX.
Behold.. the answer is in the ARM Cortex-M4 Generic User Guide, section 3.10.1, verse 14:
Rm (i.e. R3 in my case) Is a Register that indicates an address to branch to. Bit[0] of the value in Rm must be 1, but the address to branch to is created by changing bit[0] to 0.
So.. had to jump to 0x455 if I wanted to get to 0x454