cancel
Showing results for 
Search instead for 
Did you mean: 

stm32g070cbt6 bootloader; jump to app

MBarb.2
Associate II

Hello everybody,

 

I am developing a bootloader that is currently writing to flash, but I am not being able to jump to the written blocks.

The bootloader runs from 0x8000000. Built with arduino_stm32.

App starts at 0x8009000.

I can test the app with the linker set to 0x8000000 with no problems seen.

So, the bootloader runs, loads the app binary to 0x8009000 and I am not able to jump to it properly.

I think I have done what other developers did in most forum posts.

Added the jump function I am using. After the Jump() call, the PC stops and I can not step the code in asm.

 

 

 

 

void BootJump(uint32_t *Address) {
    uint32_t JumpAddress = 0x08009004;
    pFunction Jump = (pFunction)JumpAddress;
    HAL_RCC_DeInit();
    HAL_DeInit();
    /* 5. Disable SysTick and clear its exception pending bit, if it is used in the bootloader, e. g. by the RTX.  */
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL  = 0;
    /*8. Load the vector table address of the user application into SCB->VTOR register.
         Make sure the address meets the alignment requirements of the register. */
    SCB->VTOR = (uint32_t)Address;
    /* 9. Set the MSP to the value found in the user application vector table. */
    __set_MSP(*(__IO uint32_t*)0x08009000);
    /* 10. Set the PC to the reset vector value of the user application via a function call. */
    Jump();
}

 

 

 

 

Bootloader linker:

/* Memories definition */
MEMORY
{
  RAM    (xrw)   : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
  FLASH  (rx)    : ORIGIN = 0x8000000, LENGTH = 0x8FFF
}
 
App linker:
/* Memories definition */
MEMORY
{
  RAM    (xrw)   : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
  FLASH  (rx)    : ORIGIN = 0x8009000, LENGTH = LD_MAX_SIZE - 0x9000 - 2048
}

 

Thanks for any tips!

2 REPLIES 2
Andreas Bolsch
Lead II

Your jump is to 0x08009004, but that's the location of the reset vector, so you're missing one level of indirection. The jump target is the *contents* of 0x08009004.

 

Thank you.
 
So I changed the app address and the code:

 

// build_flags = -DUSER_APP_ADDRESS=0x0800A000
void BootJump(void) {
    void (*Jump)(void);

    HAL_RCC_DeInit();
    HAL_DeInit();
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL  = 0;
    Jump = (void (*)(void)) (*((__IO uint32_t *)(USER_APP_ADDRESS+4)));
    SCB->VTOR = (uint32_t)USER_APP_ADDRESS;
    __set_MSP(*(__IO uint32_t*)USER_APP_ADDRESS);
    Jump();
}

 

App linker changed to:

 

 

/* Memories definition */
MEMORY
{
  RAM    (xrw)   : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
  FLASH  (rx)    : ORIGIN = 0x800A000, LENGTH = LD_MAX_SIZE - 0xA000 - 2048
}

 

App build flags:

-DVECT_TAB_BASE_ADDRESS=0x08000000
-DVECT_TAB_OFFSET=0xA000

The app seems to be correct in flash.

MBarb2_1-1696010239175.png

After the jump, the PC is stuck at 0x08014304

 

MBarb2_2-1696010715025.png

Looks like it has crashed, but platformio does not show the disassembly for this section.