This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cortex-M0: How to switch from one program to another

Hi,

In my Cortex-M0 project, there are two program images residing at different memory locations: 0x0000_0000 and 0x0010_0000.  Each program has its own vector table.  M0 will boot from the program at 0x0010_0000 then switch to the other program (0x0000_0000) at the end.

What is the correct way to switch to the porgram at 0x0000_0000?  I'm not sure whether the following instructions are correct or not.

     LDR     R6, =0x1                             ; set R6 to 0x0000_0001 due to Thumb mode

     LDR     R0, [R6]

     MOV     SP, R0

     LDR     R1, [R6, #4]

     BX      R1

Can someone please point me the right implementation?  Thanks a lot.

Parents
  • Now, this question keeps occupying my mind.

    If you're only going to copy code to the RAM, then you could also do one of these things:

    1. Create fixed addresses for interrupt service routines (not really a good solution).
    2. Create indirect interrupt service routines. These are not completely 'transparent' but will forward interrupt-invocations "manually".
    3. Create 'ramcode' or 'fastcode' sections in your linker-script, and then have your startup-code copy small code snippets from Flash-memory to SRAM when the microcontroller starts up. This requires no modifications of the vector tables, these will be fixed and point to the SRAM address.

    If you're interested in solution #3, I could send you an example linker-script and some startup-code. I could also write a document about it.

Reply
  • Now, this question keeps occupying my mind.

    If you're only going to copy code to the RAM, then you could also do one of these things:

    1. Create fixed addresses for interrupt service routines (not really a good solution).
    2. Create indirect interrupt service routines. These are not completely 'transparent' but will forward interrupt-invocations "manually".
    3. Create 'ramcode' or 'fastcode' sections in your linker-script, and then have your startup-code copy small code snippets from Flash-memory to SRAM when the microcontroller starts up. This requires no modifications of the vector tables, these will be fixed and point to the SRAM address.

    If you're interested in solution #3, I could send you an example linker-script and some startup-code. I could also write a document about it.

Children