Skip to content

Commit

Permalink
[example] Add generic RTC for most STM32 boards
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Dec 30, 2024
1 parent 967d0fa commit c812267
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
59 changes: 59 additions & 0 deletions examples/generic/rtc/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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();
Board::Leds::setOutput();
#ifdef MODM_BOARD_HAS_LOGGER
MODM_LOG_INFO << "Initialize RTC" << modm::endl;
#endif
const bool inited = Rtc::initialize<Board::SystemClock>();
#ifdef MODM_BOARD_HAS_LOGGER
if (not inited) { MODM_LOG_INFO << "RTC was already initialized." << modm::endl; }
#endif

constexpr auto cdt = modm::DateTime::fromBuildTime();
if (Rtc::dateTime() < cdt) Rtc::setDateTime(cdt);
#ifdef MODM_BOARD_HAS_LOGGER
MODM_LOG_INFO << "Compile DateTime: " << cdt << modm::endl;
MODM_LOG_INFO << "YMD: " << cdt.year_month_day() << modm::endl;
MODM_LOG_INFO << "HMS: " << cdt.hh_mm_ss() << modm::endl;
MODM_LOG_INFO << "Weekday: " << cdt.weekday() << modm::endl;
#endif


while (true)
{
const auto dt = Rtc::dateTime();
#ifdef MODM_BOARD_HAS_LOGGER
const auto now = Rtc::now();
MODM_LOG_INFO << dt << " (" << dt.weekday() << ") = " << now << " since 1970" << modm::endl;
modm::delay(1.1s);
#else
static uint8_t prev_second{};
if (prev_second != dt.seconds().count())
{
prev_second = dt.seconds().count();
Board::Leds::toggle();
}
modm::delay(10ms);
#endif

}

return 0;
}
2 changes: 2 additions & 0 deletions examples/generic/rtc/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Replace this with your custom programmer
source [find interface/stlink.cfg]
46 changes: 46 additions & 0 deletions examples/generic/rtc/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<library>
<!-- <extends>modm:nucleo-c031c6</extends> -->

<!-- <extends>modm:nucleo-g071rb</extends> -->

<!-- <extends>modm:stm32f030_demo</extends> -->
<!-- <extends>modm:disco-f051r8</extends> -->
<!-- <extends>modm:disco-f072rb</extends> -->
<!-- <extends>modm:nucleo-f072rb</extends> -->
<!-- <extends>modm:nucleo-f091rc</extends> -->

<!-- <extends>modm:nucleo-l053r8</extends> -->
<!-- <extends>modm:nucleo-l152re</extends> -->
<!-- <extends>modm:disco-l152rc</extends> -->
<!-- <extends>modm:nucleo-l476rg</extends> -->
<!-- <extends>modm:disco-l476vg</extends> -->

<!-- <extends>modm:disco-f303vc</extends> -->
<!-- <extends>modm:nucleo-f334r8</extends> -->


<!-- <extends>modm:black-pill-f401</extends> -->
<!-- <extends>modm:nucleo-f401re</extends> -->
<!-- <extends>modm:disco-f407vg</extends> -->
<!-- <extends>modm:black-pill-f411</extends> -->
<!-- <extends>modm:nucleo-f411re</extends> -->
<!-- <extends>modm:nucleo-f429zi</extends> -->
<!-- <extends>modm:disco-f429zi</extends> -->
<!-- <extends>modm:nucleo-f446re</extends> -->
<!-- <extends>modm:disco-f469ni</extends> -->

<!-- <extends>modm:nucleo-g474re</extends> -->

<!-- <extends>modm:disco-f746ng</extends> -->
<!-- <extends>modm:nucleo-h723zg</extends> -->
<!-- <extends>modm:nucleo-h743zi</extends> -->
<extends>modm:nucleo-u575zi-q</extends>
<options>
<option name="modm:build:build.path">../../../build/generic/rtc</option>
<!-- <option name="modm:build:openocd.cfg">openocd.cfg</option> -->
</options>
<modules>
<module>modm:platform:rtc</module>
<module>modm:build:scons</module>
</modules>
</library>

0 comments on commit c812267

Please sign in to comment.