AnsweredAssumed Answered

Jump to USB DFU Bootloader in startup code on STM32F042

Question asked by ethanz on Feb 21, 2015
Latest reply on May 2, 2018 by Hitoshi Yamada
I'm running a STM32F04 and want to jump to the USB DFU bootloader from user code. As recommended in other posts, I set a magic bit in SRAM, issue a soft reset, check for the magic value and branch to the bootloader if the magic value exists in the startup code.

My problem is that I branch to the bootloader but the F042 doesn't show up as a USB DFU device, it just seems to hang. I'm confident I have the correct memory addresses and I can't find any issues with my approach. Any ideas? Thanks.

Reset_Handler:
 
  /* Bootloader jumping */
  ldr r0, =0x200017F0 /* address of magic token */
  ldr r1, =0xDEADBEEF /* magic token */
  ldr r2, [r0, #0] /* load data from magic address */
  str r0, [r0, #0] /* zero data at magic address so we don't get stuck here */
  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 */
 
/* Copy the data segment initializers from flash to SRAM */
  movs r1, #0
  b LoopCopyDataInit

// On reset, SP=value at address 0x0
ldr r0, =0x00000000
ldr r0, [r0, #0]
mov sp, r0
 
ldr r0, =0x1FFFC800 /* Address of bootloader on f042 from CD00167594 pg 15 table 3 */
 
// Branch to bootloader
ldr r0, [r0, #4]
bx r0

Outcomes