-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Add generic RTC for most STM32 boards
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 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,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; | ||
} |
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,2 @@ | ||
# Replace this with your custom programmer | ||
source [find interface/stlink.cfg] |
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,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> |