Skip to content

Fix jump from STM bootloader to application - #319

Merged
marckleinebudde merged 1 commit into
candle-usb:masterfrom
Semiotmo:fix-jump-to-application-from-bootloader
Sep 17, 2026
Merged

marckleinebudde merged 1 commit into
candle-usb:masterfrom
Semiotmo:fix-jump-to-application-from-bootloader

Conversation

@Semiotmo

@Semiotmo Semiotmo commented Sep 16, 2026

Copy link
Copy Markdown

Jump from STM bootloader to application is currently broken.

When jumping from STM integrated bootloader to application (e.g. after a firmware update via dfu), SCB->VTOR is still set to point to the bootloaders vector table.
The STM bootloader does not reset this to the appropriate value on exit. It expects that the application itself sets the correct VTOR, as documented in AN3156, Rev 18, page 20.

The Jump to application works only if the user application sets the vector table correctly to
point to the application address.

When VTOR is not set to the applications vector table and an interrupt arrives, the application executes the interrupt handler defined in STM bootloader code instead of its own. In my case this crashed the MCU.

This pull request fixes this by making sure that the VTOR is set appropriately and no interrupt can arrive before it is set.

Additionally it ensures that after a successful jump from bootloader to application, the application does not directly jump back to bootloader by explicitly clearing the dfu_reset_to_bootloader_magic variable.
I decided to explicitly do it as well as I don't know if the STM bootloader will reset the memory associated with this variable itself.

This fix enables using the :leave parameter of dfu-util ( dfu-util -s 0x08000000:leave ...).

Closes: #195

@Semiotmo
Semiotmo force-pushed the fix-jump-to-application-from-bootloader branch from 6e97490 to cf9c31a Compare September 16, 2026 06:38

@marckleinebudde marckleinebudde left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!
Works for me on stm32g0b1. Please squash suggested fix.

Comment thread src/dfu.c Outdated
@marckleinebudde

Copy link
Copy Markdown
Collaborator

This will fix #176 (comment) and
Closes: #195

@marckleinebudde
marckleinebudde force-pushed the fix-jump-to-application-from-bootloader branch from cf9c31a to 7c92044 Compare September 17, 2026 07:35
@marckleinebudde
marckleinebudde self-requested a review September 17, 2026 07:35
@marckleinebudde
marckleinebudde force-pushed the fix-jump-to-application-from-bootloader branch from 7c92044 to 21148b5 Compare September 17, 2026 07:59
@marckleinebudde
marckleinebudde merged commit 85e5b33 into candle-usb:master Sep 17, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firmware restart after USB DFU update fails

2 participants