diff options
| author | xoviat <[email protected]> | 2023-04-25 17:35:01 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-04-25 17:35:01 -0500 |
| commit | 0d82ebea29d5bad6d1b40258419a215c44786e1d (patch) | |
| tree | 25c1a8060242674f02e9f8aa1c7929a4eab10036 /tests | |
| parent | e24421a393a549a000c8824d2ede275203b64a26 (diff) | |
stm32/rtc: fix datetime and add f4 test
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stm32/Cargo.toml | 10 | ||||
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 52 |
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] |
| 8 | stm32f103c8 = ["embassy-stm32/stm32f103c8"] # Blue Pill | 8 | stm32f103c8 = ["embassy-stm32/stm32f103c8"] # Blue Pill |
| 9 | stm32f429zi = ["embassy-stm32/stm32f429zi", "sdmmc"] # Nucleo | 9 | stm32f429zi = ["embassy-stm32/stm32f429zi", "sdmmc", "chrono"] # Nucleo |
| 10 | stm32g071rb = ["embassy-stm32/stm32g071rb"] # Nucleo | 10 | stm32g071rb = ["embassy-stm32/stm32g071rb"] # Nucleo |
| 11 | stm32c031c6 = ["embassy-stm32/stm32c031c6"] # Nucleo | 11 | stm32c031c6 = ["embassy-stm32/stm32c031c6"] # Nucleo |
| 12 | stm32g491re = ["embassy-stm32/stm32g491re"] # Nucleo | 12 | stm32g491re = ["embassy-stm32/stm32g491re"] # Nucleo |
| @@ -16,6 +16,7 @@ stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo | |||
| 16 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board | 16 | stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board |
| 17 | 17 | ||
| 18 | sdmmc = [] | 18 | sdmmc = [] |
| 19 | chrono = ["embassy-stm32/chrono", "dep:chrono"] | ||
| 19 | 20 | ||
| 20 | [dependencies] | 21 | [dependencies] |
| 21 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 22 | embassy-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" } | |||
| 33 | embedded-hal-async = { version = "=0.2.0-alpha.1" } | 34 | embedded-hal-async = { version = "=0.2.0-alpha.1" } |
| 34 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 35 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } |
| 35 | 36 | ||
| 37 | chrono = { 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" | |||
| 41 | required-features = [] | 44 | required-features = [] |
| 42 | 45 | ||
| 43 | [[bin]] | 46 | [[bin]] |
| 47 | name = "rtc" | ||
| 48 | path = "src/bin/rtc.rs" | ||
| 49 | required-features = [ "chrono",] | ||
| 50 | |||
| 51 | [[bin]] | ||
| 44 | name = "sdmmc" | 52 | name = "sdmmc" |
| 45 | path = "src/bin/sdmmc.rs" | 53 | path = "src/bin/sdmmc.rs" |
| 46 | required-features = [ "sdmmc",] | 54 | required-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"] | ||
| 8 | mod example_common; | ||
| 9 | use chrono::{NaiveDate, NaiveDateTime}; | ||
| 10 | use defmt::assert; | ||
| 11 | use embassy_executor::Spawner; | ||
| 12 | use embassy_stm32::pac; | ||
| 13 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | ||
| 14 | use embassy_time::{Duration, Timer}; | ||
| 15 | use example_common::*; | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async 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 | } | ||
