2019-09-04 09:10 AM
Hi,
I am writing a customized bootloader for STM32L072CZ (Cortex M0+) and I have an issue with performing the jumping from the bootloader to the application.
My application is linked at certain address (0x800b000) and I want to jump to this address from the bootloader. I've looked into a lot of online discussions but mainly for different stm32 processors.
Here is my code to do the jumping:
void mbed_start_application(uint32_t address) {
__disable_irq();
SysTick->CTRL = 0;
// Disable IRQs & clear pending IRQs
int i;
for (i = 0; i < 8; i++) {
NVIC->IP[i] = 0x00000000;
}
NVIC->ICER[0] = 0xFFFFFFFF;
NVIC->ICPR[0] = 0xFFFFFFFF;
// SCB->CPUID - Read only CPU ID register
SCB->ICSR |= SCB_ICSR_PENDSVCLR_Msk;
SCB->VTOR = address;
SCB->AIRCR = 0x05FA | 0x0000;
SCB->SCR = 0x00000000;
for (i = 0; i < 2; i++) {
SCB->SHP[i] = 0x00;
}
SCB->SHCSR = 0x00000000;
HAL_DeInit();
/*GPIO_DeInit();
HAL_RCC_DeInit();
HAL_MPU_Disable();*/
__set_MSP(*(__IO uint32_t*)address);
/* Launch application */
uint32_t JumpAddress = *(__IO uint32_t*)(address + 4u);
pFunction Jump = (pFunction)JumpAddress;
Jump();
}
Please point what I could be missing .
Thanks,
Khaled
2019-09-04 09:32 AM
It is best to have a switch very early in the boot code before any initialization. That switch should look for a magic number in RAM that has not yet been initialized. If it sees the magic number, the number is reset and a jump to bootloader with setting Sysmen, vtor msp etc is done. User code , when boot loader is requested, sets that magic number and performs a warm reset.
2019-09-04 09:50 AM
Thanks for your answer Uwe but I would appreciate if you clarify what you mean. It's not clear for me what you mean by early switch and magic number in the RAM. Thanks!
2019-09-04 10:00 AM
Early in the boot code you test some RAM at known address for a know number (magic number). If the magic number is read, you branch (switch) to the code calling the system bootloader otherwise you proceed with your code.
Otherwise I do not see SYSCFG_CFGR1 set to 01. Maybe that is what is missing from your code.
2019-09-04 10:12 AM
Who will enable the interrupt you disabled?
What about the code on the app side using the correct vector table?
It is not jumping? Have you traced execution?
>>I've looked into a lot of online discussions but mainly for different stm32 processors.
The real problem is the shot-gun/kitchen-sink approach, and not really understanding the problem or the processor properly.
Or the interactions/expectations of the code on either side.