I am working with the stm32f4 Discovery board and I am trying to jump to a section of flash where I will begin executing another program there.The variable ApplicationAddress
is 0x08008000. When my code hits this section, the PC goes to 0x0000000 and the system freezes. I am not sure exactly what is going on. Thank you for your time. My code to jump is shown below.
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x8000);
JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);
Jump_To_Application = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
Jump_To_Application();
Presumably the bit of code that you posted int he question is actually using the MSP stack, so when you execute:
__set_MSP(*(__IO uint32_t*) ApplicationAddress);
that stack gets thrown away and if the Jump_To_Application
variable is a local variable (which might have been on the stack if it's a local variable - especially if you're running a non-optimized/debug build) might suddenly be garbage.
to solve this problem, I've used:
void LoadStackAndGo( void* sp, void* entry)
{
__asm (
"mov sp, r0 \n"
"mov pc, r1 \n"
);
}
which should be easily adaptable to whatever toolchain you're using.
I had the exact same problem, however my solution:
__set_MSP (*(__IO uint32_t*)ApplicationAddress);
__set_PSP (*(__IO uint32_t*)ApplicationAddress);
and declare the function pointer as static...
static Function jumpToApplication = (Function) * (__IO uint32_t*)(ApplicationAddress + 4);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.