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
  • You would need to change the linker ROM start for each application,
    so they all get their own vector table (below tested for M0+)
    Can take a couple of short cuts as M0 probably will have less than 64K of flash,
    and you compile to 1K boundary.

    
    


    if ( firm1 > firm2)   __asm("movs r0, #0x40");            // upper byte for firmware at 0x4000
    else  __asm("movs r0, #0xA0");                            // upper byte for firmware at 0xA000
    __asm("lsls r0, r0, #8"); __asm("ldr r1, [r0]"); __asm("msr msp, r1"); // Set new MSP __asm("msr psp, r1"); // PSP based on SP __asm("ldr r1, [r0,#0x4]"); __asm("mov pc, r1"); // Jump by changing PC



Reply
  • You would need to change the linker ROM start for each application,
    so they all get their own vector table (below tested for M0+)
    Can take a couple of short cuts as M0 probably will have less than 64K of flash,
    and you compile to 1K boundary.

    
    


    if ( firm1 > firm2)   __asm("movs r0, #0x40");            // upper byte for firmware at 0x4000
    else  __asm("movs r0, #0xA0");                            // upper byte for firmware at 0xA000
    __asm("lsls r0, r0, #8"); __asm("ldr r1, [r0]"); __asm("msr msp, r1"); // Set new MSP __asm("msr psp, r1"); // PSP based on SP __asm("ldr r1, [r0,#0x4]"); __asm("mov pc, r1"); // Jump by changing PC



Children
No data
More questions in this forum