Why Doesn't My STM32 Bootloader Jump to the Application After a Hard Reset?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-12 10:05 PM - last edited on ‎2025-01-13 4:53 AM by mƎALLEm
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:
- Verified the application vector table is correctly placed at 0x08040000.
- Deinitialized HAL and RCC in the bootloader before jumping.
- Confirmed that the application's linker script starts at 0x08040000.
- 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.
- Labels:
-
Bootloader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-13 3:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-13 4:33 AM
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.
