Question
HardFault exception when jumping from application to system bootloader
Hello,
when trying to jump from my application to system bootloader, I get an HardFault exception.
This is the jumping routine that I am using, based on the following ST tutorial:
https://community.st.com/t5/stm32-mcus/how-to-jump-to-system-bootloader-from-application-code-on-stm32/ta-p/49424
#define SYSTEM_MEMORY_ADDR 0x1FFF0000
#define BOOTLOADER_ENTRY_ADDR (SYSTEM_MEMORY_ADDR + 4)
void JumpToBootloader(void)
{
ADC_HandleTypeDef hadc;
UART_HandleTypeDef huart;
SPI_HandleTypeDef hspi;
TIM_HandleTypeDef htim;
void (*f)(void);
uint8_t i;
/* Disable all interrupts */
__disable_irq();
/* Disable Systick timer */
SysTick->CTRL = 0;
/* Set the clock to the default state */
HAL_RCC_DeInit();
/* Disable all other peripherls */
hadc.Instance = ADC1;
HAL_ADC_DeInit(&hadc);
huart.Instance = USART2;
HAL_UART_DeInit(&huart);
hspi.Instance = SPI1;
HAL_SPI_DeInit(&hspi);
htim.Instance = TIM2;
HAL_TIM_Base_DeInit(&htim);
/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (i = 0; i < 5; i++)
{
NVIC->ICER[i]=0xFFFFFFFF;
NVIC->ICPR[i]=0xFFFFFFFF;
}
/* Re-enable all interrupts */
__enable_irq();
/* Set the main stack pointer to the boot loader stack */
__set_MSP(*(uint32_t *) SYSTEM_MEMORY_ADDR);
/* jump to bootloader */
f = (void (*)(void)) BOOTLOADER_ENTRY_ADDR;
f();
}
Thank you,
Daniele