RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

drivers/rtt_rtc: add option to not attempt to retain time across reboots

Open benpicco opened this issue 3 years ago • 3 comments

Contribution description

This can be error prone if no backup RAM is available. When keeping multiple sensors in sync, it can be more desirable to let them all start at 0 (when powered on at the same time) than some random time when using the .noinit section.

Testing procedure

Issues/PRs references

benpicco avatar Mar 10 '22 13:03 benpicco

Can you provide a test procudure and output?

fjmolinas avatar May 17 '22 08:05 fjmolinas

Can you provide a test procudure and output?

diff --git a/cpu/samd5x/periph/pm.c b/cpu/samd5x/periph/pm.c
index e06b3c6dd6..67ef1c980d 100644
--- a/cpu/samd5x/periph/pm.c
+++ b/cpu/samd5x/periph/pm.c
@@ -21,7 +21,7 @@
 
 #include "periph/pm.h"
 
-#define ENABLE_DEBUG 0
+#define ENABLE_DEBUG 1
 #include "debug.h"
 
 void pm_set(unsigned mode)
diff --git a/examples/default/Makefile b/examples/default/Makefile
index 467c36f3f8..d462470efc 100644
--- a/examples/default/Makefile
+++ b/examples/default/Makefile
@@ -49,7 +49,8 @@ ifneq (,$(filter $(BOARD),$(BOARD_PROVIDES_NETIF)))
   USEMODULE += gnrc_pktdump
 endif
 
-FEATURES_OPTIONAL += periph_rtc
+#FEATURES_OPTIONAL += periph_rtc
+FEATURES_OPTIONAL += periph_rtt
 
 ifneq (,$(filter msba2,$(BOARD)))
   USEMODULE += mci
diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile
index eeddbbbb07..73b53f607e 100644
--- a/sys/shell/commands/Makefile
+++ b/sys/shell/commands/Makefile
@@ -110,6 +110,12 @@ ifneq (,$(filter periph_rtc,$(USEMODULE)))
   SRC += sc_rtc.c
 endif
 
+ifneq (,$(filter periph_rtt,$(USEMODULE)))
+  ifneq (,$(filter rtt_rtc,$(USEMODULE)))
+    SRC += sc_rtc.c
+  endif
+endif
+
 ifneq (,$(filter rtt_cmd,$(USEMODULE)))
   SRC += sc_rtt.c
 endif
diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c
index 33a948a4d2..890c70e418 100644
--- a/sys/shell/commands/shell_commands.c
+++ b/sys/shell/commands/shell_commands.c
@@ -64,7 +64,7 @@ extern int _at30tse75x_handler(int argc, char **argv);
 extern int _saul(int argc, char **argv);
 #endif
 
-#ifdef MODULE_PERIPH_RTC
+#if defined(MODULE_PERIPH_RTC) || (defined(MODULE_PERIPH_RTT) && defined(MODULE_RTT_RTC))
 extern int _rtc_handler(int argc, char **argv);
 #endif
 
