diff --git a/src/target/cortexm.c b/src/target/cortexm.c index fd1bde1e..00668d51 100644 --- a/src/target/cortexm.c +++ b/src/target/cortexm.c @@ -269,16 +269,17 @@ static bool cortexm_forced_halt(target *t) platform_srst_set_val(false); uint32_t dhcsr = 0; uint32_t start_time = platform_time_ms(); + const uint32_t dhcsr_halted_bits = CORTEXM_DHCSR_S_HALT | CORTEXM_DHCSR_S_REGRDY | + CORTEXM_DHCSR_C_HALT | CORTEXM_DHCSR_C_DEBUGEN; /* Try hard to halt the target. STM32F7 in WFI needs multiple writes!*/ while (platform_time_ms() < start_time + cortexm_wait_timeout) { dhcsr = target_mem_read32(t, CORTEXM_DHCSR); - if (dhcsr == (CORTEXM_DHCSR_S_HALT | CORTEXM_DHCSR_S_REGRDY | - CORTEXM_DHCSR_C_HALT | CORTEXM_DHCSR_C_DEBUGEN)) + if ((dhcsr & dhcsr_halted_bits) == dhcsr_halted_bits) break; target_halt_request(t); } - if (dhcsr != 0x00030003) + if ((dhcsr & dhcsr_halted_bits) != dhcsr_halted_bits) return false; return true; }