In the past, you need modify rtc_api.c in mbed-dev source code. From this revision, you can just use RTC function all of conditions (Normal, Reset, Stand-by, Power OFF).

Note

From now on, you do NOT need any modification for mbed-dev library because STM team updates rtc_api.c source code and support RTC function under reset & standby condition includes power off condition (You need additional VBAT back-up hardware).

Please refer following NOTE information.
/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Sat Mar 06 08:29:51 2021 +0000
Parent:
13:c1f984932e98
Commit message:
run on mbed-os6.8.0

Changed in this revision

check_revision.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
uart_as_stdio/uart_as_stdio.cpp Show annotated file Show diff for this revision Revisions of this file
uart_as_stdio/uart_as_stdio.h Show annotated file Show diff for this revision Revisions of this file
--- a/check_revision.cpp	Mon Jan 11 07:55:27 2021 +0000
+++ b/check_revision.cpp	Sat Mar 06 08:29:51 2021 +0000
@@ -1,22 +1,22 @@
 /*
  * Check Mbed revision
  *
- * Copyright (c) 2019,'20, '21 Kenji Arai / JH1PJL
+ * Copyright (c) 2019,'20,'21 Kenji Arai / JH1PJL
  *  http://www7b.biglobe.ne.jp/~kenjia/
  *  https://os.mbed.com/users/kenjiArai/
  *      Created:    July      17th, 2019
- *      Revised:    January    6th, 2021
+ *      Revised:    March      5th, 2021
  */
 
 #include "mbed.h"
- 
-//    RUN ONLY ON mbed-os-6.6.0
-//      https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-6.6.0
+
+//    RUN ONLY ON mbed-os-6.8.0
+//      https://github.com/ARMmbed/mbed-os/releases/tag/mbed-os-6.8.0
 #if (MBED_MAJOR_VERSION == 6) &&\
-    (MBED_MINOR_VERSION == 6) &&\
+    (MBED_MINOR_VERSION == 8) &&\
     (MBED_PATCH_VERSION == 0)
 #else
-#   error "Please use mbed-os-6.6.0"
+#   error "Please use mbed-os-6.8.0"
 #endif
 
 void print_revision(void)
--- a/main.cpp	Mon Jan 11 07:55:27 2021 +0000
+++ b/main.cpp	Sat Mar 06 08:29:51 2021 +0000
@@ -6,7 +6,7 @@
  *  http://www7b.biglobe.ne.jp/~kenjia/
  *  https://os.mbed.com/users/kenjiArai/
  *      Created: January   17th, 2015
