Ensure Cortex-M reset wakes device from sleep (wfi/wfe)
[fw/openocd] / src / target / cortex_m.c
index 74505a85e1b669168640eaae4cf0ec7fa1f8b9c3..81d6ccf4f5a4ed3d69212ed3f5072a13151f7f40 100644 (file)
@@ -973,6 +973,14 @@ static int cortex_m3_assert_reset(struct target *target)
                        return retval;
        }
 
+       /* If the processor is sleeping in a WFI or WFE instruction, the
+        * C_HALT bit must be asserted to regain control */
+       if (cortex_m3->dcb_dhcsr & S_SLEEP) {
+               retval = mem_ap_write_u32(swjdp, DCB_DHCSR, DBGKEY | C_HALT | C_DEBUGEN);
+               if (retval != ERROR_OK)
+                       return retval;
+       }
+
        retval = mem_ap_write_u32(swjdp, DCB_DCRDR, 0);
        if (retval != ERROR_OK)
                return retval;