2025-03-03 4:29 AM - edited 2025-03-03 7:57 AM
void Flash_JumpToApp(uint32_t appAddr)
{
uint32_t appJumpAddress;
void (*GoToApp)(void);
// Disable RCC
LL_RCC_DeInit();
HAL_DeInit();
// Disable systick timer and reset it to default values
SysTick->CTRL = 0;
SysTick->LOAD = 0;
SysTick->VAL = 0;
// Disable all interrupts
__disable_irq();
/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (int i=0;i<7;i++)
{
NVIC->ICER[i]=0xFFFFFFFF;
NVIC->ICPR[i]=0xFFFFFFFF;
}
// Set addresses for Jump
SCB->VTOR = appAddr;
__set_MSP(*((volatile uint32_t*) appAddr));
__set_PSP(*((volatile uint32_t*) appAddr));
appJumpAddress = *((volatile uint32_t*)(appAddr + 4));
GoToApp = (void (*)(void))appJumpAddress;
GoToApp();
}
Then in the main app, FreeRTOS image has the following code.
SCB->VTOR = FLASH_FW_START_ADDR;
__set_MSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
__set_PSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
SCB->VTOR = FLASH_FW_START_ADDR;
__set_MSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
__set_PSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
SCB->VTOR = FLASH_FW_START_ADDR;
__set_MSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
__set_PSP(*((volatile uint32_t*) FLASH_FW_START_ADDR));
__enable_irq();
2025-03-03 5:26 AM
I've uploaded the current code to this repo, feel free to clone and test it
2025-03-03 7:55 AM
So I've decided to make a bootloader version without the FreeRTOS, because I started to recall that I had a simillar issue with STM32G0 a few years ago.
And it turned out, that it works both with FreeRTOS and HAL images.So I guess the problem is that I need to do some extra work, when performing JumpToApp from FreeRTOS application? Any suggestions what else is missing?
I've also decided to turn off this code inside the main function of bootloader, to make sure it will not affect anything.
SCB->VTOR = FLASH_BOOTLOADER_START_ADDR;
__set_MSP(*((volatile uint32_t*) FLASH_BOOTLOADER_START_ADDR));
__set_PSP(*((volatile uint32_t*) FLASH_BOOTLOADER_START_ADDR));
__enable_irq();
But it didn't help with FreeRTOS version.
The main purpose of that was to be able to perform JumpToApp inside the main app.
For now I decided to perform NVIC_SystemReset everywhere.
Why I decided to use FreeRTOS for the first time in bootloader?
That's because I wanted the code to be the same between both images.
But now I can't find a lot of examples of how others implementing FreeRTOS in their bootloaders, so maybe it was just the wrong concept from the start.
Attached the code here