Skip to content

Commit

Permalink
reset: clear systicks and interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Jan 5, 2025
1 parent 3a27c9e commit 78a0c55
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/driver/mcu/stm32/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 78a0c55

Please sign in to comment.