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?

20 REPLIES 20

sure, I use 0x08003000 as Flash origin:

/* Memories definition */
MEMORY
{
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 112K
  FLASH    (rx)    : ORIGIN = 0x8003000,   LENGTH = 244K
}

 

I'm sorry, I don't understand

It was already uncommented:

/************************* Miscellaneous Configuration ************************/
/* Note: Following vector table addresses must be defined in line with linker
         configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
     anywhere in Flash or Sram, else the vector table is kept at the automatic
     remap of boot address selected */
#define USER_VECT_TAB_ADDRESS

#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
     in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS   SRAM_BASE       /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS   FLASH_BASE      /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/

 

I don't understand why you don't understand the 2 simple steps

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.

@Yves Bmnt wrote:

It was already uncommented:

 

/************************* Miscellaneous Configuration ************************/
/* Note: Following vector table addresses must be defined in line with linker
         configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
     anywhere in Flash or Sram, else the vector table is kept at the automatic
     remap of boot address selected */
#define USER_VECT_TAB_ADDRESS

#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
     in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS   SRAM_BASE       /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS   FLASH_BASE      /*!< Vector Table base address field.
                                                     This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET         0x00000000U     /*!< Vector Table base offset field.
                                                     This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/

 

 


I only see that you did step 1.

 

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.

you are right, I read your message too fast!

It works fine now, thanks a lot :)

In my other projects using STM32L010 and STM32F446, I didn't change the VECT_TAB_OFFSET and the jump to app works fine, but the #define USER_VECT_TAB_ADDRESS is still commented.

Thanks again for your help!

Just commented the #define USER_VECT_TAB_ADDRESS now in my STM32G491 project, and the jump works fine this way too

FShah.1
Associate III

Hi,

I will appreciate your prompt response. I found the issue in my code, and now the CRC is working correctly.

However, another problem has arisen. As you know, I am working on a bootloader program. My application code is successfully transferred from the source to the controller via the serial port. But when the code attempts to set the reset handler and jump to the application code, it is failing.

I am using the STM32F446 microcontroller.

First, I copied the code to memory address 0x08040000. Then, bootloader copied to the application memory address, which is 0x08020000. The CRC of the application on the host side, the CRC at address 0x08040000, and the CRC at address 0x08020000 are all the same.

I checked the memory locations, and they have the same data. However, the jump_to_application function is not successful.

Blink LED Application: I changed the Flash address in linker file

/* Memories definition */

MEMORY

{

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K

FLASH (rx) : ORIGIN = 0x08020000, LENGTH = 128K

}

 

/*!< Uncomment the following line if you need to relocate the vector table

anywhere in Flash or Sram, else the vector table is kept at the automatic

remap of boot address selected */

#define USER_VECT_TAB_ADDRESS

 

#if defined(USER_VECT_TAB_ADDRESS)

/*!< Uncomment the following line if you need to relocate your vector Table

in Sram else user remap will be done in Flash. */

/* #define VECT_TAB_SRAM */

#if defined(VECT_TAB_SRAM)

#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.

This value must be a multiple of 0x200. */

#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

#else

#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.

This value must be a multiple of 0x200. */

#define VECT_TAB_OFFSET 0x00020000U /*!< Vector Table base offset field.

This value must be a multiple of 0x200. */

#endif /* VECT_TAB_SRAM */

#endif /* USER_VECT_TAB_ADDRESS */

 

 

Bootloader: jump_to_application function:

static void goto_application(void)
{
 
printf("Gonna Jump to Application\r\n");
 
 
 
// Set the Vector Table Offset Register (VTOR) to the address of the application
SCB->VTOR = ETX_APP_FLASH_ADDR;
// Get the application reset handler address
void (*app_reset_handler)(void) = (void*)(*((volatile uint32_t*) (ETX_APP_FLASH_ADDR + 4U)));//Application starting address
// Optionally turn off the LED
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);
 
/* Reset the Clock */
HAL_RCC_DeInit();
HAL_DeInit();
__set_MSP(*(volatile uint32_t*) ETX_APP_FLASH_ADDR);
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
 
/* Jump to application */
app_reset_handler();    //call the app reset handler
}
Kindly advise on how to solve this problem. I am very close to the finish line, but something I am doing seems to be wrong! Please help. Thank you
 

See my remark in this thread, below the main article:

https://community.st.com/t5/stm32-mcus/how-to-share-an-api-between-a-bootloader-and-an-application/ta-p/736681

- check the code generated by the compiler, maybe change optimization level.

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