Jumping to system bootloader from FreeRTOS application code - STM32U5A5
Hello Forum,
I'm trying to get a simple application, running on a NUCLEO-U5A5ZJ-Q dev board, to jump to the system bootloader from FreeRTOS. I've also got AN2606 to hand (application note for the STM bootloader) and RM0456 (STM32 U5 reference manual). I have been following this guide. How to jump to system bootloader from application ... - STMicroelectronics Community
According to the guide and reference manuals the bootloader base address on my MCU (STM32U5A5) is at 0x0BF90000. The 32 bit word at that address is the stack location, and the 32bit work at 0x0BF90004 is the entry point for the bootloader. In my setup values are read as:
- 0x200034E8 - this is valid memory (stack)
- 0x0BF98C39 - this is unexpected as lots of the internet says this should be 0x0BF99EFE but I'm guessing this is actually OK.
I currently have this code:
#define BOOTLOADER_BASE 0x0BF90000
typedef struct boot_vectable
{
uint32_t Initial_SP;
void (*Reset_Handler)(void);
}
boot_vectable_t;
void JumpToBootloader()
{
boot_vectable_t* pBootVec = (boot_vectable_t*)(BOOTLOADER_BASE);
// Stop FreeRTOS
vTaskSuspendAll();
taskDISABLE_INTERRUPTS();
/* Disable all interrupts */
__disable_irq();
/* Disable Systick timer */
SysTick->CTRL = 0;
/* Set the clock to the default state */
HAL_RCC_DeInit();
/* Clear Interrupt Enable Register & Interrupt Pending Register */
const uint8_t NVIC_count = sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]);
for (uint8_t i = 0; i < NVIC_count; i++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
/* Re-enable all interrupts */
__enable_irq();
// Set the MSP
__set_MSP(pBootVec->Initial_SP);
// Jump to bootloader
pBootVec->Reset_Handler();
}I am calling `JumpToBootloader()` this from this simple task.
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN DefaultTask */
for(;;)
{
if (BootloaderRequested)
{
BootloaderRequested = false;
JumpToBootloader();
}
else
{
BSP_LED_Toggle(LED_GREEN);
}
osDelay(500);
}
/* USER CODE END DefaultTask */
}Where `BootloaderRequested` is set to true in an ISR when the BLUE button on the board is pressed. Unfortunately it doesn't work and I can't figure out what's missing/wrong. The code gets to line 42 (pBootVec->Reset_Handler()) but then something goes wrong and the BL doesn't run.
I'd appreciate any help/thoughts anyone can offer.
DD
