-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add RTC example on NUCLEO-G071RB/G474RE
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// coding: utf-8 | ||
/* | ||
* Copyright (c) 2023, Rasmus Kleist Hørlyck Sørensen | ||
* Copyright (c) 2024, Niklas Hauser | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
MODM_LOG_INFO << "Initialize RTC" << modm::endl; | ||
const bool inited = Rtc::initialize<Board::SystemClock>(); | ||
if (not inited) { MODM_LOG_INFO << "RTC was already initialized." << modm::endl; } | ||
|
||
constexpr auto cdt = modm::DateTime::fromBuildTime(); | ||
if (Rtc::dateTime() < cdt) Rtc::setDateTime(cdt); | ||
MODM_LOG_INFO << "Compile DateTime: " << cdt << " weekday: " << cdt.weekday().c_encoding() << modm::endl; | ||
|
||
|
||
while (true) | ||
{ | ||
const auto dt = Rtc::dateTime(); | ||
const auto now = Rtc::now(); | ||
|
||
const char *const wd = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat"; | ||
MODM_LOG_INFO << dt << " (" << (wd + dt.weekday().c_encoding()*4) << ") = "; | ||
MODM_LOG_INFO << now.time_since_epoch().count() << "ms since 1970" << modm::endl; | ||
|
||
modm::delay(1.1s); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<library> | ||
<extends>modm:nucleo-g071rb</extends> | ||
<!-- <extends>modm:nucleo-g474re</extends> --> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/generic/rtc</option> | ||
</options> | ||
<modules> | ||
<module>modm:platform:rtc</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters