cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader jump to app not working on STM32G491

Yves Bmnt
Associate III

Hi all,

I am trying to launch the app from a bootloader code that I copied from a project on an STM32L0 and STM32F446, it worked fine there but somehow my app doesn't start on the STM32G491.

Here's the code for the jump:

 

 

static void bootloader_jump_to_app(void)
{
    uint32_t  JumpAddress = *(__IO uint32_t*)(APP_ADDRESS + 4u);

    pFunction Jump = (pFunction)JumpAddress;


    if (!bootloader_check_integrity())
    {
        bootloader_send_message("Abort\r", 8u);
        bootloader_init();
    }
    else
    {
		bootloader_send_message("Starting\r", 9u);

		HAL_FLASH_Lock(); // lock flash after memory erase + write

		HAL_RCC_DeInit();
		HAL_DeInit();

		SysTick->CTRL = 0u;
		SysTick->LOAD = 0u;
		SysTick->VAL  = 0u;

		SCB->VTOR = (__IO uint32_t)APP_ADDRESS;

		__set_MSP(*(__IO uint32_t*)APP_ADDRESS);

		Jump();
		while(1);
    }
}

 

 

I have modified my .ld file accordingly with app start address 0x08003000, I compared the memory part with the app to the bin file and it's similar, I don't understand where the problem comes from, even though I noticed some differences in the APIs between STM32L0 and G4 series, all the code examples seem to match, or maybe I missed something, can anybody help please?

1 ACCEPTED SOLUTION

Accepted Solutions

Did you makes changes to the system_stm32g4xx.c file for the application?

if not,

  • Uncomment #define USER_VECT_TAB_ADDRESS
  • change VECT_TAB_OFFSET 0x00000000U to the application address
Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

View solution in original post

20 REPLIES 20
Imen.D
ST Employee

Hello @Yves Bmnt ,

Please have a look at this article How to jump to system bootloader from application ... - STMicroelectronics Community. This will help you to jump to system bootloader from application code.

 
 
When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

thank you for your quick answer.

After reading the article, I modified my code to this, but the app doesn't run somehow. Also, I don't understand why my original code works with STM32L010 & STM32F446 but not with STM32G491.

 

 

static void bootloader_jump_to_app(void)
{
    uint32_t  JumpAddress = *(__IO uint32_t*)(APP_ADDRESS + 4u), i= 0u;

    pFunction Jump = (pFunction)JumpAddress;


    if (!bootloader_check_integrity())
    {
        bootloader_send_message("Abort\r", 8u);
        bootloader_init();
    }
    else
    {
		bootloader_send_message("Starting\r", 9u);

		HAL_FLASH_Lock(); // lock flash after memory erase + write

		/* Disable all interrupts */
		__disable_irq();

		HAL_RCC_DeInit();
		//HAL_DeInit();

		SysTick->CTRL = 0u;
		//SysTick->LOAD = 0u;
		//SysTick->VAL  = 0u;

		/* 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();

		//SCB->VTOR = (__IO uint32_t)APP_ADDRESS;

		__set_MSP(*(__IO uint32_t*)APP_ADDRESS);

		Jump();
		while(1);
    }
}

 

 

Check the assembly code generated for the above routine (your project .list file). If there is any instruction using sp register between the MSM setting code and jumping to application, it will fail. If this is the case - use -O2 optimization level, which should solve the problem. Also, leave the VTOR setting statement uncommented.

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

Noted in the AN2606:

"On devices with dual bank boot, to jump to system memory from user code the user must first remap the system memory bootloader at address 0x00000000 using SYSCFG register (except for STM32F7 series), then jump to bootloader..."

So to jump, try adding this line in your code just before jumping:

SYSCFG->MEMRMP = 0x01;

Hope this helps ! Please, let me know about your progress on this issue.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

I directly tried with O2 level, removed optimisation for my app, and also uncommented the VTOR line, but still it won't start. I have enough flash to try without optimisation for both app and bootloader if I change the app start address.

Maybe it could also come from my app, but it works fine without bootloader, the only difference is the linker file flash address.

I placed this line right before the Jump(); but it didn't work :(

Imen.D
ST Employee

Did you try to alter the linker script for the application and change the Flash origin?

As you see in AN4767 that when FB_MODE is set, the addresses are remapped:

ImenD_0-1729189135301.png

 

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Primary test start app from stlink change to your hex and address

"C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe" -c port=SWD mode=UR -d ledtest.hex -v -g 0x08004000

 

Did you makes changes to the system_stm32g4xx.c file for the application?

if not,

  • Uncomment #define USER_VECT_TAB_ADDRESS
  • change VECT_TAB_OFFSET 0x00000000U to the application address
Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.