cancel
Showing results for 
Search instead for 
Did you mean: 

Why Doesn't My STM32 Bootloader Jump to the Application After a Hard Reset?

Harsh_Gajjalwar
Associate II

Hello STM Community,

I'm working on an STM32 project that involves a custom bootloader and application code. Here's the setup:

  • Bootloader: Located at 0x08000000.
  • Application: Located at 0x08040000.
  • The bootloader successfully jumps to the application using a soft reset or in normal operation. However, after a hard reset (power cycle), the bootloader doesn't jump to the application as expected.

Here's the goto_application function I am using in the bootloader:

 

void goto_application(void)
{
/* Disable all interrupts */
__disable_irq();

/* Set the application's vector table address */
SCB->VTOR = 0x08040000UL;

/* Get the application reset handler address */
void (*app_reset_handler)(void) = (void (*)(void))(*((volatile uint32_t*)(0x08040004UL)));

/* Set the application's main stack pointer (MSP) */
__set_MSP(*(volatile uint32_t*)(0x08040000UL));

/* Disable SysTick */
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;

/* Ensure changes are applied */
__DSB();
__ISB();

/* Jump to the application's reset handler */
app_reset_handler();
}

 

What I've Tried:

  1. Verified the application vector table is correctly placed at 0x08040000.
  2. Deinitialized HAL and RCC in the bootloader before jumping.
  3. Confirmed that the application's linker script starts at 0x08040000.
  4. Double-checked the option bytes to ensure boot mode settings are correct.

Problem:

  • After a power cycle, the bootloader executes but does not jump to the application.
  • In normal operation (e.g., without a power cycle), the jump works fine.
2 REPLIES 2
SofLit
ST Employee

Hello,

When sharing a code please use </> button to paste your code. See this post. (I've edited your post).

Thank you for your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: Be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.
gbm
Lead III

1. What MCU type exactly?

2. How do you know that "it doesn't jump"? Maybe it's stuck in your app in some loop waiting for something, like clock startup?

3. As it was discussed in many topics on bootloaders, the safest way to invoke the app is to jump to it at the very beginning of a bootloader, based on some flag set in RTC/Backup registers or in non-initilaized RAM location. To invoke the app, set the flag and issue soft reset - this way you ensure that all the peripherals are in the default state.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice