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-17 07:13 PM - edited 2024-10-17 07:14 PM
Did you makes changes to the system_stm32g4xx.c file for the application?
if not,
2024-10-17 06:00 AM
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.
2024-10-17 06:32 AM - edited 2024-10-17 07:08 AM
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);
}
}
2024-10-17 07:38 AM
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.
2024-10-17 07:50 AM - edited 2024-10-17 07:52 AM
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.
2024-10-17 08:14 AM
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.
2024-10-17 08:16 AM
I placed this line right before the Jump(); but it didn't work :(
2024-10-17 11:24 AM
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:
2024-10-17 11:48 AM
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
2024-10-17 07:13 PM - edited 2024-10-17 07:14 PM
Did you makes changes to the system_stm32g4xx.c file for the application?
if not,