Skip to content

Commit 1ea807a

Browse files
committed
stm32/mboot: Only exit on timeout if application valid.
Check application validity before exiting bootloader due to timeout. If application is invalid, disable timeout and remain in bootloader indefinitely to avoid reset loop. Signed-off-by: Andrew Leech <[email protected]>
1 parent 27fac38 commit 1ea807a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ports/stm32/mboot/main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,14 @@ void stm32_main(uint32_t initial_r0) {
17451745
// Capture systick_ms once to avoid race condition with ISR
17461746
uint32_t current_ms = systick_ms;
17471747
if (dfu_context.timeout_active && current_ms >= MBOOT_DFU_TIMEOUT_MS) {
1748-
dfu_context.leave_dfu = true;
1748+
// Only exit if application is valid (avoid reset loop with invalid app)
1749+
uint32_t msp = *(volatile uint32_t *)APPLICATION_ADDR;
1750+
if ((msp & APP_VALIDITY_BITS) == 0) {
1751+
dfu_context.leave_dfu = true;
1752+
} else {
1753+
// Application invalid, disable timeout and stay in bootloader
1754+
dfu_context.timeout_active = false;
1755+
}
17491756
}
17501757
#endif
17511758
}

0 commit comments

Comments
 (0)