aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-04-25 17:35:01 -0500
committerxoviat <[email protected]>2023-04-25 17:35:01 -0500
commit0d82ebea29d5bad6d1b40258419a215c44786e1d (patch)
tree25c1a8060242674f02e9f8aa1c7929a4eab10036 /tests
parente24421a393a549a000c8824d2ede275203b64a26 (diff)
stm32/rtc: fix datetime and add f4 test
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/Cargo.toml10
-rw-r--r--tests/stm32/src/bin/rtc.rs52
2 files changed, 61 insertions, 1 deletions
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index 3047c34ce..c48d26456 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[features] 7[features]
8stm32f103c8 = ["embassy-stm32/stm32f103c8"] # Blue Pill 8stm32f103c8 = ["embassy-stm32/stm32f103c8"] # Blue Pill
9stm32f429zi = ["embassy-stm32/stm32f429zi", "sdmmc"] # Nucleo 9stm32f429zi = ["embassy-stm32/stm32f429zi", "sdmmc", "chrono"] # Nucleo
10stm32g071rb = ["embassy-stm32/stm32g071rb"] # Nucleo 10stm32g071rb = ["embassy-stm32/stm32g071rb"] # Nucleo
11stm32c031c6 = ["embassy-stm32/stm32c031c6"] # Nucleo 11stm32c031c6 = ["embassy-stm32/stm32c031c6"] # Nucleo
12stm32g491re = ["embassy-stm32/stm32g491re"] # Nucleo 12stm32g491re = ["embassy-stm32/stm32g491re"] # Nucleo
@@ -16,6 +16,7 @@ stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo
16stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board 16stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board
17 17
18sdmmc = [] 18sdmmc = []
19chrono = ["embassy-stm32/chrono", "dep:chrono"]
19 20
20[dependencies] 21[dependencies]
21embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 22embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
@@ -33,6 +34,8 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.10" }
33embedded-hal-async = { version = "=0.2.0-alpha.1" } 34embedded-hal-async = { version = "=0.2.0-alpha.1" }
34panic-probe = { version = "0.3.0", features = ["print-defmt"] } 35panic-probe = { version = "0.3.0", features = ["print-defmt"] }
35 36
37chrono = { version = "^0.4", default-features = false, optional = true}
38
36# BEGIN TESTS 39# BEGIN TESTS
37# Generated by gen_test.py. DO NOT EDIT. 40# Generated by gen_test.py. DO NOT EDIT.
38[[bin]] 41[[bin]]
@@ -41,6 +44,11 @@ path = "src/bin/gpio.rs"
41required-features = [] 44required-features = []
42 45
43[[bin]] 46[[bin]]
47name = "rtc"
48path = "src/bin/rtc.rs"
49required-features = [ "chrono",]
50
51[[bin]]
44name = "sdmmc" 52name = "sdmmc"
45path = "src/bin/sdmmc.rs" 53path = "src/bin/sdmmc.rs"
46required-features = [ "sdmmc",] 54required-features = [ "sdmmc",]
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}