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?

4 REPLIES 4
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