Search code examples
memorystm32bootloaderremap

STM32 IAP Application Jump Condition Not Satisfied


I have a boot code at 0x08000000 and an application code at 0x08060000. I can jump to application from boot code if I comment out the condition check shown below:

//if (( (*(__IO uint32_t*)0x08060000) & 0x2FFE0000 ) == 0x20000000)
{
    JumpAddress = *(__IO uint32_t*)( 0x08060000 + 4 );
    Jump_To_Application = (pFunction)JumpAddress;
    __set_MSP( *(__IO uint32_t*)0x08060000 );
    Jump_To_Application();
}

The condition is not satisfied as the left side is equal to 0x20020000. I don't understand why it is 0x20020000 instead of being 0x20000000.

Why do we check the content of the start address with 0x20000000. What is stored in this memory address and what should it be normally?


Solution

  • It's a vector table that's located at these addresses (at 0x08000000 for bootloader and at 0x08060000 for application respectively). The first value stored in the vector table is the reset value of the stack pointer.

    You can check this link for more information: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/BABIFJFG.html

    Why you'd want to check this value this way, one may only guess. It is likely there to act as a kind of safety check to see whether there may be a valid application loaded. It's definitely not sufficient and doesn't guarantee much (e.g. half of the application may be loaded). It also depends entirely on your memory layout and where in RAM you decide to place your stack. I assume you copy-pasted (or generated) some portion of the code responsible for memory layout in your application, then copy-pasted - from another source - this portion of the code that has the check in question. Those two will likely not work together very well.