2023-12-14 08:31 AM
I am trying to implement a bootloader using STM32 F103 processor. I have not used an Arm processor before, but I have read the various articles and posts, and I think I’m doing the jump-to-app as described. But as soon as I execute the jump, the next instruction executed is the first instruction of the Reset_Handler in the boot code (at 0x08002930), not the Reset_Handler in the app code (at 0x0801018C).
I load the app code first but don't execute. Then I load and run the boot code.
Boot linker file:
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 48K
App linker file:
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K
FLASH (rx) : ORIGIN = 0x800C000, LENGTH = 80K
Memory Browser:
Boot ISR Vector Table at 0x08000000
_estack 0x20005000
Reset_Handler 0x08002931
App ISR Vector Table at 0x0800C000
_estack 0x20005000
Reset_Handler 0x0801018D
In the app I uncommented the define for USER_VECT_TAB_ADDRESS and set VECT_TAB_OFFSET to 0x0000C000.
The watchdog is disabled in the boot code.
In boot:
typedef void (*pFunction)(void) __attribute__((noreturn));
typedef unsigned long int U32; /* 32 bits */
#define FLASH_BASE 0x08000000UL /*!< FLASH base address in the alias region */
#define APP_OFFSET (0x0000C000UL)
#define APP_START (FLASH_BASE + APP_OFFSET)
void JumpToApp(void)
{
volatile U32 JumpAddress = *(volatile U32*)(APP_START + 4);
pFunction Jump = (pFunction)JumpAddress;
__disable_irq();
HAL_RCC_DeInit();
HAL_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
SCB->VTOR = APP_START;
__set_MSP(*(U32*)APP_START);
Jump();
}
When I single step through JumpToApp, the JumpAddress is 0x801018D. Everything seems ok until I single step into the Jump() instruction. Then the next instruction is the Reset_Handler of the boot at 0x08002930, not the Reset_Handler of the app at 0x801018C.
What am I missing? Any input would be appreciated.
2023-12-18 04:48 PM
re-enabling interrupts right before I write to SCB->VTOR
The order should be the opposite and there are other related issues. Read this post: