diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32wl/.cargo/config.toml | 2 | ||||
| -rw-r--r-- | examples/stm32wl/Cargo.toml | 5 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/rtc.rs | 43 |
3 files changed, 47 insertions, 3 deletions
diff --git a/examples/stm32wl/.cargo/config.toml b/examples/stm32wl/.cargo/config.toml index 4f8094ff2..ee416fcbc 100644 --- a/examples/stm32wl/.cargo/config.toml +++ b/examples/stm32wl/.cargo/config.toml | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | runner = "probe-rs run --chip STM32WLE5JCIx" | 3 | runner = "probe-rs run --chip STM32WLE5JCIx" |
| 4 | 4 | ||
| 5 | [build] | 5 | [build] |
| 6 | target = "thumbv7em-none-eabihf" | 6 | target = "thumbv7em-none-eabi" |
| 7 | 7 | ||
| 8 | [env] | 8 | [env] |
| 9 | DEFMT_LOG = "trace" | 9 | DEFMT_LOG = "trace" |
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 99f68387f..e2c66f456 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" | |||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 10 | embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "unstable-pac", "exti", "chrono"] } |
| 12 | embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } | 12 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 13 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } | 13 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } |
| 14 | lora-phy = { version = "1" } | 14 | lora-phy = { version = "1" } |
| 15 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] } | 15 | lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] } |
| @@ -25,6 +25,7 @@ embedded-storage = "0.3.0" | |||
| 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 25 | panic-probe = { version = "0.3", features = ["print-defmt"] } |
| 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | 26 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } |
| 27 | heapless = { version = "0.7.5", default-features = false } | 27 | heapless = { version = "0.7.5", default-features = false } |
| 28 | chrono = { version = "^0.4", default-features = false } | ||
| 28 | 29 | ||
| 29 | [patch.crates-io] | 30 | [patch.crates-io] |
| 30 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } | 31 | lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "ad289428fd44b02788e2fa2116445cc8f640a265" } |
diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs new file mode 100644 index 000000000..e11825499 --- /dev/null +++ b/examples/stm32wl/src/bin/rtc.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use chrono::{NaiveDate, NaiveDateTime}; | ||
| 6 | use defmt::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_stm32::rcc::{self, ClockSrc}; | ||
| 9 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | ||
| 10 | use embassy_stm32::Config; | ||
| 11 | use embassy_time::{Duration, Timer}; | ||
| 12 | use {defmt_rtt as _, panic_probe as _}; | ||
| 13 | |||
| 14 | #[embassy_executor::main] | ||
| 15 | async fn main(_spawner: Spawner) { | ||
| 16 | let p = { | ||
| 17 | let mut config = Config::default(); | ||
| 18 | config.rcc.mux = ClockSrc::HSE32; | ||
| 19 | config.rcc.rtc_mux = rcc::RtcClockSource::LSE32; | ||
| 20 | config.rcc.enable_rtc_apb = true; | ||
| 21 | embassy_stm32::init(config) | ||
| 22 | }; | ||
| 23 | info!("Hello World!"); | ||
| 24 | |||
| 25 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) | ||
| 26 | .unwrap() | ||
| 27 | .and_hms_opt(10, 30, 15) | ||
| 28 | .unwrap(); | ||
| 29 | |||
| 30 | let mut rtc = Rtc::new( | ||
| 31 | p.RTC, | ||
| 32 | RtcConfig::default().clock_config(embassy_stm32::rtc::RtcClockSource::LSE), | ||
| 33 | ); | ||
| 34 | info!("Got RTC! {:?}", now.timestamp()); | ||
| 35 | |||
| 36 | rtc.set_datetime(now.into()).expect("datetime not set"); | ||
| 37 | |||
| 38 | // In reality the delay would be much longer | ||
| 39 | Timer::after(Duration::from_millis(20000)).await; | ||
| 40 | |||
| 41 | let then: NaiveDateTime = rtc.now().unwrap().into(); | ||
| 42 | info!("Got RTC! {:?}", then.timestamp()); | ||
| 43 | } | ||
