File tree Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Expand file tree Collapse file tree 4 files changed +61
-2
lines changed Original file line number Diff line number Diff line change
1
+ // coding: utf-8
2
+ /*
3
+ * Copyright (c) 2023, Rasmus Kleist Hørlyck Sørensen
4
+ * Copyright (c) 2024, Niklas Hauser
5
+ *
6
+ * This file is part of the modm project.
7
+ *
8
+ * This Source Code Form is subject to the terms of the Mozilla Public
9
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
10
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11
+ */
12
+ // ----------------------------------------------------------------------------
13
+
14
+ #include < modm/board.hpp>
15
+
16
+ int
17
+ main ()
18
+ {
19
+ Board::initialize ();
20
+ MODM_LOG_INFO << " Initialize RTC" << modm::endl;
21
+ Rtc::initialize<Board::SystemClock>();
22
+
23
+ constexpr auto cdt = modm::DateTime::fromBuildTime ();
24
+ MODM_LOG_INFO << " Compile DateTime: " << cdt << modm::endl;
25
+ // MODM_LOG_INFO << "Compile Weekday: " << cdt.weekday().c_encoding() << modm::endl;
26
+
27
+ if (Rtc::dateTime () < cdt) Rtc::setDateTime (cdt);
28
+
29
+ while (true )
30
+ {
31
+ const auto dt = Rtc::dateTime ();
32
+ const auto now = Rtc::now ();
33
+ MODM_LOG_INFO << dt << modm::endl;
34
+ MODM_LOG_INFO << now.time_since_epoch ().count () << modm::endl;
35
+ // MODM_LOG_INFO << "Weekday: " << dt.weekday().c_encoding() << modm::endl;
36
+ modm::delay (0 .9s);
37
+ }
38
+
39
+ return 0 ;
40
+ }
Original file line number Diff line number Diff line change
1
+ <library >
2
+ <extends >modm:nucleo-g071rb</extends >
3
+ <!-- <extends>modm:nucleo-g474re</extends> -->
4
+ <options >
5
+ <option name =" modm:build:build.path" >../../../build/generic/rtc</option >
6
+ </options >
7
+ <modules >
8
+ <module >modm:platform:rtc</module >
9
+ <module >modm:build:scons</module >
10
+ </modules >
11
+ </library >
Original file line number Diff line number Diff line change @@ -72,16 +72,20 @@ struct SystemClock
72
72
static constexpr uint32_t Spi2 = Apb;
73
73
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
74
74
static constexpr uint32_t Wwdg = Apb;
75
- static constexpr uint32_t Rtc = Apb;
76
75
static constexpr uint32_t Timer14 = Apb;
77
76
static constexpr uint32_t Timer7 = Apb;
78
77
static constexpr uint32_t Timer6 = Apb;
79
78
static constexpr uint32_t Timer3 = Apb;
80
79
static constexpr uint32_t Timer2 = Apb;
81
80
81
+ static constexpr uint32_t Rtc = 32 .768_kHz;
82
+
82
83
static bool inline
83
84
enable ()
84
85
{
86
+ Rcc::enableLowSpeedExternalCrystal ();
87
+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::LowSpeedExternalCrystal);
88
+
85
89
Rcc::enableInternalClock (); // 16MHz
86
90
// (internal clock / 1_M) * 8_N / 2_R = 128MHz / 2 = 64MHz
87
91
const Rcc::PllFactors pllFactors{
Original file line number Diff line number Diff line change @@ -66,7 +66,6 @@ struct SystemClock
66
66
static constexpr uint32_t I2c4 = I2c;
67
67
static constexpr uint32_t Lptim = Apb1;
68
68
static constexpr uint32_t Lpuart = Apb1;
69
- static constexpr uint32_t Rtc = Apb1;
70
69
static constexpr uint32_t Spi2 = Apb1;
71
70
static constexpr uint32_t Spi3 = Apb1;
72
71
static constexpr uint32_t Uart4 = Apb1;
@@ -94,6 +93,8 @@ struct SystemClock
94
93
static constexpr uint32_t Timer20 = Apb2Timer;
95
94
static constexpr uint32_t Iwdg = Rcc::LsiFrequency;
96
95
96
+ static constexpr uint32_t Rtc = 32 .768_kHz;
97
+
97
98
static bool inline
98
99
enable ()
99
100
{
@@ -115,6 +116,9 @@ struct SystemClock
115
116
// update frequencies for busy-wait delay functions
116
117
Rcc::updateCoreFrequency<Frequency>();
117
118
119
+ Rcc::enableLowSpeedExternalCrystal ();
120
+ Rcc::enableRealTimeClock (Rcc::RealTimeClockSource::LowSpeedExternalCrystal);
121
+
118
122
Rcc::setCanClockSource (Rcc::CanClockSource::Pclk);
119
123
return true ;
120
124
}
You can’t perform that action at this time.
0 commit comments