diff --git a/startup_stm32f042x6.s b/startup_stm32f042x6.s --- a/startup_stm32f042x6.s +++ b/startup_stm32f042x6.s @@ -64,6 +64,17 @@ defined in linker script */ .weak Reset_Handler .type Reset_Handler, %function Reset_Handler: + + /* Bootloader jumping */ + ldr r0, =0x200017F0 /* address of magic token, is addr within memory range? */ + ldr r1, =0xDEADBEEF /* magical beef token */ + ldr r2, [r0, #0] /* load data from magic address */ + str r0, [r0, #0] /* zero data at magic address so we don't bootloop */ + cmp r2, r1 /* compare data at magic address to magic token */ + beq Reboot_Loader /* jump to bootloader if token match */ + /* End bootloader jumping */ + + ldr r0, =_estack mov sp, r0 /* set stack pointer */ @@ -71,6 +82,19 @@ Reset_Handler: movs r1, #0 b LoopCopyDataInit +/* Boot into bootloader */ +Reboot_Loader: + ldr r0, =0x1FFFF6A6 /* Address of bootloader on f042 from CD00167594 pg 15 table 3 */ + /* This replaces ldr sp, [r0, #0] which doesn't work on m0 */ + // Set stack pointer + ldr r1, [r0, #0] + mov sp, r1 + + // Branch to bootloader + ldr r0, [r0, #4] + bx r0 + + CopyDataInit: ldr r3, =_sidata ldr r3, [r3, r1]