AnsweredAssumed Answered

Jump address is not compiling correctly for STML1x

Question asked by tom cooper on Apr 23, 2014
Latest reply on May 21, 2014 by Tom_Rfid
My goal is to jump from bank 1 to bank 2 at the start of main. I'm trying to follow the example in this forum post: link

However, when I try to specify an address in the opposite flash bank, an address that is offset from PC seems to be loaded instead of the exact address. As you can see, the 0x08000000 address is loaded correctly but the 0x08030000 address is not. Even if I replace the C code with inline ASM, it still does this. Am I doing something wrong or using the wrong ASM instruction? How do I go about accomplishing this?

Here is my relevant C code in main:

01./* Jump to opposite bank without modifying BFB2 bit */
02.if (currFwBank == 1)
03.{
04.  U32 jumpAddr = *(U32*)(FLASH_BANK_2_START_ADDR+4);
05.  JumpFunc_t jumpToOtherBank = (JumpFunc_t)jumpAddr;
06.  //__ASM volatile ("");
07.  __disable_irq();
08.  __set_MSP(*(U32*)FLASH_BANK_2_START_ADDR);
09.  jumpToOtherBank();
10.}
11.else
12.{
13.  U32 jumpAddr = *(U32*)(FLASH_BANK_1_START_ADDR+4);
14.  JumpFunc_t jumpToOtherBank = (JumpFunc_t)jumpAddr;
15.  __disable_irq();
16.  __set_MSP(*(U32*)FLASH_BANK_1_START_ADDR);
17.  jumpToOtherBank();
18.}


Here are my mixed C/assembly instructions from the Keil debugger:

   203:         if (currFwBank == 1)
   204:         {
0x0800061E F89D0000  LDRB     r0,[sp,#0x00]
0x08000622 2801      CMP      r0,#0x01
0x08000624 D10A      BNE      0x0800063C
   205:             U32 jumpAddr = *(U32*)(FLASH_BANK_2_START_ADDR+4);
0x08000626 481F      LDR      r0,[pc,#124]  ; @0x080006A4
0x08000628 6844      LDR      r4,[r0,#0x04]
   206:             JumpFunc_t jumpToOtherBank = (JumpFunc_t)jumpAddr;
   207:             //__ASM volatile ("");
0x0800062A 4625      MOV      r5,r4
   208:             __disable_irq();
0x0800062C B672      CPSID    I
   209:             __set_MSP(*(U32*)FLASH_BANK_2_START_ADDR);
0x0800062E 491D      LDR      r1,[pc,#116]  ; @0x080006A4
0x08000630 6808      LDR      r0,[r1,#0x00]
   171:   __regMainStackPointer = topOfMainStack;
0x08000632 F3808808  MSR      MSP,r0
   172: }
0x08000636 BF00      NOP     
   210:             jumpToOtherBank();
0x08000638 47A8      BLX      r5
   211:         }
   212:         else
   213:         {
0x0800063A E00C      B        0x08000656
   214:             U32 jumpAddr = *(U32*)(FLASH_BANK_1_START_ADDR+4);
0x0800063C F04F6000  MOV      r0,#0x8000000
0x08000640 6844      LDR      r4,[r0,#0x04]
   215:             JumpFunc_t jumpToOtherBank = (JumpFunc_t)jumpAddr;
0x08000642 4625      MOV      r5,r4
   216:             __disable_irq();
0x08000644 B672      CPSID    I
   217:             __set_MSP(*(U32*)FLASH_BANK_1_START_ADDR);
0x08000646 F04F6100  MOV      r1,#0x8000000
0x0800064A 6808      LDR      r0,[r1,#0x00]
0x0800064C F3808808  MSR      MSP,r0
0x08000650 BF00      NOP     
   218:             jumpToOtherBank();
0x08000652 47A8      BLX      r5
   219:         }

Outcomes