diff --git a/src/driver/mcu/stm32/reset.c b/src/driver/mcu/stm32/reset.c index 0753dc8e5..505d9ace8 100644 --- a/src/driver/mcu/stm32/reset.c +++ b/src/driver/mcu/stm32/reset.c @@ -46,11 +46,22 @@ __attribute__((__used__)) void system_check_for_bootloader() { case RESET_BOOTLOADER_MAGIC: { backup_register_write(0); -#ifdef STM32G4 + __disable_irq(); + + SysTick->CTRL = 0; + HAL_RCC_DeInit(); +#ifdef STM32G4 __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH(); #endif + for (uint8_t i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) + NVIC->ICER[i] = 0xFFFFFFFF; + for (uint8_t i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) + NVIC->ICPR[i] = 0xFFFFFFFF; + + __enable_irq(); + void (*DfuBootJump)(void) = (void (*)(void))(*((uint32_t *)(BOOTLOADER_OFFSET + 4))); __set_MSP(*((uint32_t *)BOOTLOADER_OFFSET)); DfuBootJump();