cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L072 Jumping to embedded bootloader from application code

ATirl
Associate II

Hi,

MCU version 20KB RAM, 128 KB FLASH category 5. I tried solutions on the web available for different STM32 MCU with no success. BOOT0 pin is fixed to GND in my custom PCB.

My final code flow is like below:

  • Reset Handler
  • Sytem init
    • MSI as a system clock, reset all other clock settings
    • and does something like below
SCB -> VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector table relocation in Internal Flash*/
  • Main Function
int main(){
 
HAL_RCC_DeInit();
 
Systick -> CTRL = 0;
Systick -> LOAD =0;
Systick -> VAL =0;
 
__disable_irq();
 
HAL_FLASH_Unlock();
 
void (*foo)(void) = 0x00000004;
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
SCB -> VTOR = 0;
__set_MSP(0x20005000);
foo();
 
while(1);
} 

When i debug, code jumps to the location 0x00000004 but after some instructions device jumps again to reset handler.

Can you correct me to make embedded USBDFU bootloader work ?

Thanks in advance,

5 REPLIES 5

Pretty sure there is no code at 4

And nothing on the other side enables the processor's IRQ again. ​

Unlocking the flash does not enable.the syscfg clock.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Please note that i remapped the system memory. So 0x1FF00004(AN2606 says system memory start address is 0x1FF00000) is mapped to 4 actually. I could see it from debugger's disassembly section. I tried to enable syscfg clock with __HAL_RCC_SYSCFG_CLK_ENABLE() also, No success. Please help with more detailed comments.

Pavel A.
Evangelist III

> So 0x1FF00004(AN2606 says system memory start address is 0x1FF00000) is mapped to 4 actually.

4 is not the address to jump to. It is address of address to jump to.

-- pa

 ((void (*)(void)) *((uint32_t*) 0x00000004))();

I observed same behavior with the above jump too. I mean, It jumps back to reset handler.

Pavel A.
Evangelist III

Also, don't forget to set the stack pointer. The value is *(NULL) 🙂

-- pa