flash_loader: preventing unpredictable behavior when disabling interrupts
@@ -2731,7 +2731,11 @@ int stm32l1_write_half_pages(
int stlink_flashloader_start(stlink_t *sl, flash_loader_t *fl) {
- // force halt and disable interrupt
+ // According to DDI0419C, Table C1-7 firstly force halt
+ stlink_write_debug32(sl, STLINK_REG_DHCSR, STLINK_REG_DHCSR_DBGKEY |
+ STLINK_REG_DHCSR_C_DEBUGEN |
+ STLINK_REG_DHCSR_C_HALT);
+ // and only then disable interrupts
stlink_write_debug32(sl, STLINK_REG_DHCSR, STLINK_REG_DHCSR_DBGKEY |
STLINK_REG_DHCSR_C_DEBUGEN |
STLINK_REG_DHCSR_C_HALT |
