aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-05-01 19:32:06 +0000
committerGitHub <[email protected]>2023-05-01 19:32:06 +0000
commit855c0d1423cb1aacd4f4f45e255b02b442afde34 (patch)
tree727d6409543c308d2e8cb48fc722c61ed753be9c /tests/stm32/src
parent05c36e05f9f6b1a0a36982239b2e7c697f0d3734 (diff)
parent0d82ebea29d5bad6d1b40258419a215c44786e1d (diff)
Merge #1376
1376: rtc: cleanup and consolidate r=Dirbaio a=xoviat This removes an extra file that I left in, adds an example, and consolidates the files into one 'v2' file. Co-authored-by: xoviat <[email protected]>
Diffstat (limited to 'tests/stm32/src')
-rw-r--r--tests/stm32/src/bin/rtc.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs
new file mode 100644
index 000000000..ccf2ca609
--- /dev/null
+++ b/tests/stm32/src/bin/rtc.rs
@@ -0,0 +1,52 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5// required-features: chrono
6
7#[path = "../example_common.rs"]
8mod example_common;
9use chrono::{NaiveDate, NaiveDateTime};
10use defmt::assert;
11use embassy_executor::Spawner;
12use embassy_stm32::pac;
13use embassy_stm32::rtc::{Rtc, RtcConfig};
14use embassy_time::{Duration, Timer};
15use example_common::*;
16
17#[embassy_executor::main]
18async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(config());
20 info!("Hello World!");
21
22 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
23 .unwrap()
24 .and_hms_opt(10, 30, 15)
25 .unwrap();
26
27 info!("Starting LSI");
28
29 unsafe {
30 pac::RCC.csr().modify(|w| w.set_lsion(true));
31 while !pac::RCC.csr().read().lsirdy() {}
32 }
33
34 info!("Started LSI");
35
36 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
37
38 rtc.set_datetime(now.into()).expect("datetime not set");
39
40 info!("Waiting 5 seconds");
41 Timer::after(Duration::from_millis(5000)).await;
42
43 let then: NaiveDateTime = rtc.now().unwrap().into();
44 let seconds = (then - now).num_seconds();
45
46 defmt::info!("measured = {}", seconds);
47
48 assert!(seconds > 3 && seconds < 7);
49
50 info!("Test OK");
51 cortex_m::asm::bkpt();
52}