简体   繁体   English

Stm32f4内存跳跃

[英]Stm32f4 Memory Jumping

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. 我正在使用stm32f4发现板,并且尝试跳到Flash的一部分,在那里我将开始执行另一个程序。变量ApplicationAddress为0x08008000。 When my code hits this section, the PC goes to 0x0000000 and the system freezes. 当我的代码触及此部分时,PC转到0x0000000,系统冻结。 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: 大概您在问题中发布的代码实际上是在使用MSP堆栈,因此在执行时:

__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. 该堆栈将被丢弃,并且如果Jump_To_Application变量是局部变量(如果它是局部变量,则可能已在堆栈上-尤其是如果您运行的是非优化/调试版本)可能会突然变成垃圾。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM