From a6c2477aca71c0dd3aed21d34009aecf056a6f4a Mon Sep 17 00:00:00 2001 From: Yicheng Li Date: Tue, 8 Oct 2019 17:31:56 -0700 Subject: chip/stm32: Fix bug that LPTIM_PERIOD_US became unsigned long. Due to a refactoring of bit shifts (BIT macro), LPTIM_PERIOD_US changed from int to unsigned int, which in turn changed behavior of set_lptim_event. This causes a watchdog reset during a long suspend. In particular, this caused the stm32h7 FPMCU to reboot during long suspend and fingerprint unlock to not work. BUG=b:140538084 BRANCH=none TEST=verified that FPMCU no longer reboots during deep sleep, fingerprint unlock works after deep sleeping for a whole night. Change-Id: If2ed9cb94aad4216012e28ffec530bc4ce858093 Signed-off-by: Yicheng Li Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1854785 Reviewed-by: Nicolas Norvez --- chip/stm32/clock-stm32h7.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/chip/stm32/clock-stm32h7.c b/chip/stm32/clock-stm32h7.c index a3ebb9aa36..f41a76b87a 100644 --- a/chip/stm32/clock-stm32h7.c +++ b/chip/stm32/clock-stm32h7.c @@ -32,7 +32,13 @@ * with /4 prescaler (2^2): period 125 us, full range ~8s */ #define LPTIM_PRESCALER_LOG2 2 -#define LPTIM_PRESCALER BIT(LPTIM_PRESCALER_LOG2) +/* + * LPTIM_PRESCALER and LPTIM_PERIOD_US have to be signed, because we compare + * them to an int to decide whether to go to deep sleep. Simply using BIT() + * makes them unsigned, which causes a bug in deep sleep behavior. + * TODO(b/140538084): Explain exactly what the bug is. + */ +#define LPTIM_PRESCALER ((int)BIT(LPTIM_PRESCALER_LOG2)) #define LPTIM_PERIOD_US (SECOND / (STM32_LSI_CLOCK / LPTIM_PRESCALER)) /* -- cgit v1.2.1