Enter Standby mode then wake up(only restart) by RTC timer

Dependencies:   WakeUp_STM32

/users/kenjiArai/notebook/standby-mode-current-consumption-on-nucleo-f446re/

IDD Jumper(JP6)
ModeMbed-OSBoardIDD Current(sleep)IDD Current(Normal(*1))
DeepSleep0s5.15.1Nucleo-L152RE4.23uA5mA to 8mA
^0s6.6.0^4.22uA4mA to 7mA
StandBy0s5.15.1^3.90uA4mA to 7mA
^0s6.6.0^3.90uA4mA to 7mA
DeepSleep0s5.15.1Nucleo-L476RG2.13uA7mA to 10mA
^0s6.6.0^2.23uA7mA to 10mA
StandBy0s5.15.1^-uA(*2)-mA(*2)
^0s6.6.0^-uA(*2)-mA(*2)
DeepSleep0s5.15.1Nucleo-F411RE1.91mA(*3)7mA to 10mA
^0s6.6.0^1.65mA(*3)7mA to 10mA
StandBy0s5.15.1^3.35uA7mA to 10mA
^0s6.6.0^3.40uA7mA to 9mA
DeepSleep0s5.15.1Nucleo-F446RE1.67mA(*3)14mA to 17mA
^0s6.6.0^1.76mA(*3)14mA to 16mA
StandBy0s5.15.1^3.42uA14mA to 17mA
^0s6.6.0^3.42uA14mA to 16mA

(*1)-> LED1 Blinky every 1sec and change LED1 current
(*2)-> Could NOT make proper program and could NOT measure
(*3)-> NOT uA but mA
All Nucleo boards are stand alone condition(not additional circuit).
Equipment: DMM6500

/users/kenjiArai/code/Check_DeepSleep_os5/
/users/kenjiArai/code/Check_DeepSleep_os6/
/users/kenjiArai/code/Check_StandBy_os5/
/users/kenjiArai/code/Check_StandBy_os6/

Revision:
4:ce30d249515e
Parent:
3:4cdb02c5bd94
Child:
5:3da1fdb725d9
--- a/main.cpp	Fri Mar 13 03:33:37 2020 +0000
+++ b/main.cpp	Sat Jan 16 06:11:29 2021 +0000
@@ -1,25 +1,35 @@
 /*
  * Mbed Application program
- *  Check Deep Sleep Mode
+ *  Check StandBy Mode
  *
- * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * Copyright (c) 2020,'21 Kenji Arai / JH1PJL
  *  http://www7b.biglobe.ne.jp/~kenjia/
  *  https://os.mbed.com/users/kenjiArai/
  *      Revised:    March     12th, 2020
- *      Revised:    March     13th, 2020
+ *      Revised:    January   16th, 2020
  */
 
 /*
     Reference information:
         https://forums.mbed.com/t/how-to-deep-sleep/7551
+        https://os.mbed.com/users/kenjiArai/code/Check_DeepSleep_os6/
+        https://os.mbed.com/users/kenjiArai/code/Check_StandBy_os6/
 
-    Tested on
-        Nucleo-F401RE
-        Nucleo-F411RE
-        Nucleo-F446RE
-        Nucleo-L053R8   only os2
-        Nucleo-L073RZ   only os2
-        Nucleo-L152RE
+    DEEP SLEEP MODE (Tested on with mbed-os5.15.1)
+        https://os.mbed.com/users/kenjiArai/code/Check_DeepSleep_os5/
+        Nucleo-L152RE       -> 4.23uA (Normal run = 5mA to 8mA)
+        Nucleo-L476RG       -> 2.13uA (Normal run = 7mA to 10mA)
+        Nucleo-F411RE       -> 1.91mA (not uA)(Normal run = 7mA to 10mA)
+        Nucleo-F446RE       -> 1.67mA (not uA)(Normal run = 14mA to 17mA)
+    STANDBY MODE (Tested on with mbed-os5.15.1)
+        Nucleo-L152RE       -> 3.89uA (Normal run = 5mA to 8mA)
+        Nucleo-L476RG       -> not work until today
+        Nucleo-F411RE       -> 3.35uA (Normal run = 7mA to 10mA)
+        Nucleo-F446RE       -> 3.42uA (Normal run = 14mA to 17mA)   
+
+        Current Measurement:
+         Nucleo board has IDD Jumper (JP6).
+         I measured CPU current using Digital Multi-meter DCI mode.
  */
 
 //  Include --------------------------------------------------------------------
@@ -27,14 +37,6 @@
 #include "WakeUp.h"
 
 //  Definition -----------------------------------------------------------------
-//      https://keisan.casio.jp/exec/system/1526003938
-#define DATE_20200222_222222    1582377742      // 2020/2/22 22:22:22 
-
-#if (MBED_MAJOR_VERSION == 5)
-#define WAIT_MS(x)  ThisThread::sleep_for(x)
-#else
-#define WAIT_MS(x)  wait_ms(x)
-#endif
 
 //  Constructor ----------------------------------------------------------------
 DigitalIn   my_sw(USER_BUTTON);
@@ -48,11 +50,10 @@
 //  ROM / Constant data --------------------------------------------------------
 
 //  Function prototypes --------------------------------------------------------
-void sw_irq(void);
 void time_enter_mode(void);
 void chk_and_set_time(char *ptr);
 int32_t  xatoi (char **str, int32_t *res);
-void get_line (char *buff, int len);
+void get_line (char *buff, int32_t len);
 void print_revision(void);
 
 //------------------------------------------------------------------------------
@@ -69,17 +70,12 @@
     printf("\r\nCheck current consumption at Deep-sleep mode.\r\n");
     print_revision();
     seconds = time(NULL);
-    if (seconds < DATE_20200222_222222) {
-        strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds));
-        pc.printf("[Time] %s\r\n", buf);
-        time_enter_mode();
-    }
     while (my_sw == 0) {;}
-    WAIT_MS(10);
+    ThisThread::sleep_for(10);
     while (true) {
         t.reset();
         t.start();
-        if ((my_sw == 0) || (loop_count > 20)) {
+        if ((my_sw == 0) || (loop_count > 10)) {
             DigitalIn dmy0(LED1);
             DigitalIn dmy1(USBTX);
             DigitalIn dmy2(USBRX);
@@ -92,11 +88,16 @@
         strftime(buf, 50, "%H:%M:%S -> ", localtime(&seconds));
         pc.printf("%s", buf);
         pc.printf(
-            "analog = %4.3f, loop_time=%3d, counter=%4d\r\n",
+            "analog = %4.3f, processing time=%3d, counter=%4d\r\n",
             ain, t_pass, loop_count++
         );
         t_pass = t.read_ms();
-        WAIT_MS(1000 - t_pass);
+        ThisThread::sleep_for(1000 - t_pass);
+        if (pc.readable()) {
+            strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds));
+            pc.printf("[Time] %s\r\n", buf);
+            time_enter_mode();
+        }
     }
 }
 
@@ -105,8 +106,11 @@
     char *ptr;
     char linebuf[64];
 
+    if (pc.readable()) {
+        pc.getc();    // dummy read
+    }
     pc.printf("\r\nSet time into RTC\r\n");
-    pc.printf(" e.g. >20 2 22 22 22 22 -> February 22,'20, 22:22:22\r\n");
+    pc.printf(" e.g. >21 1 12 13 14 15 -> January 12,'21, 13:14:14\r\n");
     pc.putc('>');
     ptr = linebuf;
     get_line(ptr, sizeof(linebuf));
@@ -238,3 +242,4 @@
     *res = val;
     return 1;
 }
+