-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use time instead of rtcc, add rtc-example
- Loading branch information
Showing
4 changed files
with
164 additions
and
168 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! This example demonstrates how to use the RTC. | ||
//! Note that the LSI can be quite inaccurate. | ||
//! The tolerance is up to ±47% (Min 17 kHz, Typ 32 kHz, Max 47 kHz). | ||
|
||
#![no_main] | ||
#![no_std] | ||
|
||
use cortex_m_rt::entry; | ||
use panic_rtt_target as _; | ||
use rtt_target::{rprintln, rtt_init_print}; | ||
|
||
use stm32f4xx_hal::{pac, prelude::*, rtc::Rtc}; | ||
use time::{ | ||
macros::{date, time}, | ||
PrimitiveDateTime, | ||
}; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
rtt_init_print!(); | ||
let mut p = pac::Peripherals::take().unwrap(); | ||
let rcc = p.RCC.constrain(); | ||
|
||
let clocks = rcc.cfgr.freeze(); | ||
|
||
let mut rtc = Rtc::new(p.RTC, 249, 127, false, &mut p.PWR); | ||
let mut delay = p.TIM5.delay_us(&clocks); | ||
|
||
rtc.set_datetime(&PrimitiveDateTime::new( | ||
date!(2022 - 02 - 07), | ||
time!(23:59:50), | ||
)) | ||
.unwrap(); | ||
// Alternatively: | ||
// rtc.set_date(&date!(2022 - 02 - 07)).unwrap(); | ||
// rtc.set_time(&time!(23:59:50)).unwrap(); | ||
// Or: | ||
// rtc.set_year(2022).unwrap(); | ||
// rtc.set_month(02).unwrap(); | ||
// rtc.set_day(07).unwrap(); | ||
// rtc.set_hours(23).unwrap(); | ||
// rtc.set_minutes(59).unwrap(); | ||
// rtc.set_seconds(50).unwrap(); | ||
loop { | ||
rprintln!("{}", rtc.get_datetime()); | ||
delay.delay(500.millis()).unwrap(); | ||
} | ||
} |
Oops, something went wrong.