cancel
Showing results for 
Search instead for 
Did you mean: 

How to jump into internal bootloader from software in STM32L552

navidcity
Associate III

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?

8 REPLIES 8
Uwe Bonnes
Principal III

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.

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Javier1
Principal

table 147 is not the table for your microcontroller!, maaybe you have an outdated AN2606 version? mine is february 20230693W00000aIP48QAG.png 

Is this what youre looking for?

0693W00000aIP4cQAG.png 

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();�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

we dont need to firmware by ourselves, lets talk

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.

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.

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).

navidcity
Associate III

up

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();  }