This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

two programs simultaneously downloaded to different parts of memory?

 

Is there a way to compile two programs (each has its own main() function) and download them to different parts of memory at the same time?

My first program is a resident firmware programmed to reside in 0xC000 ... 0xC3FF, my second program is an application programmed to reside in 0xC400...0xDFFF.  They use

__asm("mov.w   #0xC000, PC");  ..... and

__asm("mov.w   #0xC400, PC");

to jump back and forth to each other, as needed.  I currently download them one at a time.  The firmware is downloaded with the option to "Erase main and information memory" and the app is downloaded with the option "Retain unchanged memory".  The firmware uses the default linker file, the app uses a custom linker file with

-Z(CONST)DATA16_C,DATA16_ID,DIFUNCT,CHECKSUM=C400-FFDF
-Z(CODE)CSTART,ISR_CODE,CODE_ID=C400-FFDF
-P(CODE)CODE=C400-FFDF

so that it doesn't overwrite the firmware that is already downloaded into 0xC000 ... 0xC3FF.

What I would like to be able to do is download both programs with one command, either from within IAR Embedded Workbench or via command line.  Any suggestions?

 

  • Adam Hoover said:
    Is there a way to compile two programs (each has its own main() function) and download them to different parts of memory at the same time?

    Yes. And it has been discussed in several (older an d newer) threads. Mostly in conjunction with the term 'custom BSL'.

    However, it is difficult.

    Both programs have their own ISRs and therefore their own vector table, but the MSP only knows one vector table.
    As long as no program uses an interrupt used by the othe rprogram too, the two vector tables might be joined, but this is unlikely. Reprogramming the vector table at runtime isn't really a solution too.
    So you need to implement some sort of managing. E.g. by implementing a jumptable to which the real vectors point, and the jumptable utilizes a secondary table in ram which is copied there depending on which applicaiton runs.

    It's not trivial.

    In most cases it is easier to join the two projects on source code level and compile them as one project.

  • It is possible to place a function (for example, the main() function) in a specific range of memory?  If I could do this, I could rename the main() function of one of the programs to something else and then compile it all together.

    Or, is it possible to download code from the command line, instead of having to use IAR?  I would still be downloading twice but it would be easier.

     

  • My apologies for being lazy and asking easily searched questions.  In case others search for the same problem, here's how you place functions in specific memory locations:

    http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/107911/380999.aspx

    Also, see the IAR C/C++ Compiler Reference Guide, the section on placing code and data in memory.

     

    For how to use command line arguments to download instead of going through IAR's GUI, look at the .bat file created in the "Settings" sub-folder of your project.

     

     

  • Why do you need to know where it ends up?

    Just write a common main() function that calls main1() and main2() depending on uintended usage (por pin, written config, etc.) It doesn't matter where it starts. After all, main() is just a normal function.

    Since you need to merge the used variables (you only have one startup code that initializes only one set of variables), there's no difference in having code here or there, as long as the linker knows where it did put it.
    And there is no difference between having two projects or just one whose one half is never executed.

  •  

    One of the programs is a resident monitor.  It's purpose is to replace all the code for the other program (the application).  When the host PC software initiates the correct interrupt, program control jumps to the monitor, which can then receive new application code which overwrites the designated memory.  Thus, they need to have defined locations.

     

     

  • So the downloaded part has its own, changing vector table, variables etc. The start of the downloaded program is in the vector table. It needs its startup code called etc. And the reset vector points to it. New application, new vector table, new variables that need to be initialized before calling main(). So knowing or setting the address of main() won't help a bit. YOu need to call the specific startup code, and the reset vector in the applicaiton specific vector table tells you where it is.

    The monitor code can just use ram as it likes, but if compiled together with the application, it must not use any global variables, except for those with fixed addresses (which are not linked later).
    The only requirement is that the monitor program is always at the same location and the applicaiton does not use this location.

    The theory for such a 'bootloader' has been discussed in many threads. Yet there is no implementation ready for immediate use (as it depends on the project requirements).

**Attention** This is a public forum