2023-09-27 06:04 PM
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:
Thanks for any tips!
2023-09-27 09:36 PM
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.
2023-09-29 11:12 AM
// 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:
The app seems to be correct in flash.
After the jump, the PC is stuck at 0x08014304
Looks like it has crashed, but platformio does not show the disassembly for this section.