From 4d8504425a1b43a9b90a9a3b7a596e919b8cdb67 Mon Sep 17 00:00:00 2001
From: roland <roland@van-straten.org>
Date: Thu, 27 Dec 2018 18:04:00 +0100
Subject: [PATCH] stm32/modmachine: Fix reset_cause to correctly give DEEPSLEEP
 on L4 MCU.

Before this fix it returned SOFT_RESET after waking from a deepsleep
(standby).
---
 ports/stm32/modmachine.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c
index 7c8104b13..06c07812c 100644
--- a/ports/stm32/modmachine.c
+++ b/ports/stm32/modmachine.c
@@ -105,6 +105,12 @@ void machine_init(void) {
         reset_cause = PYB_RESET_DEEPSLEEP;
         PWR->CPUCR |= PWR_CPUCR_CSSF;
     } else
+    #elif defined(STM32L4)
+    if (PWR->SR1 & PWR_SR1_SBF) {
+        // came out of standby
+        reset_cause = PYB_RESET_DEEPSLEEP;
+        PWR->SCR |= PWR_SCR_CSBF;
+    } else
     #endif
     {
         // get reset cause from RCC flags
-- 
GitLab