This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32L072 Jumping to embedded bootloader from application code

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:

1)Reset Handler

2)System 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*/

3) 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,

Parents
  • void (*foo)(void) = 0x00000004;
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
    SCB -> VTOR = 0;
    __set_MSP(0x20005000);
    foo();
    

    You need to remap SYSTEM Flash to 0 first
    You need the value AT address 4 (after remapping) as the function pointer, not the value 4.

    Note:

    MSP is probably just fine, but it would normally use the value at 0x00000000 after the remapping.

Reply
  • void (*foo)(void) = 0x00000004;
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
    SCB -> VTOR = 0;
    __set_MSP(0x20005000);
    foo();
    

    You need to remap SYSTEM Flash to 0 first
    You need the value AT address 4 (after remapping) as the function pointer, not the value 4.

    Note:

    MSP is probably just fine, but it would normally use the value at 0x00000000 after the remapping.

Children
No data