From 6663a788a53ee38f2d6950fe7802eae7855e01f3 Mon Sep 17 00:00:00 2001 From: Evan Hunter Date: Fri, 12 Oct 2012 07:24:11 +1100 Subject: [PATCH] Ensure Cortex-M reset wakes device from sleep (wfi/wfe) Change-Id: Idb52ca3123bb3e2f7863ba1b82ac9b176d7cb094 Signed-off-by: Evan Hunter Reviewed-on: http://openocd.zylin.com/833 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/target/cortex_m.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 74505a85e..81d6ccf4f 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -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; -- 2.30.2