From b325538a3dedb7b89680e0d9385899638afd529e Mon Sep 17 00:00:00 2001 From: Bobby Casey Date: Mon, 22 Feb 2021 10:42:20 -0800 Subject: cortex-m: Don't execute WFI instruction if debugging Allowing the processor to sleep causes the debugger to stop working. BRANCH=none BUG=b:180144572 TEST=Monitor power per go/cros-fpmcu-source-code-docs#dragonclaw-v0_2 TEST=Icetower (pp3300_dx_mcu_mw) with no debugger connected Idle: ~44 mW Low Power Mode: ~5.5 mW TEST=Icetower (pp3300_dx_mcu_mw) with debugger connected Idle: ~75 mW Low Power Mode: ~70 mW TEST=Dragonclaw (pp3300_dx_mcu_mw) with no debugger connected Idle: ~22 mW Low Power Mode: ~1.5 mW TEST=Dragonclaw (pp3300_dx_mcu_mw) with debugger connected Idle: ~64 mW Low Power Mode: ~19 mW Signed-off-by: Bobby Casey Change-Id: I48d58395b168dc3bb0932348cd8f5ce088fc0ac9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2713754 Commit-Queue: Tom Hughes Tested-by: Tom Hughes Reviewed-by: Tom Hughes --- core/cortex-m0/cpu.h | 9 +++++++++ core/cortex-m0/task.c | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'core/cortex-m0') diff --git a/core/cortex-m0/cpu.h b/core/cortex-m0/cpu.h index 48abf916d6..0fc2e655d4 100644 --- a/core/cortex-m0/cpu.h +++ b/core/cortex-m0/cpu.h @@ -10,6 +10,7 @@ #include #include "compile_time_macros.h" +#include "debug.h" /* Macro to access 32-bit registers */ #define CPUREG(addr) (*(volatile uint32_t *)(addr)) @@ -61,4 +62,12 @@ static inline void cpu_set_interrupt_priority(uint8_t irq, uint8_t priority) (priority << prio_shift); } +static inline void cpu_enter_suspend_mode(void) +{ + /* Preserve debug sessions by not suspending when connected */ + if (!debugger_is_connected()) { + asm("wfi"); + } +} + #endif /* __CROS_EC_CPU_H */ diff --git a/core/cortex-m0/task.c b/core/cortex-m0/task.c index 5eb67c7346..4837c2dfbd 100644 --- a/core/cortex-m0/task.c +++ b/core/cortex-m0/task.c @@ -72,7 +72,7 @@ void __idle(void) * Wait for the next irq event. This stops the CPU clock * (sleep / deep sleep, depending on chip config). */ - asm("wfi"); + cpu_enter_suspend_mode(); } } #endif /* !CONFIG_LOW_POWER_IDLE */ -- cgit v1.2.1