cancel
Showing results for 
Search instead for 
Did you mean: 

IAP Bootloader Question

solomonviveros
Associate II
Posted on November 27, 2013 at 20:15

I've developed a single project[using two separate irom sections which keil currently manages] that contains my bootloader and ApplicationMain(). The first flash block is reserved for the bootloader that runs upon power-up which then depending on criteria will either remain in the bootloader or run the rest of my project[found in following flash sections]...

#define ApplicationMain() ((void (*)())(0x08005d69))()
if((BootLoaderSaved.BootLoaderProgrammedFlag1 == VALID_FW_PRESENT_FLAG1) && (BootLoaderSaved.BootLoaderProgrammedFlag2 == VALID_FW_PRESENT_FLAG2) && (BootLoaderSaved.BootLoaderProgrammedFlag3 == VALID_FW_PRESENT_FLAG3))
ApplicationMain();
else
{
FLASH_If_Init();
while(1)
{ 
BootLoaderDoReceive();
BootLoaderDoTransmit();
}

My current implementation requires the known location of my ApplicationMain which I get from looking at the project *.map file...no sooner the address of ApplicationMain() changes, I get a hard fault...my question is -- do the ST IAP examples expect whatever user application's main() to be fixed at 0x08004000, if so, how does one accomplish this in keil? What does__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); do exactly? I noticed that the code appears to be running correctly even without the line present in my current code...
1 REPLY 1
Posted on November 28, 2013 at 02:36

Missing a couple of major plot points here.

The loader and app really need to be independent and free standing, each will have it's own vector table, stack and C runtime startup code. There are other ways, be this is likely to be the easiest and most robust method. Each will get a unique region of IROM so as not to step on each other. The IRAM can be the same, because there should be no expectation of returning, but you could carve out some space for parameters, etc.

You are not attempting to call main(), but rather the initialization code from the compiler. Setting the MSP (Stack Pointer) while preferred, does get done later in the Keil start up code. Nominally to __initial_sp, the same value in the vector table.

The transfer code is looking to load both SP and PC (Program Counter - ResetHandler) from the first two words of the vector table for the Application image.

Linking through the vector table, and establishing it for the processor in SCB->VTOR, means you don't have to code special addresses in the Boot images, and you won't get Hard Faults because you are not jumping to some arbitrary/random location.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..