@@ -262,7 +262,7 @@ const shell_command_t _shell_command_list[] = {
     { "random_init", "initializes the PRNG", _random_init },
     { "random_get", "returns 32 bit of pseudo randomness", _random_get },
 #endif
-#ifdef MODULE_PERIPH_RTC
+#if defined(MODULE_PERIPH_RTC) || (defined(MODULE_PERIPH_RTT) && defined(MODULE_RTT_RTC))
     {"rtc", "control RTC peripheral interface",  _rtc_handler},
 #endif
 #ifdef MODULE_RTT_CMD
(END)

USEMODULE+=rtt_rtc CFLAGS+=-DCONFIG_RTT_RTC_NO_RETAIN=1 BOARD=same54-xpro make -C examples/default flash term

rtc gettime
rtc setalarm  2024-01-01 00:01:00
rtc settime 2024-01-01 00:00:00
pm set 0
2023-12-31 15:15:05,622 # rtc gettime
2023-12-31 15:15:05,624 # 2020-01-01 00:00:01
> 2023-12-31 15:15:05,626 # pm_set(): setting IDLE2 mode.
rtc setalarm  2024-01-01 00:01:00
2023-12-31 15:15:15,521 # rtc setalarm  2024-01-01 00:01:00
> 2023-12-31 15:15:15,524 # pm_set(): setting IDLE2 mode.
rtc settime 2024-01-01 00:00:00
2023-12-31 15:15:19,952 # rtc settime 2024-01-01 00:00:00
> 2023-12-31 15:15:19,955 # pm_set(): setting IDLE2 mode.
pm set 0
2023-12-31 15:15:23,487 # pm set 0
2023-12-31 15:15:23,490 # CPU is entering power mode 0.
2023-12-31 15:15:23,493 # Now waiting for a wakeup event...
2023-12-31 15:15:23,496 # pm_set(): setting BACKUP mode.
2023-12-31 15:16:19,973 # NETOPT_RX_END_IRQ not implemented by driver
2023-12-31 15:16:19,979 # main(): This is RIOT! (Version: 2022.04-devel-805-g72c7ac-HEAD)
2023-12-31 15:16:19,980 # Welcome to RIOT!
> 2023-12-31 15:16:19,983 # pm_set(): setting IDLE2 mode.
rtc gettime
2023-12-31 15:16:25,641 # rtc gettime
2023-12-31 15:16:25,643 # 2020-01-01 00:00:05
> 2023-12-31 15:16:25,646 # pm_set(): setting IDLE2 mode.

USEMODULE+=rtt_rtc CFLAGS+=-DCONFIG_RTT_RTC_NO_RETAIN=0 BOARD=same54-xpro make -C examples/default flash term

rtc gettime
rtc setalarm  2024-01-01 00:01:00
rtc settime 2024-01-01 00:00:00
pm set 0
2023-12-31 15:17:36,525 # rtc gettime
2023-12-31 15:17:36,527 # 2020-01-01 00:00:05
> 2023-12-31 15:17:36,530 # pm_set(): setting IDLE2 mode.
rtc setalarm  2024-01-01 00:01:00
2023-12-31 15:17:41,918 # rtc setalarm  2024-01-01 00:01:00
> 2023-12-31 15:17:41,921 # pm_set(): setting IDLE2 mode.
rtc settime 2024-01-01 00:00:00
2023-12-31 15:17:46,450 # rtc settime 2024-01-01 00:00:00
> 2023-12-31 15:17:46,453 # pm_set(): setting IDLE2 mode.
pm set 0
2023-12-31 15:17:50,592 # pm set 0
2023-12-31 15:17:50,594 # CPU is entering power mode 0.
2023-12-31 15:17:50,597 # Now waiting for a wakeup event...
2023-12-31 15:17:50,600 # pm_set(): setting BACKUP mode.
2023-12-31 15:18:46,472 # NETOPT_RX_END_IRQ not implemented by driver
2023-12-31 15:18:46,477 # main(): This is RIOT! (Version: 2022.04-devel-805-g72c7ac-HEAD)
2023-12-31 15:18:46,479 # Welcome to RIOT!
> 2023-12-31 15:18:46,482 # pm_set(): setting IDLE2 mode.
rtc gettime
2023-12-31 15:18:49,848 # rtc gettime
2023-12-31 15:18:49,850 # 2024-01-02 12:24:20
> 2023-12-31 15:18:49,853 # pm_set(): setting IDLE2 mode.

fabian18 avatar Dec 31 '23 14:12 fabian18

2023-12-31 15:18:49,850 # 2024-01-02 12:24:20

That's a bit unexpected that it is about one and a half days in the future. But executing rtc gettime again returns the correct time.

rtc gettime
2023-12-31 15:57:25,367 # rtc gettime
2023-12-31 15:57:25,369 # 2024-01-01 00:01:49
> 2023-12-31 15:57:25,372 # pm_set(): setting IDLE2 mode.

fabian18 avatar Dec 31 '23 14:12 fabian18