2024-10-17 05:39 AM - edited 2024-10-17 06:35 AM
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?
Solved! Go to Solution.
2024-10-18 12:39 AM
sure, I use 0x08003000 as Flash origin:
/* Memories definition */
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 112K
FLASH (rx) : ORIGIN = 0x8003000, LENGTH = 244K
}
2024-10-18 12:40 AM
I'm sorry, I don't understand
2024-10-18 12:46 AM
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 */
/******************************************************************************/
2024-10-18 12:46 AM
I don't understand why you don't understand the 2 simple steps
2024-10-18 12:49 AM
@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.
2024-10-18 01:06 AM
you are right, I read your message too fast!
It works fine now, thanks a lot :)
2024-10-18 01:10 AM - edited 2024-10-18 01:13 AM
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!
2024-10-18 01:20 AM
Just commented the #define USER_VECT_TAB_ADDRESS now in my STM32G491 project, and the jump works fine this way too
2024-12-01 06:03 PM
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:
2024-12-02 12:32 AM
See my remark in this thread, below the main article:
- check the code generated by the compiler, maybe change optimization level.