2023-03-07 02:59 AM
Hi,
recently I changed my microcontroller from STM32L152 to STM32L552. In L1 I was using the code in the following link to activate the internal bootloader.
https://community.st.com/s/question/0D50X00009XkeeWSAR/stm32l476rg-jump-to-bootloader-from-software
But apparently that piece of code is not working on STM32L552. Actually by looking into aplication note (AN2606) in "table 153. STM32L552xx/562xx configuration in system memory boot mode" in system memory row it isn't stated that system memory contains the bootloader firmware.
I was wondering how I can activate internal bootloader in the software?
Solved! Go to Solution.
2024-08-19 10:11 AM
void Jump_App(void)
{
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
__DSB();
__ISB();
__enable_irq();
SCB->VTOR =MAIN_PROGRAM_START_ADDRESS;
jumpAddress = *(__IO uint32_t*) (MAIN_PROGRAM_START_ADDRESS + 4);
Jump_To_Application = (pFunction) jumpAddress;
__set_MSP(*(__IO uint32_t*) MAIN_PROGRAM_START_ADDRESS);
Jump_To_Application();
}
its work at STM32L552 for program jump to enother app
2023-03-07 08:44 AM
It has been pointed out many times here that it is better to reset the system and have a switch early in the boot process that decides to start the bootloader or the application.
2023-03-07 08:49 AM
>> was wondering how I can activate internal bootloader in the software?
Check the address of the ROM, map it if necessary, and then do a control transfer, using usual MCU methods.
Simple enough in assembler, function pointers in C
2023-03-07 09:17 AM
table 147 is not the table for your microcontroller!, maaybe you have an outdated AN2606 version? mine is february 2023
Is this what youre looking for?
So the code you need would be:
typedef void (*pFunction)(void);
pFunction JumpToApplication;
uint32_t JumpAddress;
HAL_RCC_DeInit();
SysTick->CTRL = 0;SysTick->LOAD = 0;
SysTick->VAL = 0;
/** * Step: Disable all interrupts */
__disable_irq();
/* ARM Cortex-M Programming Guide to Memory Barrier Instructions.*/
__DSB();
__HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
/* Remap is bot visible at once. Execute some unrelated command! */
__DSB();
__ISB();
JumpToApplication = (void (*)(void)) (*((uint32_t *)(0x0BF90000+ 4)));
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) 0x0BF90000);JumpToApplication();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2023-03-07 10:07 AM
Thanks for your comment.
My bad. Mine is actually up to date too. I wrote the wrong table number. I'll fix it.
And if you look at the system memory row. It doesn't state that it contains bootloader firmware.
About your suggested code snippet:
That's really similar to the code snippet that I use for L1 but in L5 it isn't working. The point is this code snippet doesn't even compile. Because __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH macro is not defined in L5. __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH macro modifies SYSCFG register and set memory remap bits to 01 which is system flash memory mapped to 0x0. In L5 SYSCFG doesn't have that feature anymore.
2023-03-07 10:17 AM
Thanks for your reply.
My question is not about software design. Suppose that I have that switch and after reset it's decided to start the bootloader. Now what is the process of starting internal (jumping into) bootloader in L5?
The process that I've used for L1 isn't working for L5 and I couldn't find any solution that is suitable for L5.
2023-03-07 10:31 AM
Thanks for your reply.
Actually bootloader in L5 is in another flash (system flash) so definitely we need to remap that to 0x0. But SYSCFG doesn't have the remap functionality anymore and I couldn't find any register responsible for that in datasheet and reference manual.
Besides the internal bootloader is not located at the beginning system flash. At the bottom is the so called RSS (Root Security Services) then the bootloader. But most important is, this region (as far as I understand) is a secure area. I assume that Trust Zone must be enabled in order to have access to secure world.
Actually I don't want to enable Trust Zone because neither I know how to deal with this technology nor I have the time to learn it (at least for the near future).
2023-05-25 07:11 AM
up
2023-11-28 01:24 AM
Its work without remap . just call this function :
void JumpToBootloader(void) { void (*SysMemBootJump)(void); volatile uint32_t addr = 0x0BF90000; // ADDRES FOR SYSTEM BOOTLOADER HAL_RCC_DeInit(); SysTick->CTRL = 0; SysTick->LOAD = 0; SysTick->VAL = 0; __disable_irq(); SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4))); __set_MSP(*(uint32_t *)addr); SysMemBootJump(); }
2024-08-19 10:11 AM
void Jump_App(void)
{
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
__DSB();
__ISB();
__enable_irq();
SCB->VTOR =MAIN_PROGRAM_START_ADDRESS;
jumpAddress = *(__IO uint32_t*) (MAIN_PROGRAM_START_ADDRESS + 4);
Jump_To_Application = (pFunction) jumpAddress;
__set_MSP(*(__IO uint32_t*) MAIN_PROGRAM_START_ADDRESS);
Jump_To_Application();
}
its work at STM32L552 for program jump to enother app