- *      Revised: January   11th, 2021
+ *      Revised: March      6th, 2021
  */
 
 /*  mbed library now suports RTC continuous operation at Reset & Power ON/OFF
@@ -51,11 +51,13 @@
 
 //  Include --------------------------------------------------------------------
 #include "mbed.h"
+#include "uart_as_stdio.h"
 
 //  Definition -----------------------------------------------------------------
 #if defined(TARGET_DISCO_F746NG)  \
  || defined(TARGET_NUCLEO_F746ZG) \
  || defined(TARGET_DISCO_F769NI)  \
+ || defined(TARGET_DISCO_F469NI)  \
  || defined(TARGET_NUCLEO_F446ZE) \
  || defined(TARGET_NUCLEO_H743ZI2)
 #define PUSHED_SW   1   // Active high
@@ -67,13 +69,11 @@
 #define PUSHED_SW   0   // Active low
 #endif
 
-#define LONGLONGTIME    2147483647
+#define LONGLONGTIME    2147483647s
 
 //  Object ---------------------------------------------------------------------
 DigitalIn userSW(USER_BUTTON);
 DigitalOut myled(LED1);                 // Indicate the sampling period
-// Create a BufferedSerial object to be used by the system I/O retarget code
-static BufferedSerial pc(USBTX, USBRX, 9600);
 
 //  RAM ------------------------------------------------------------------------
 
@@ -102,9 +102,9 @@
     puts("\r\n\r\nTest Nucleo RTC Function.");
     print_revision();
     myled = !myled;
-    thread_sleep_for(500);
+    ThisThread::sleep_for(500ms);
     myled = !myled;
-    thread_sleep_for(500);
+    ThisThread::sleep_for(500ms);
     while(true) {
         seconds = time(NULL);
         strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds));
@@ -114,15 +114,15 @@
         puts("\r");
         wait_counter = 0;
         while (seconds == time(NULL)) {
-            if (pc.readable() == 1) {
-                pc.read(buf,1);  // dummy read
+            if (readable() == 1) {
+                buf[0] = getc();    // dummy read
                 time_enter_mode();
             }
             if (userSW == PUSHED_SW) {  // goto sleep
                 while (userSW == PUSHED_SW) {
-                    thread_sleep_for(10);
+                    ThisThread::sleep_for(10ms);
                 }
-                thread_sleep_for(10);
+                ThisThread::sleep_for(10ms);
                 puts("Entered the standby mode. ");
 #if defined(TARGET_NUCLEO_F303K8) || defined(TARGET_NUCLEO_L432KC)
                 puts("Please change A0 level for wake-up(Reset).");
@@ -132,43 +132,28 @@
                 myled = 0;
  
                 InterruptIn usr_sw(USER_BUTTON);
-                thread_sleep_for(1000);
+                ThisThread::sleep_for(1s);
                 DigitalIn dmy0(LED1);
                 DigitalIn dmy1(USBTX);
                 DigitalIn dmy2(USBRX);
                 usr_sw.fall(&usr_sw_irq); // actual push or chattering
-                thread_sleep_for(LONGLONGTIME);
+                sleep_preparation();
+                ThisThread::sleep_for(LONGLONGTIME);
             }
-            thread_sleep_for(50);
+            ThisThread::sleep_for(50ms);
             if (++wait_counter > (2000 / 50)) {
                 break;
             }
         }
         // delete previous strings
-        printf("\033[2A");
-        puts("");   // null
-        uint8_t n = strlen(msg0) + strlen(msg1);
-        memset(buf, ' ', 64);
-        if (n > 64) {
-            n -= 64;
-            pc.write(buf, 64);
-        }
-        if (n > 64) {
-            pc.write(buf, 64);
-        } else {
-            pc.write(buf, n);
-        }
-        printf("\033[G");
+        // https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection
+        // \33[ = CSI sequences, 1A=Cursor Up (one line), 2K=Erase in Line(all)
+        //                       G=Cursor Horizontal Absolute
+        printf("\33[1A\033[2K\033[G");
         myled = !myled;
     }
 }
 
-//  the system I/O retarget
-FileHandle *mbed::mbed_override_console(int fd)
-{
-    return &pc;
-}
-
 //  Interrupt for wake up
 static void usr_sw_irq(void)
 {
@@ -182,13 +167,12 @@
     char linebuf[64];
 
     puts("Set time into RTC.");
-    puts(" e.g. >21 1 6 12 34 56 -> January 06,'21, 12:34:56");
+    puts(" e.g. >21 3 3 3 33 33 -> March  03,'21, 03:33:33");
     puts(" If time is fine, just hit enter key.");
-    linebuf[0] = '>';
-    pc.write(linebuf, 1);
+    putc('>');
     ptr = linebuf;
     get_line(ptr, sizeof(linebuf));
-    puts("\r");
+    putc('\r');
     chk_and_set_time(ptr);
 }
 
@@ -251,12 +235,10 @@
 static void get_line(char *buff, int32_t len)
 {
     char c;
-    char bf[8];
     int32_t idx = 0;
 
     for (;;) {
-        pc.read(bf, 1);
-        c = bf[0];
+        c = getc();
         //printf("0x%x \r\n", c);
         if (c == '\r') {
             buff[idx++] = c;
@@ -266,16 +248,15 @@
             idx--;
             const char bf_bs[] =
             {0x1b, '[', '1', 'D', ' ', 0x1b, '[', '1', 'D'};
-            pc.write(bf_bs, 9);
+            printf(bf_bs, 9);
         }
         if (((uint8_t)c >= ' ') && (idx < len - 1)) {
             buff[idx++] = c;
-            pc.write(bf, 1);
+            putc(c);
         }
     }
     buff[idx] = 0;
-    bf[0] = '\n';
-    pc.write(bf, 1);
+    putc('\n');
 }
 
 //  Check key input strings and set time
--- a/mbed-os.lib	Mon Jan 11 07:55:27 2021 +0000
+++ b/mbed-os.lib	Sat Mar 06 08:29:51 2021 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#84d991342a41011fc417aab62c0f5a8832f1d18f
+https://github.com/ARMmbed/mbed-os/#bfde5aa1e74802771eaeacfa74789f71677325cb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uart_as_stdio/uart_as_stdio.cpp	Sat Mar 06 08:29:51 2021 +0000
@@ -0,0 +1,53 @@
+/*
+ * mbed Application program
+ *      Redirect Standard Input/Output
+ *
+ * Copyright (c) 2021 Kenji Arai / JH1PJL
+ *  http://www7b.biglobe.ne.jp/~kenjia/
+ *  https://os.mbed.com/users/kenjiArai/
+ *      Created:    January   13th, 2021
+ *      Revised:    March      5th, 2021
+ */
+
+//  Include --------------------------------------------------------------------
+#include "mbed.h"
+
+//  Definition -----------------------------------------------------------------
+
+//  Constructor ----------------------------------------------------------------
+static BufferedSerial pc(USBTX, USBRX, 9600);
+
+//  RAM ------------------------------------------------------------------------
+
+//  ROM / Constant data --------------------------------------------------------
+
+//  Function prototypes --------------------------------------------------------
+
+//------------------------------------------------------------------------------
+//  Control Program
+//------------------------------------------------------------------------------
+uint8_t readable()
+{
+    return pc.readable();
+}
+
+void putc(uint8_t c)
+{
+    char dt[4];
+    dt[0] = (char)c;
+    pc.write(dt, 1);
+}
+
+uint8_t getc()
+{
+    char dt[4];
+    pc.read(dt, 1);
+    return (uint8_t)dt[0];
+}
+
+//https://os.mbed.com/users/kenjiArai/code/Check_DeepSleep_os6/
+void sleep_preparation()
+{
+    pc.enable_input(false);
+    sleep_manager_can_deep_sleep();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/uart_as_stdio/uart_as_stdio.h	Sat Mar 06 08:29:51 2021 +0000
@@ -0,0 +1,18 @@
+/*
+ * mbed Application program
+ *      Redirect Standard Input/Output
+ *
+ * Copyright (c) 2021 Kenji Arai / JH1PJL
+ *  http://www7b.biglobe.ne.jp/~kenjia/
+ *  https://os.mbed.com/users/kenjiArai/
+ *      Created:    January   13th, 2021
+ *      Revised:    January   14th, 2021
+ */
+
+#include "mbed.h"
+
+//  Function prototypes --------------------------------------------------------
+uint8_t readable(void);
+void putc(uint8_t c);
+uint8_t getc(void);
+void sleep_preparation(void);