Skip to main content
gareth
Associate II
June 3, 2009
Question

Switching Between Programs in Flash

  • June 3, 2009
  • 5 replies
  • 1056 views
Posted on June 03, 2009 at 09:56

Switching Between Programs in Flash

    This topic has been closed for replies.

    5 replies

    ccowdery9
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    Can't you use function pointers?:

    (0xdeadbeef)(); // probably needs some casting

    Chris.

    gareth
    garethAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    Hi all,

    I have two programs stored in flash memory and whish to be able to switch between the two. I have a known address for each that i wish to switch too and hence would normaly use inline assembler to create a Branch function. However in this function does not seem to be supported by the STM32 in the Keil environment.

    Can anyone please advise me on a method of doing this Jump?

    Thanks in advance

    Gareth

    gareth
    garethAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    I have tried this method with little/no success. is it possible to do it using embedded assembly? if so can some one please show me an example.

    gareth
    garethAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    Hi Andy,

    Thankyou for your help.

    This works well for me too. have implemented and tested it and all seems well.

    Cheers,

    Gareth

    andy239955_st
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:12

    Hi,

    I've done something similar.

    I have a bootloader that checks to see if the main application is present. If it is it passes control to it.

    The main app is a stand-alone program, built to run by itself so it's doing all of the normal c startup stuff including having a vector table at the start.

    I use that to get the start address of the actual app.

    Code:

    /*

    * Transfer control to the main application.

    *

    * We get the start address from the reset vector in the jump table.

    */

    void launchMainApp(void)

    {

    void (*mainApplicationStart) ();

    long *myPtr1, *myPtr2;

    myPtr1 = (long*)ROM_BLOCK_HIGH_START; // Take address from the vector table

    myPtr1++;

    myPtr2 = (long*)*myPtr1;

    mainApplicationStart = (void(*)(void))myPtr2;

    mainApplicationStart();

    }

    This works well for me.

    Cheers.

    Andy.