2022-06-29 02:39 AM
Hi there,
using the STM32U585 I try to jump from application into bootloader. Could somebody please share some code that I could use, instead of this piece that does not do its job?
void JumpToBootloader(void)
{
void (*SysMemBootJump)(void);
volatile uint32_t addr = 0x0BF90000;
HAL_I2C_DeInit(&hi2c1);
HAL_I2C_DeInit(&hi2c2);
USBD_DeInit(&hUsbDeviceFS);
HAL_RCC_DeInit();
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
__disable_irq();
SYSCFG->CFGR1 = 0x01;
__DSB();
SysMemBootJump = (void (*)(void)) (*((uint32_t *)(addr + 4)));
__set_MSP(*(uint32_t *)addr);
SysMemBootJump();
}
Besides: do I have to pay attention to something special, when using FreeRTOS?
Thanks in advance,
2022-06-29 03:51 AM
Deinitialising everything may be difficult. I.m.h.o. best thing is to have a switch early in the startup code before RAM is initialized or use RAM that is not initialized. When jump to bootloader is needed, set some magic in ram and reset. When bootswitch sees the magic, it remove the magic and jumps to bootloader. When no magic is seen, eventually also check for valid code and when not found, jump to bootloader too.
2022-06-29 04:08 AM
Thank you Uwe,
would you please share a link with an example?
Best,
Kai
2022-06-29 04:29 AM
https://github.com/bl*ckm*g*c-debug/bl*ckm*g*c/blob/main/src/platforms/f072/platform.c
Sorry for the obfuscation, but big brother blocks w/o obfuscation...
2022-06-29 04:38 AM
tried now this:
/*...snip*/
/* Call the clock system initialization function.*/
bl SystemInit
/* Call static constructors */
bl __libc_init_array
/* check for a magic constant in RAM, if present brach to bootloader */
LDR R0, =0x2000FFF0
LDR R1, =0xDEADBEEF
LDR R2, [R0, #0]
STR R0, [R0, #0] /* Invalidate*/
CMP R2, R1
BEQ Reboot_Loader
/* Call the application's entry point.*/
bl main
LoopForever:
b LoopForever
.size Reset_Handler, .-Reset_Handler
Reboot_Loader:
LDR R0, =0x0BF90000
LDR SP,[R0, #0]
LDR R0,[R0, #4]
BX R0
/*...snip*/
and this:
void JumpToBootloader(void)
{
*((unsigned long *)0x2000FFF0) = 0xDEADBEEF;
NVIC_SystemReset();
}
took from: 'https://www.mikrocontroller.net/articles/STM32_jump_to_bootloader'.
Debugging this, I can see the jump to 'Reboot_Loader:' after Reset and then the jump to the bootloader's section.
Using it without debugger, it even works!
Thanks for the hint, Uwe!
2022-07-02 07:58 AM
Hello @KHofm.1 ,
This document, AN2606 STM32 microcontroller system memory boot mode, gives all the details about: How to jump in bootloader from user application.
Note that on some STM32 with flash empty check mechanism, it's not possible to jump in the bootloader from your application running in the user flash.
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Imen