Skip to main content
SBaro.11
Associate III
September 3, 2025
Question

Custom bootloader doesn't jump to app

  • September 3, 2025
  • 2 replies
  • 535 views

Hi all,

I'm trying to create a custom bootloader with openbl on rak3172 sip buil with stm32wl, so Ive used this repos here. I've just ipdate the main like this

#define APP_ADDRESS 0x08008000U


 HAL_PWR_EnableBkUpAccess();
 __HAL_RCC_RTC_ENABLE();
 init_led();

 if(get_bootloader_flag() == BOOTLOADER_MAGIC){

	 set_led_bootloader();


	 OpenBootloader_Init();

	 while (1)
	 {
		OpenBootloader_ProtocolDetection();
	 }
 }else{
	 set_led();
	 jump_to_app(APP_ADDRESS);
 }

void jump_to_app(uint32_t address)
{
	uint32_t i=0;
	void (*SysMemBootJump)(void);
	__disable_irq();

	/* Disable Systick timer */
	SysTick->CTRL = 0;

	/* Set the clock to the default state */
	HAL_RCC_DeInit();

	/* Clear Interrupt Enable Register & Interrupt Pending Register */
	for (i=0;i<5;i++)
	{
		NVIC->ICER[i]=0xFFFFFFFF;
		NVIC->ICPR[i]=0xFFFFFFFF;
	}

	/* Re-enable all interrupts */
	__enable_irq();

	/* Set up the jump to boot loader address + 4 */
	SysMemBootJump = (void (*)(void)) (*((uint32_t *) ((APP_ADDRESS + 4))));

	/* Set the main stack pointer to the boot loader stack */
	__set_MSP(*(uint32_t *)APP_ADDRESS);

	/* Call the function to jump to boot loader location */
	SysMemBootJump();
}

 

I check if I have a flag, if not jump to app. I flash bootloader with cube programmer, and after thaht I flash my app also with cube programmer at 0x08008000, to confirm I read flash with cube programmer and I'm able to see data at  0x08000000 and 0x08008000.

My linker script for my app

MEMORY
{
 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K
 RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
 FLASH (rx) : ORIGIN = 0x08008000, LENGTH = 256K - 0x8000
}

 

and system_stm32wlxx.c file

#define USER_VECT_TAB_ADDRESS
#define VECT_TAB_BASE_ADDRESS FLASH_BASE 
#define VECT_TAB_OFFSET 0x00008000U

void SystemInit(void)
{
#if defined(USER_VECT_TAB_ADDRESS)
 /* Configure the Vector Table location add offset address ------------------*/
 SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
#endif

 /* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
 SCB->CPACR |= ((3UL << (10UL*2UL))|(3UL << (11UL*2UL))); /* set CP10 and CP11 Full Access */
#endif
}


I can see my led set in my case with set_led(), but my bootloader doesn't jump to my app. What I missed?

 

EDIT: ok so if I comment __enable_irq() in jump_to_app() I'm able to see the begining f my app with UART, but app stuck at first Hal_Delay... If I uncomment __enable_irq() my app never start... What happen ?

2 replies

Technical Moderator
September 3, 2025

Hello @SBaro.11 ,

This tutorial, will help you to easily jump from application code: How to jump to system bootloader from application code on STM32 microcontrollers

"When your question is answered, please close this topic by clicking ""Accept as Solution"".ThanksImen"
SBaro.11
SBaro.11Author
Associate III
September 3, 2025

Hello @Imen.D 
I've followed this tutorial for jumping to my app just changing addr by my app starting adr but doesn't work, my custom bootloader never jump to my app

LCE
Principal II
September 3, 2025

Have you de-initialised all peripherals?

Why enable interrupts before jumping?
Just checked my working H7 jump code, I thought I disable interrupts before jumping, but I don't. 

EDIT: just tested with __disable_irq() before jump -> jump either fails, or app does not start correctly

SBaro.11
SBaro.11Author
Associate III
September 3, 2025

Hi @LCE ,


jump_to_app is a function coming from ST How to jump to system bootloader from application code on STM32 microcontrollers 

I've just try to comment __enable_irq() if I do thaht, my app start but stuck at the first Hal_delay() function. If I leave __enable_irq() my app never start from bootloader...

Tesla DeLorean
Guru
September 3, 2025

You'll want to double check what's going on in the NVIC, that SCB->VTOR is set correctly, and that the vectors in the vector table point to the correct functions.

Would strongly recommend getting some diagnostic instrumentation working, and that Error_Handler and HardFault_Handler and perhaps Default_Handler output some kind of information or illuminate different LEDs or GPIO.

Check the SysTick system handler is correctly configured, and that you don't have a mess of other PHYSICAL interrupts enabled, and pointing to handlers, with uninitialized peripheral structure/instances.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..