Compare commits
25 Commits
embassy-ma
...
embassy-ti
Author | SHA1 | Date | |
---|---|---|---|
a36ee75d19 | |||
1f63bf4153 | |||
88146eb53e | |||
326e78757b | |||
f77a7fe4bf | |||
cbc92dce05 | |||
531f51d0eb | |||
f28ab18d7b | |||
3bf6081eb5 | |||
fb942e6675 | |||
10ea068027 | |||
4caa8497fc | |||
48085939e7 | |||
db6f9afa2e | |||
59a5e84df5 | |||
13f0501673 | |||
94de1a5353 | |||
db71887817 | |||
1e430f7413 | |||
2897670f24 | |||
ca738d6c99 | |||
d33246b072 | |||
54e2e17520 | |||
3023e70ccf | |||
cda4047310 |
13
ci.sh
13
ci.sh
@ -19,6 +19,19 @@ cargo batch \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,log \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,defmt \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-interrupt,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target thumbv7em-none-eabi --features nightly,arch-cortex-m,executor-thread,executor-interrupt,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32 \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,integrated-timers \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread \
|
||||
--- build --release --manifest-path embassy-executor/Cargo.toml --target riscv32imac-unknown-none-elf --features nightly,arch-riscv32,executor-thread,integrated-timers \
|
||||
--- build --release --manifest-path embassy-sync/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt \
|
||||
--- build --release --manifest-path embassy-time/Cargo.toml --target thumbv6m-none-eabi --features nightly,defmt,defmt-timestamp-uptime,tick-hz-32_768,generic-queue-8 \
|
||||
--- build --release --manifest-path embassy-net/Cargo.toml --target thumbv7em-none-eabi --features defmt,tcp,udp,dns,proto-ipv4,medium-ethernet \
|
||||
|
@ -11,7 +11,7 @@ log = ["dep:log"]
|
||||
firmware-logs = []
|
||||
|
||||
[dependencies]
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time"}
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time"}
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync"}
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures"}
|
||||
embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel"}
|
||||
@ -31,4 +31,4 @@ num_enum = { version = "0.5.7", default-features = false }
|
||||
src_base = "https://github.com/embassy-rs/embassy/blob/cyw43-v$VERSION/cyw43/src/"
|
||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/cyw43/src/"
|
||||
target = "thumbv6m-none-eabi"
|
||||
features = ["defmt", "firmware-logs"]
|
||||
features = ["defmt", "firmware-logs"]
|
||||
|
@ -21,7 +21,7 @@ default = ["time"]
|
||||
[dependencies]
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures", optional = true }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
|
||||
embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [
|
||||
"unproven",
|
||||
] }
|
||||
|
@ -59,7 +59,7 @@ rtos-trace = { version = "0.1.2", optional = true }
|
||||
|
||||
futures-util = { version = "0.3.17", default-features = false }
|
||||
embassy-macros = { version = "0.2.1", path = "../embassy-macros" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true}
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true}
|
||||
atomic-polyfill = "1.0.1"
|
||||
critical-section = "1.1"
|
||||
static_cell = "1.1"
|
||||
|
@ -1,5 +1,3 @@
|
||||
const THREAD_PENDER: usize = usize::MAX;
|
||||
|
||||
#[export_name = "__pender"]
|
||||
#[cfg(any(feature = "executor-thread", feature = "executor-interrupt"))]
|
||||
fn __pender(context: *mut ()) {
|
||||
@ -48,13 +46,14 @@ fn __pender(context: *mut ()) {
|
||||
pub use thread::*;
|
||||
#[cfg(feature = "executor-thread")]
|
||||
mod thread {
|
||||
pub(super) const THREAD_PENDER: usize = usize::MAX;
|
||||
|
||||
use core::arch::asm;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
pub use embassy_macros::main_cortex_m as main;
|
||||
|
||||
use crate::arch::THREAD_PENDER;
|
||||
use crate::{raw, Spawner};
|
||||
|
||||
/// Thread mode executor, using WFE/SEV.
|
||||
|
@ -20,7 +20,7 @@ defmt = ["dep:defmt", "lorawan-device/defmt"]
|
||||
defmt = { version = "0.3", optional = true }
|
||||
log = { version = "0.4.14", optional = true }
|
||||
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true }
|
||||
embedded-hal-async = { version = "=1.0.0-rc.1" }
|
||||
@ -31,4 +31,4 @@ lora-phy = { version = "1" }
|
||||
lorawan-device = { version = "0.10.0", default-features = false, features = ["async"], optional = true }
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
|
@ -11,7 +11,7 @@ edition = "2021"
|
||||
embedded-hal = { version = "1.0.0-rc.1" }
|
||||
embedded-hal-async = { version = "=1.0.0-rc.1" }
|
||||
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time" }
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
|
||||
|
||||
defmt = { version = "0.3", optional = true }
|
||||
@ -20,4 +20,4 @@ log = { version = "0.4.14", optional = true }
|
||||
[package.metadata.embassy_docs]
|
||||
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-enc28j60-v$VERSION/embassy-net-enc28j60/src/"
|
||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-enc28j60/src/"
|
||||
target = "thumbv7em-none-eabi"
|
||||
target = "thumbv7em-none-eabi"
|
||||
|
@ -7,7 +7,7 @@ edition = "2021"
|
||||
defmt = { version = "0.3", optional = true }
|
||||
log = { version = "0.4.14", optional = true }
|
||||
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time" }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync"}
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures"}
|
||||
embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel"}
|
||||
@ -23,4 +23,4 @@ heapless = "0.7.16"
|
||||
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-esp-hosted-v$VERSION/embassy-net-esp-hosted/src/"
|
||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-esp-hosted/src/"
|
||||
target = "thumbv7em-none-eabi"
|
||||
features = ["defmt"]
|
||||
features = ["defmt"]
|
||||
|
@ -11,7 +11,7 @@ edition = "2021"
|
||||
embedded-hal = { version = "1.0.0-rc.1" }
|
||||
embedded-hal-async = { version = "=1.0.0-rc.1" }
|
||||
embassy-net-driver-channel = { version = "0.1.0", path = "../embassy-net-driver-channel" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time" }
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
|
||||
defmt = { version = "0.3", optional = true }
|
||||
|
||||
@ -19,4 +19,4 @@ defmt = { version = "0.3", optional = true }
|
||||
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-wiznet-v$VERSION/embassy-net-wiznet/src/"
|
||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-wiznet/src/"
|
||||
target = "thumbv7em-none-eabi"
|
||||
features = ["defmt"]
|
||||
features = ["defmt"]
|
||||
|
@ -51,7 +51,7 @@ smoltcp = { version = "0.10.0", default-features = false, features = [
|
||||
] }
|
||||
|
||||
embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time" }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embedded-io-async = { version = "0.5.0", optional = true }
|
||||
|
||||
|
@ -91,7 +91,7 @@ _dppi = []
|
||||
_gpio-p1 = []
|
||||
|
||||
[dependencies]
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-hal-internal = {version = "0.1.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-3"] }
|
||||
embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
|
||||
|
@ -60,7 +60,7 @@ unstable-traits = ["embedded-hal-1", "embedded-hal-nb"]
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", features = [ "tick-hz-1_000_000" ] }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", features = [ "tick-hz-1_000_000" ] }
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
|
||||
embassy-hal-internal = {version = "0.1.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-2"] }
|
||||
embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
|
||||
|
@ -13,7 +13,7 @@ features = ["stm32wb55rg"]
|
||||
[dependencies]
|
||||
embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32" }
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
|
||||
embassy-hal-internal = { version = "0.1.0", path = "../embassy-hal-internal" }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../embassy-embedded-hal" }
|
||||
|
@ -32,7 +32,7 @@ flavors = [
|
||||
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
|
||||
embassy-time = { version = "0.1.2", path = "../embassy-time", optional = true }
|
||||
embassy-time = { version = "0.1.3", path = "../embassy-time", optional = true }
|
||||
embassy-futures = { version = "0.1.0", path = "../embassy-futures" }
|
||||
embassy-hal-internal = {version = "0.1.0", path = "../embassy-hal-internal", features = ["cortex-m", "prio-bits-4"] }
|
||||
embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
|
||||
@ -58,7 +58,7 @@ sdio-host = "0.5.0"
|
||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
||||
critical-section = "1.1"
|
||||
atomic-polyfill = "1.0.1"
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2b87e34c661e19ff6dc603fabfe7fe99ab7261f7" }
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-9a61a1f090462df8bd1751f89951f04934fdceb3" }
|
||||
vcell = "0.1.3"
|
||||
bxcan = "0.7.0"
|
||||
nb = "1.0.0"
|
||||
@ -77,7 +77,7 @@ critical-section = { version = "1.1", features = ["std"] }
|
||||
[build-dependencies]
|
||||
proc-macro2 = "1.0.36"
|
||||
quote = "1.0.15"
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2b87e34c661e19ff6dc603fabfe7fe99ab7261f7", default-features = false, features = ["metadata"]}
|
||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-9a61a1f090462df8bd1751f89951f04934fdceb3", default-features = false, features = ["metadata"]}
|
||||
|
||||
[features]
|
||||
default = ["rt"]
|
||||
|
@ -197,6 +197,11 @@ pub fn init(config: Config) -> Peripherals {
|
||||
// must be after rcc init
|
||||
#[cfg(feature = "_time-driver")]
|
||||
time_driver::init();
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
while !crate::rcc::low_power_ready() {
|
||||
crate::rcc::clock_refcount_sub();
|
||||
}
|
||||
}
|
||||
|
||||
p
|
||||
|
@ -3,46 +3,52 @@ use core::marker::PhantomData;
|
||||
|
||||
use cortex_m::peripheral::SCB;
|
||||
use embassy_executor::*;
|
||||
use embassy_time::Duration;
|
||||
|
||||
use crate::interrupt;
|
||||
use crate::interrupt::typelevel::Interrupt;
|
||||
use crate::pac::EXTI;
|
||||
use crate::rcc::low_power_ready;
|
||||
use crate::time_driver::{get_driver, RtcDriver};
|
||||
|
||||
const THREAD_PENDER: usize = usize::MAX;
|
||||
const THRESHOLD: Duration = Duration::from_millis(500);
|
||||
|
||||
use crate::rtc::{Rtc, RtcInstant};
|
||||
use crate::rtc::Rtc;
|
||||
|
||||
static mut RTC: Option<&'static Rtc> = None;
|
||||
static mut EXECUTOR: Option<Executor> = None;
|
||||
|
||||
foreach_interrupt! {
|
||||
(RTC, rtc, $block:ident, WKUP, $irq:ident) => {
|
||||
#[interrupt]
|
||||
unsafe fn $irq() {
|
||||
Executor::on_wakeup_irq();
|
||||
unsafe { EXECUTOR.as_mut().unwrap() }.on_wakeup_irq();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// pub fn timer_driver_pause_time() {
|
||||
// pause_time();
|
||||
// }
|
||||
|
||||
pub fn stop_with_rtc(rtc: &'static Rtc) {
|
||||
crate::interrupt::typelevel::RTC_WKUP::unpend();
|
||||
unsafe { crate::interrupt::typelevel::RTC_WKUP::enable() };
|
||||
|
||||
EXTI.rtsr(0).modify(|w| w.set_line(22, true));
|
||||
EXTI.imr(0).modify(|w| w.set_line(22, true));
|
||||
|
||||
unsafe { RTC = Some(rtc) };
|
||||
unsafe { EXECUTOR.as_mut().unwrap() }.stop_with_rtc(rtc)
|
||||
}
|
||||
|
||||
pub fn start_wakeup_alarm(requested_duration: embassy_time::Duration) -> RtcInstant {
|
||||
unsafe { RTC }.unwrap().start_wakeup_alarm(requested_duration)
|
||||
}
|
||||
|
||||
pub fn stop_wakeup_alarm() -> RtcInstant {
|
||||
unsafe { RTC }.unwrap().stop_wakeup_alarm()
|
||||
}
|
||||
// pub fn start_wakeup_alarm(requested_duration: embassy_time::Duration) {
|
||||
// let rtc_instant = unsafe { EXECUTOR.as_mut().unwrap() }
|
||||
// .rtc
|
||||
// .unwrap()
|
||||
// .start_wakeup_alarm(requested_duration);
|
||||
//
|
||||
// unsafe { EXECUTOR.as_mut().unwrap() }.last_stop = Some(rtc_instant);
|
||||
// }
|
||||
//
|
||||
// pub fn set_sleepdeep() {
|
||||
// unsafe { EXECUTOR.as_mut().unwrap() }.scb.set_sleepdeep();
|
||||
// }
|
||||
//
|
||||
// pub fn stop_wakeup_alarm() -> RtcInstant {
|
||||
// unsafe { EXECUTOR.as_mut().unwrap() }.rtc.unwrap().stop_wakeup_alarm()
|
||||
// }
|
||||
|
||||
/// Thread mode executor, using WFE/SEV.
|
||||
///
|
||||
@ -57,54 +63,62 @@ pub fn stop_wakeup_alarm() -> RtcInstant {
|
||||
pub struct Executor {
|
||||
inner: raw::Executor,
|
||||
not_send: PhantomData<*mut ()>,
|
||||
scb: SCB,
|
||||
time_driver: &'static RtcDriver,
|
||||
}
|
||||
|
||||
impl Executor {
|
||||
/// Create a new Executor.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: raw::Executor::new(THREAD_PENDER as *mut ()),
|
||||
not_send: PhantomData,
|
||||
pub fn take() -> &'static mut Self {
|
||||
unsafe {
|
||||
assert!(EXECUTOR.is_none());
|
||||
|
||||
EXECUTOR = Some(Self {
|
||||
inner: raw::Executor::new(THREAD_PENDER as *mut ()),
|
||||
not_send: PhantomData,
|
||||
scb: cortex_m::Peripherals::steal().SCB,
|
||||
time_driver: get_driver(),
|
||||
});
|
||||
|
||||
EXECUTOR.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn on_wakeup_irq() {
|
||||
info!("on wakeup irq");
|
||||
unsafe fn on_wakeup_irq(&mut self) {
|
||||
trace!("low power: on wakeup irq");
|
||||
|
||||
cortex_m::asm::bkpt();
|
||||
self.time_driver.resume_time();
|
||||
trace!("low power: resume time");
|
||||
}
|
||||
|
||||
fn time_until_next_alarm(&self) -> Duration {
|
||||
Duration::from_secs(3)
|
||||
pub(self) fn stop_with_rtc(&mut self, rtc: &'static Rtc) {
|
||||
trace!("low power: stop with rtc configured");
|
||||
|
||||
self.time_driver.set_rtc(rtc);
|
||||
|
||||
crate::interrupt::typelevel::RTC_WKUP::unpend();
|
||||
unsafe { crate::interrupt::typelevel::RTC_WKUP::enable() };
|
||||
|
||||
EXTI.rtsr(0).modify(|w| w.set_line(22, true));
|
||||
EXTI.imr(0).modify(|w| w.set_line(22, true));
|
||||
}
|
||||
|
||||
fn get_scb() -> SCB {
|
||||
unsafe { cortex_m::Peripherals::steal() }.SCB
|
||||
}
|
||||
|
||||
fn configure_pwr(&self) {
|
||||
trace!("configure_pwr");
|
||||
fn configure_pwr(&mut self) {
|
||||
trace!("low power: configure_pwr");
|
||||
|
||||
self.scb.clear_sleepdeep();
|
||||
if !low_power_ready() {
|
||||
trace!("low power: configure_pwr: low power not ready");
|
||||
return;
|
||||
}
|
||||
|
||||
let time_until_next_alarm = self.time_until_next_alarm();
|
||||
if time_until_next_alarm < THRESHOLD {
|
||||
if self.time_driver.pause_time().is_err() {
|
||||
trace!("low power: configure_pwr: time driver failed to pause");
|
||||
return;
|
||||
}
|
||||
|
||||
trace!("low power stop required");
|
||||
|
||||
critical_section::with(|_| {
|
||||
trace!("executor: set wakeup alarm...");
|
||||
|
||||
start_wakeup_alarm(time_until_next_alarm);
|
||||
|
||||
trace!("low power wait for rtc ready...");
|
||||
|
||||
Self::get_scb().set_sleepdeep();
|
||||
});
|
||||
trace!("low power: enter stop...");
|
||||
self.scb.set_sleepdeep();
|
||||
}
|
||||
|
||||
/// Run the executor.
|
||||
@ -126,11 +140,11 @@ impl Executor {
|
||||
///
|
||||
/// This function never returns.
|
||||
pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
|
||||
init(self.inner.spawner());
|
||||
init(unsafe { EXECUTOR.as_mut().unwrap() }.inner.spawner());
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
self.inner.poll();
|
||||
EXECUTOR.as_mut().unwrap().inner.poll();
|
||||
self.configure_pwr();
|
||||
asm!("wfe");
|
||||
};
|
||||
|
151
embassy-stm32/src/rcc/bd.rs
Normal file
151
embassy-stm32/src/rcc/bd.rs
Normal file
@ -0,0 +1,151 @@
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[repr(u8)]
|
||||
#[allow(dead_code)]
|
||||
pub enum RtcClockSource {
|
||||
/// 00: No clock
|
||||
NoClock = 0b00,
|
||||
/// 01: LSE oscillator clock used as RTC clock
|
||||
LSE = 0b01,
|
||||
/// 10: LSI oscillator clock used as RTC clock
|
||||
LSI = 0b10,
|
||||
/// 11: HSE oscillator clock divided by 32 used as RTC clock
|
||||
HSE = 0b11,
|
||||
}
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1, stm32c0)))]
|
||||
#[allow(dead_code)]
|
||||
type Bdcr = crate::pac::rcc::regs::Bdcr;
|
||||
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
#[allow(dead_code)]
|
||||
type Bdcr = crate::pac::rcc::regs::Csr;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct BackupDomain {}
|
||||
|
||||
impl BackupDomain {
|
||||
#[cfg(any(
|
||||
rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb, rtc_v3,
|
||||
rtc_v3u5
|
||||
))]
|
||||
#[allow(dead_code, unused_variables)]
|
||||
fn modify<R>(f: impl FnOnce(&mut Bdcr) -> R) -> R {
|
||||
#[cfg(any(rtc_v2f2, rtc_v2f3, rtc_v2l1))]
|
||||
let cr = crate::pac::PWR.cr();
|
||||
#[cfg(any(rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb, rtc_v3, rtc_v3u5))]
|
||||
let cr = crate::pac::PWR.cr1();
|
||||
|
||||
// TODO: Missing from PAC for l0 and f0?
|
||||
#[cfg(not(any(rtc_v2f0, rtc_v2l0, rtc_v3u5)))]
|
||||
{
|
||||
cr.modify(|w| w.set_dbp(true));
|
||||
while !cr.read().dbp() {}
|
||||
}
|
||||
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let cr = crate::pac::RCC.csr();
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let cr = crate::pac::RCC.bdcr();
|
||||
|
||||
cr.modify(|w| f(w))
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb, rtc_v3,
|
||||
rtc_v3u5
|
||||
))]
|
||||
#[allow(dead_code)]
|
||||
fn read() -> Bdcr {
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let r = crate::pac::RCC.csr().read();
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let r = crate::pac::RCC.bdcr().read();
|
||||
|
||||
r
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb, rtc_v3,
|
||||
rtc_v3u5
|
||||
))]
|
||||
#[allow(dead_code, unused_variables)]
|
||||
pub fn set_rtc_clock_source(clock_source: RtcClockSource) {
|
||||
let clock_source = clock_source as u8;
|
||||
#[cfg(any(
|
||||
all(not(any(rtc_v3, rtc_v3u5)), not(rtc_v2wb)),
|
||||
all(any(rtc_v3, rtc_v3u5), not(any(rcc_wl5, rcc_wle)))
|
||||
))]
|
||||
let clock_source = crate::pac::rcc::vals::Rtcsel::from_bits(clock_source);
|
||||
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
Self::modify(|w| {
|
||||
// Select RTC source
|
||||
w.set_rtcsel(clock_source);
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
rtc_v2f0, rtc_v2f2, rtc_v2f3, rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l0, rtc_v2l1, rtc_v2l4, rtc_v2wb
|
||||
))]
|
||||
#[allow(dead_code)]
|
||||
pub fn enable_rtc() {
|
||||
let reg = Self::read();
|
||||
|
||||
#[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
|
||||
|
||||
if !reg.rtcen() {
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1, rtc_v2f2)))]
|
||||
Self::modify(|w| w.set_bdrst(true));
|
||||
|
||||
Self::modify(|w| {
|
||||
// Reset
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
w.set_bdrst(false);
|
||||
|
||||
w.set_rtcen(true);
|
||||
w.set_rtcsel(reg.rtcsel());
|
||||
|
||||
// Restore bcdr
|
||||
#[cfg(any(rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lscosel(reg.lscosel());
|
||||
#[cfg(any(rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lscoen(reg.lscoen());
|
||||
|
||||
w.set_lseon(reg.lseon());
|
||||
|
||||
#[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lsedrv(reg.lsedrv());
|
||||
w.set_lsebyp(reg.lsebyp());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(rtc_v3, rtc_v3u5))]
|
||||
#[allow(dead_code)]
|
||||
pub fn enable_rtc() {
|
||||
let reg = Self::read();
|
||||
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
|
||||
|
||||
if !reg.rtcen() {
|
||||
Self::modify(|w| w.set_bdrst(true));
|
||||
|
||||
Self::modify(|w| {
|
||||
w.set_bdrst(false);
|
||||
|
||||
w.set_rtcen(true);
|
||||
w.set_rtcsel(reg.rtcsel());
|
||||
|
||||
// Restore bcdr
|
||||
w.set_lscosel(reg.lscosel());
|
||||
w.set_lscoen(reg.lscoen());
|
||||
|
||||
w.set_lseon(reg.lseon());
|
||||
w.set_lsedrv(reg.lsedrv());
|
||||
w.set_lsebyp(reg.lsebyp());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::flash::vals::Latency;
|
||||
use crate::pac::rcc::vals::{Hsidiv, Ppre, Sw};
|
||||
use crate::pac::{FLASH, RCC};
|
||||
|
@ -1,7 +1,7 @@
|
||||
use core::convert::TryFrom;
|
||||
use core::ops::{Div, Mul};
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::flash::vals::Latency;
|
||||
use crate::pac::rcc::vals::{Pllp, Pllsrc, Sw};
|
||||
use crate::pac::{FLASH, RCC};
|
||||
@ -201,7 +201,7 @@ pub struct PLLClocks {
|
||||
pub pll48_freq: Hertz,
|
||||
}
|
||||
|
||||
pub use super::common::VoltageScale;
|
||||
pub use super::bus::VoltageScale;
|
||||
|
||||
impl VoltageScale {
|
||||
const fn wait_states(&self, ahb_freq: Hertz) -> Option<Latency> {
|
||||
|
@ -201,9 +201,9 @@ fn calc_pll(config: &Config, Hertz(sysclk): Hertz) -> (Hertz, PllConfig) {
|
||||
// Calculates the Multiplier and the Divisor to arrive at
|
||||
// the required System clock from PLL source frequency
|
||||
let get_mul_div = |sysclk, pllsrcclk| {
|
||||
let common_div = gcd(sysclk, pllsrcclk);
|
||||
let mut multiplier = sysclk / common_div;
|
||||
let mut divisor = pllsrcclk / common_div;
|
||||
let bus_div = gcd(sysclk, pllsrcclk);
|
||||
let mut multiplier = sysclk / bus_div;
|
||||
let mut divisor = pllsrcclk / bus_div;
|
||||
// Minimum PLL multiplier is two
|
||||
if multiplier == 1 {
|
||||
multiplier *= 2;
|
||||
|
@ -8,8 +8,8 @@ use crate::gpio::sealed::AFType;
|
||||
use crate::gpio::Speed;
|
||||
use crate::pac::rcc::vals::{Hpre, Ppre, Sw};
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
use crate::rcc::bd::{BackupDomain, RtcClockSource};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
use crate::rtc::{Rtc, RtcClockSource};
|
||||
use crate::time::Hertz;
|
||||
use crate::{peripherals, Peripheral};
|
||||
|
||||
@ -470,7 +470,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
}
|
||||
|
||||
config.rtc.map(|clock_source| {
|
||||
Rtc::set_clock_source(clock_source);
|
||||
BackupDomain::set_rtc_clock_source(clock_source);
|
||||
});
|
||||
|
||||
let rtc = match config.rtc {
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::flash::vals::Latency;
|
||||
use crate::pac::rcc::vals::{self, Hsidiv, Ppre, Sw};
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
|
@ -2,7 +2,7 @@ use stm32_metapac::flash::vals::Latency;
|
||||
use stm32_metapac::rcc::vals::{Hpre, Pllsrc, Ppre, Sw};
|
||||
use stm32_metapac::FLASH;
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::{PWR, RCC};
|
||||
use crate::rcc::sealed::RccPeripheral;
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
|
@ -26,7 +26,7 @@ const VCO_MAX: u32 = 420_000_000;
|
||||
const VCO_WIDE_MIN: u32 = 128_000_000;
|
||||
const VCO_WIDE_MAX: u32 = 560_000_000;
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler, VoltageScale};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler, VoltageScale};
|
||||
|
||||
pub enum HseMode {
|
||||
/// crystal/ceramic oscillator (HSEBYP=0)
|
||||
|
@ -24,7 +24,7 @@ pub const HSI48_FREQ: Hertz = Hertz(48_000_000);
|
||||
/// LSI speed
|
||||
pub const LSI_FREQ: Hertz = Hertz(32_000);
|
||||
|
||||
pub use super::common::VoltageScale;
|
||||
pub use super::bus::VoltageScale;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum AdcClockSource {
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
|
||||
use crate::pac::RCC;
|
||||
#[cfg(crs)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
|
||||
use crate::pac::{FLASH, RCC};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
|
@ -4,13 +4,13 @@ use embassy_hal_internal::into_ref;
|
||||
use stm32_metapac::rcc::regs::Cfgr;
|
||||
use stm32_metapac::rcc::vals::{Lsedrv, Mcopre, Mcosel};
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::gpio::sealed::AFType;
|
||||
use crate::gpio::Speed;
|
||||
use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
use crate::rcc::bd::{BackupDomain, RtcClockSource};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
use crate::rtc::{Rtc, RtcClockSource as RCS};
|
||||
use crate::time::Hertz;
|
||||
use crate::{peripherals, Peripheral};
|
||||
|
||||
@ -254,16 +254,11 @@ impl Default for Config {
|
||||
pllsai1: None,
|
||||
#[cfg(not(any(stm32l471, stm32l475, stm32l476, stm32l486)))]
|
||||
hsi48: false,
|
||||
rtc_mux: RtcClockSource::LSI32,
|
||||
rtc_mux: RtcClockSource::LSI,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum RtcClockSource {
|
||||
LSE32,
|
||||
LSI32,
|
||||
}
|
||||
|
||||
pub enum McoClock {
|
||||
DIV1,
|
||||
DIV2,
|
||||
@ -413,7 +408,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
RCC.apb1enr1().modify(|w| w.set_pwren(true));
|
||||
|
||||
match config.rtc_mux {
|
||||
RtcClockSource::LSE32 => {
|
||||
RtcClockSource::LSE => {
|
||||
// 1. Unlock the backup domain
|
||||
PWR.cr1().modify(|w| w.set_dbp(true));
|
||||
|
||||
@ -429,17 +424,18 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
// Wait until LSE is running
|
||||
while !RCC.bdcr().read().lserdy() {}
|
||||
|
||||
Rtc::set_clock_source(RCS::LSE);
|
||||
BackupDomain::set_rtc_clock_source(RtcClockSource::LSE);
|
||||
}
|
||||
RtcClockSource::LSI32 => {
|
||||
RtcClockSource::LSI => {
|
||||
// Turn on the internal 32 kHz LSI oscillator
|
||||
RCC.csr().modify(|w| w.set_lsion(true));
|
||||
|
||||
// Wait until LSI is running
|
||||
while !RCC.csr().read().lsirdy() {}
|
||||
|
||||
Rtc::set_clock_source(RCS::LSI);
|
||||
BackupDomain::set_rtc_clock_source(RtcClockSource::LSI);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let (sys_clk, sw) = match config.mux {
|
||||
@ -451,7 +447,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
w.set_msirgsel(true);
|
||||
w.set_msion(true);
|
||||
|
||||
if let RtcClockSource::LSE32 = config.rtc_mux {
|
||||
if let RtcClockSource::LSE = config.rtc_mux {
|
||||
// If LSE is enabled, enable calibration of MSI
|
||||
w.set_msipllen(true);
|
||||
} else {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use stm32_metapac::PWR;
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw};
|
||||
use crate::pac::{FLASH, RCC};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
|
@ -1,9 +1,10 @@
|
||||
#![macro_use]
|
||||
|
||||
pub mod common;
|
||||
|
||||
pub(crate) mod bd;
|
||||
pub mod bus;
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
pub use crate::rcc::bd::RtcClockSource;
|
||||
use crate::time::Hertz;
|
||||
|
||||
#[cfg_attr(rcc_f0, path = "f0.rs")]
|
||||
@ -86,6 +87,8 @@ static CLOCK_REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
pub fn low_power_ready() -> bool {
|
||||
trace!("clock refcount: {}", CLOCK_REFCOUNT.load(Ordering::SeqCst));
|
||||
|
||||
CLOCK_REFCOUNT.load(Ordering::SeqCst) == 0
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use stm32_metapac::rcc::vals::{Msirange, Msirgsel, Pllm, Pllsrc, Sw};
|
||||
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::pac::{FLASH, RCC};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
use crate::time::Hertz;
|
||||
@ -11,7 +11,7 @@ pub const HSI_FREQ: Hertz = Hertz(16_000_000);
|
||||
/// LSI speed
|
||||
pub const LSI_FREQ: Hertz = Hertz(32_000);
|
||||
|
||||
pub use super::common::VoltageScale;
|
||||
pub use super::bus::VoltageScale;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub enum ClockSrc {
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler};
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||
use crate::rcc::bd::{BackupDomain, RtcClockSource};
|
||||
use crate::rcc::Clocks;
|
||||
use crate::rtc::{Rtc, RtcClockSource};
|
||||
use crate::time::{khz, mhz, Hertz};
|
||||
|
||||
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
|
||||
@ -375,5 +375,7 @@ pub(crate) fn configure_clocks(config: &Config) {
|
||||
w.set_shdhpre(config.ahb3_pre.into());
|
||||
});
|
||||
|
||||
config.rtc.map(|clock_source| Rtc::set_clock_source(clock_source));
|
||||
config
|
||||
.rtc
|
||||
.map(|clock_source| BackupDomain::set_rtc_clock_source(clock_source));
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
pub use super::common::{AHBPrescaler, APBPrescaler, VoltageScale};
|
||||
use crate::pac::pwr::vals::Dbp;
|
||||
pub use super::bus::{AHBPrescaler, APBPrescaler, VoltageScale};
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
use crate::rcc::bd::{BackupDomain, RtcClockSource};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
use crate::rtc::{Rtc, RtcClockSource as RCS};
|
||||
use crate::time::Hertz;
|
||||
|
||||
/// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC,
|
||||
@ -130,16 +129,11 @@ impl Default for Config {
|
||||
apb2_pre: APBPrescaler::NotDivided,
|
||||
enable_lsi: false,
|
||||
enable_rtc_apb: false,
|
||||
rtc_mux: RtcClockSource::LSI32,
|
||||
rtc_mux: RtcClockSource::LSI,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum RtcClockSource {
|
||||
LSE32,
|
||||
LSI32,
|
||||
}
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum Lsedrv {
|
||||
Low = 0,
|
||||
@ -215,9 +209,9 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
while FLASH.acr().read().latency() != ws {}
|
||||
|
||||
match config.rtc_mux {
|
||||
RtcClockSource::LSE32 => {
|
||||
RtcClockSource::LSE => {
|
||||
// 1. Unlock the backup domain
|
||||
PWR.cr1().modify(|w| w.set_dbp(Dbp::ENABLED));
|
||||
PWR.cr1().modify(|w| w.set_dbp(true));
|
||||
|
||||
// 2. Setup the LSE
|
||||
RCC.bdcr().modify(|w| {
|
||||
@ -231,17 +225,18 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
// Wait until LSE is running
|
||||
while !RCC.bdcr().read().lserdy() {}
|
||||
|
||||
Rtc::set_clock_source(RCS::LSE);
|
||||
BackupDomain::set_rtc_clock_source(RtcClockSource::LSE);
|
||||
}
|
||||
RtcClockSource::LSI32 => {
|
||||
RtcClockSource::LSI => {
|
||||
// Turn on the internal 32 kHz LSI oscillator
|
||||
RCC.csr().modify(|w| w.set_lsion(true));
|
||||
|
||||
// Wait until LSI is running
|
||||
while !RCC.csr().read().lsirdy() {}
|
||||
|
||||
Rtc::set_clock_source(RCS::LSI);
|
||||
BackupDomain::set_rtc_clock_source(RtcClockSource::LSI);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
match config.mux {
|
||||
@ -266,7 +261,7 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
w.set_msirange(range.into());
|
||||
w.set_msion(true);
|
||||
|
||||
if let RtcClockSource::LSE32 = config.rtc_mux {
|
||||
if let RtcClockSource::LSE = config.rtc_mux {
|
||||
// If LSE is enabled, enable calibration of MSI
|
||||
w.set_msipllen(true);
|
||||
} else {
|
||||
|
@ -89,7 +89,7 @@ pub enum DayOfWeek {
|
||||
#[cfg(feature = "chrono")]
|
||||
impl From<chrono::Weekday> for DayOfWeek {
|
||||
fn from(weekday: Weekday) -> Self {
|
||||
day_of_week_from_u8(weekday.number_from_monday() as u8).unwrap()
|
||||
day_of_week_from_u8(weekday.num_days_from_monday() as u8).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,17 @@
|
||||
//! RTC peripheral abstraction
|
||||
mod datetime;
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
use core::cell::Cell;
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
#[cfg(feature = "low-power")]
|
||||
use embassy_sync::blocking_mutex::Mutex;
|
||||
|
||||
pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError};
|
||||
use crate::rcc::bd::BackupDomain;
|
||||
pub use crate::rcc::RtcClockSource;
|
||||
|
||||
/// refer to AN4759 to compare features of RTC2 and RTC3
|
||||
#[cfg_attr(any(rtc_v1), path = "v1.rs")]
|
||||
@ -30,22 +40,73 @@ pub enum RtcError {
|
||||
NotRunning,
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Represents an instant in time that can be substracted to compute a duration
|
||||
struct RtcInstant {
|
||||
second: u8,
|
||||
subsecond: u16,
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
impl RtcInstant {
|
||||
pub fn now() -> Self {
|
||||
let tr = RTC::regs().tr().read();
|
||||
let tr2 = RTC::regs().tr().read();
|
||||
let ssr = RTC::regs().ssr().read().ss();
|
||||
let ssr2 = RTC::regs().ssr().read().ss();
|
||||
|
||||
let st = bcd2_to_byte((tr.st(), tr.su()));
|
||||
let st2 = bcd2_to_byte((tr2.st(), tr2.su()));
|
||||
|
||||
assert!(st == st2);
|
||||
assert!(ssr == ssr2);
|
||||
|
||||
let _ = RTC::regs().dr().read();
|
||||
|
||||
let subsecond = ssr;
|
||||
let second = st;
|
||||
|
||||
// trace!("rtc: instant now: st, ssr: {}, {}", st, ssr);
|
||||
|
||||
Self { second, subsecond }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
impl core::ops::Sub for RtcInstant {
|
||||
type Output = embassy_time::Duration;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
use embassy_time::{Duration, TICK_HZ};
|
||||
|
||||
let second = if self.second < rhs.second {
|
||||
self.second + 60
|
||||
} else {
|
||||
self.second
|
||||
};
|
||||
|
||||
// TODO: read prescaler
|
||||
|
||||
let self_ticks = second as u32 * 256 + (255 - self.subsecond as u32);
|
||||
let other_ticks = rhs.second as u32 * 256 + (255 - rhs.subsecond as u32);
|
||||
let rtc_ticks = self_ticks - other_ticks;
|
||||
|
||||
// trace!(
|
||||
// "rtc: instant sub: self, other, rtc ticks: {}, {}, {}",
|
||||
// self_ticks,
|
||||
// other_ticks,
|
||||
// rtc_ticks
|
||||
// );
|
||||
|
||||
Duration::from_ticks(((rtc_ticks * TICK_HZ as u32) / 256u32) as u64)
|
||||
}
|
||||
}
|
||||
|
||||
/// RTC Abstraction
|
||||
pub struct Rtc {
|
||||
rtc_config: RtcConfig,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum RtcClockSource {
|
||||
/// 00: No clock
|
||||
NoClock = 0b00,
|
||||
/// 01: LSE oscillator clock used as RTC clock
|
||||
LSE = 0b01,
|
||||
/// 10: LSI oscillator clock used as RTC clock
|
||||
LSI = 0b10,
|
||||
/// 11: HSE oscillator clock divided by 32 used as RTC clock
|
||||
HSE = 0b11,
|
||||
#[cfg(feature = "low-power")]
|
||||
stop_time: Mutex<CriticalSectionRawMutex, Cell<Option<RtcInstant>>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
@ -108,9 +169,16 @@ impl Rtc {
|
||||
pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self {
|
||||
RTC::enable_peripheral_clk();
|
||||
|
||||
#[cfg(not(feature = "low-power"))]
|
||||
let mut rtc_struct = Self { rtc_config };
|
||||
|
||||
Self::enable();
|
||||
#[cfg(feature = "low-power")]
|
||||
let mut rtc_struct = Self {
|
||||
rtc_config,
|
||||
stop_time: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)),
|
||||
};
|
||||
|
||||
BackupDomain::enable_rtc();
|
||||
|
||||
rtc_struct.configure(rtc_config);
|
||||
rtc_struct.rtc_config = rtc_config;
|
||||
|
@ -1,67 +1,12 @@
|
||||
use stm32_metapac::rtc::vals::{Init, Osel, Pol};
|
||||
|
||||
use super::{sealed, RtcClockSource, RtcConfig};
|
||||
#[cfg(feature = "low-power")]
|
||||
use super::RtcInstant;
|
||||
use super::{sealed, RtcConfig};
|
||||
use crate::pac::rtc::Rtc;
|
||||
use crate::peripherals::RTC;
|
||||
use crate::rtc::sealed::Instance;
|
||||
|
||||
#[cfg(all(feature = "time", any(stm32wb, stm32f4)))]
|
||||
pub struct RtcInstant {
|
||||
ssr: u16,
|
||||
st: u8,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "time", any(stm32wb, stm32f4)))]
|
||||
impl RtcInstant {
|
||||
pub fn now() -> Self {
|
||||
// TODO: read value twice
|
||||
use crate::rtc::bcd2_to_byte;
|
||||
|
||||
let tr = RTC::regs().tr().read();
|
||||
let tr2 = RTC::regs().tr().read();
|
||||
let ssr = RTC::regs().ssr().read().ss();
|
||||
let ssr2 = RTC::regs().ssr().read().ss();
|
||||
|
||||
let st = bcd2_to_byte((tr.st(), tr.su()));
|
||||
let st2 = bcd2_to_byte((tr2.st(), tr2.su()));
|
||||
|
||||
assert!(st == st2);
|
||||
assert!(ssr == ssr2);
|
||||
|
||||
let _ = RTC::regs().dr().read();
|
||||
|
||||
trace!("ssr: {}", ssr);
|
||||
trace!("st: {}", st);
|
||||
|
||||
Self { ssr, st }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "time", any(stm32wb, stm32f4)))]
|
||||
impl core::ops::Sub for RtcInstant {
|
||||
type Output = embassy_time::Duration;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
use embassy_time::{Duration, TICK_HZ};
|
||||
|
||||
let st = if self.st < rhs.st { self.st + 60 } else { self.st };
|
||||
|
||||
// TODO: read prescaler
|
||||
|
||||
let self_ticks = st as u32 * 256 + (255 - self.ssr as u32);
|
||||
let other_ticks = rhs.st as u32 * 256 + (255 - rhs.ssr as u32);
|
||||
let rtc_ticks = self_ticks - other_ticks;
|
||||
|
||||
trace!("self, other, rtc ticks: {}, {}, {}", self_ticks, other_ticks, rtc_ticks);
|
||||
|
||||
Duration::from_ticks(
|
||||
((((st as u32 * 256 + (255u32 - self.ssr as u32)) - (rhs.st as u32 * 256 + (255u32 - rhs.ssr as u32)))
|
||||
* TICK_HZ as u32) as u32
|
||||
/ 256u32) as u64,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum WakeupPrescaler {
|
||||
@ -128,31 +73,10 @@ impl WakeupPrescaler {
|
||||
}
|
||||
|
||||
impl super::Rtc {
|
||||
fn unlock_registers() {
|
||||
#[cfg(any(rtc_v2f2, rtc_v2f3, rtc_v2l1))]
|
||||
let cr = crate::pac::PWR.cr();
|
||||
#[cfg(any(rtc_v2f4, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
let cr = crate::pac::PWR.cr1();
|
||||
|
||||
// TODO: Missing from PAC for l0 and f0?
|
||||
#[cfg(not(any(rtc_v2f0, rtc_v2l0)))]
|
||||
{
|
||||
if !cr.read().dbp() {
|
||||
cr.modify(|w| w.set_dbp(true));
|
||||
while !cr.read().dbp() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(all(feature = "time", any(stm32wb, stm32f4)))]
|
||||
/// start the wakeup alarm and return the actual duration of the alarm
|
||||
/// the actual duration will be the closest value possible that is less
|
||||
/// than the requested duration.
|
||||
///
|
||||
/// note: this api is exposed for testing purposes until low power is implemented.
|
||||
/// it is not intended to be public
|
||||
pub(crate) fn start_wakeup_alarm(&self, requested_duration: embassy_time::Duration) -> RtcInstant {
|
||||
#[cfg(feature = "low-power")]
|
||||
/// start the wakeup alarm and wtih a duration that is as close to but less than
|
||||
/// the requested duration, and record the instant the wakeup alarm was started
|
||||
pub(crate) fn start_wakeup_alarm(&self, requested_duration: embassy_time::Duration) {
|
||||
use embassy_time::{Duration, TICK_HZ};
|
||||
|
||||
use crate::rcc::get_freqs;
|
||||
@ -174,100 +98,45 @@ impl super::Rtc {
|
||||
rtc_ticks as u64 * TICK_HZ * (<WakeupPrescaler as Into<u32>>::into(prescaler) as u64) / rtc_hz,
|
||||
);
|
||||
|
||||
trace!("set wakeup timer for {} ms", duration.as_millis());
|
||||
|
||||
self.write(false, |regs| {
|
||||
regs.cr().modify(|w| w.set_wutie(true));
|
||||
|
||||
regs.cr().modify(|w| w.set_wute(false));
|
||||
regs.isr().modify(|w| w.set_wutf(false));
|
||||
while !regs.isr().read().wutwf() {}
|
||||
|
||||
regs.cr().modify(|w| w.set_wucksel(prescaler.into()));
|
||||
regs.cr().modify(|w| w.set_wute(true));
|
||||
regs.cr().modify(|w| w.set_wutie(true));
|
||||
});
|
||||
|
||||
RtcInstant::now()
|
||||
trace!("rtc: start wakeup alarm for {} ms", duration.as_millis());
|
||||
|
||||
critical_section::with(|cs| assert!(self.stop_time.borrow(cs).replace(Some(RtcInstant::now())).is_none()))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[cfg(all(feature = "time", any(stm32wb, stm32f4)))]
|
||||
/// stop the wakeup alarm and return the time remaining
|
||||
///
|
||||
/// note: this api is exposed for testing purposes until low power is implemented.
|
||||
/// it is not intended to be public
|
||||
pub(crate) fn stop_wakeup_alarm(&self) -> RtcInstant {
|
||||
trace!("disable wakeup timer...");
|
||||
#[cfg(feature = "low-power")]
|
||||
/// stop the wakeup alarm and return the time elapsed since `start_wakeup_alarm`
|
||||
/// was called, otherwise none
|
||||
pub(crate) fn stop_wakeup_alarm(&self) -> Option<embassy_time::Duration> {
|
||||
use crate::interrupt::typelevel::Interrupt;
|
||||
|
||||
trace!("rtc: stop wakeup alarm...");
|
||||
|
||||
self.write(false, |regs| {
|
||||
regs.cr().modify(|w| w.set_wutie(false));
|
||||
regs.cr().modify(|w| w.set_wute(false));
|
||||
regs.isr().modify(|w| w.set_wutf(false));
|
||||
|
||||
crate::pac::EXTI.pr(0).modify(|w| w.set_line(22, true));
|
||||
crate::interrupt::typelevel::RTC_WKUP::unpend();
|
||||
});
|
||||
|
||||
RtcInstant::now()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_clock_source(clock_source: RtcClockSource) {
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
use stm32_metapac::rcc::vals::Rtcsel;
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let cr = crate::pac::RCC.bdcr();
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let cr = crate::pac::RCC.csr();
|
||||
|
||||
Self::unlock_registers();
|
||||
|
||||
cr.modify(|w| {
|
||||
// Select RTC source
|
||||
#[cfg(not(rtc_v2wb))]
|
||||
w.set_rtcsel(Rtcsel::from_bits(clock_source as u8));
|
||||
#[cfg(rtc_v2wb)]
|
||||
w.set_rtcsel(clock_source as u8);
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn enable() {
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let reg = crate::pac::RCC.bdcr().read();
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let reg = crate::pac::RCC.csr().read();
|
||||
|
||||
#[cfg(any(rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
|
||||
|
||||
if !reg.rtcen() {
|
||||
Self::unlock_registers();
|
||||
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1, rtc_v2f2)))]
|
||||
crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true));
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
let cr = crate::pac::RCC.bdcr();
|
||||
#[cfg(any(rtc_v2l0, rtc_v2l1))]
|
||||
let cr = crate::pac::RCC.csr();
|
||||
|
||||
cr.modify(|w| {
|
||||
// Reset
|
||||
#[cfg(not(any(rtc_v2l0, rtc_v2l1)))]
|
||||
w.set_bdrst(false);
|
||||
|
||||
w.set_rtcen(true);
|
||||
w.set_rtcsel(reg.rtcsel());
|
||||
|
||||
// Restore bcdr
|
||||
#[cfg(any(rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lscosel(reg.lscosel());
|
||||
#[cfg(any(rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lscoen(reg.lscoen());
|
||||
|
||||
w.set_lseon(reg.lseon());
|
||||
|
||||
#[cfg(any(rtc_v2f0, rtc_v2f7, rtc_v2h7, rtc_v2l4, rtc_v2wb))]
|
||||
w.set_lsedrv(reg.lsedrv());
|
||||
w.set_lsebyp(reg.lsebyp());
|
||||
});
|
||||
}
|
||||
critical_section::with(|cs| {
|
||||
if let Some(stop_time) = self.stop_time.borrow(cs).take() {
|
||||
Some(RtcInstant::now() - stop_time)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Applies the RTC config
|
||||
|
@ -1,74 +1,11 @@
|
||||
use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Init, Key, Osel, Pol, TampalrmPu, TampalrmType};
|
||||
|
||||
use super::{sealed, RtcCalibrationCyclePeriod, RtcClockSource, RtcConfig};
|
||||
use super::{sealed, RtcCalibrationCyclePeriod, RtcConfig};
|
||||
use crate::pac::rtc::Rtc;
|
||||
use crate::peripherals::RTC;
|
||||
use crate::rtc::sealed::Instance;
|
||||
|
||||
impl super::Rtc {
|
||||
fn unlock_registers() {
|
||||
// Unlock the backup domain
|
||||
#[cfg(not(any(rtc_v3u5, rcc_wl5, rcc_wle)))]
|
||||
{
|
||||
if !crate::pac::PWR.cr1().read().dbp() {
|
||||
crate::pac::PWR.cr1().modify(|w| w.set_dbp(true));
|
||||
while !crate::pac::PWR.cr1().read().dbp() {}
|
||||
}
|
||||
}
|
||||
#[cfg(any(rcc_wl5, rcc_wle))]
|
||||
{
|
||||
use crate::pac::pwr::vals::Dbp;
|
||||
|
||||
if crate::pac::PWR.cr1().read().dbp() != Dbp::ENABLED {
|
||||
crate::pac::PWR.cr1().modify(|w| w.set_dbp(Dbp::ENABLED));
|
||||
while crate::pac::PWR.cr1().read().dbp() != Dbp::ENABLED {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_clock_source(clock_source: RtcClockSource) {
|
||||
let clock_source = clock_source as u8;
|
||||
#[cfg(not(any(rcc_wl5, rcc_wle)))]
|
||||
let clock_source = crate::pac::rcc::vals::Rtcsel::from_bits(clock_source);
|
||||
|
||||
Self::unlock_registers();
|
||||
|
||||
crate::pac::RCC.bdcr().modify(|w| {
|
||||
// Select RTC source
|
||||
w.set_rtcsel(clock_source);
|
||||
});
|
||||
}
|
||||
|
||||
pub(super) fn enable() {
|
||||
let bdcr = crate::pac::RCC.bdcr();
|
||||
|
||||
let reg = bdcr.read();
|
||||
assert!(!reg.lsecsson(), "RTC is not compatible with LSE CSS, yet.");
|
||||
|
||||
if !reg.rtcen() {
|
||||
Self::unlock_registers();
|
||||
|
||||
bdcr.modify(|w| w.set_bdrst(true));
|
||||
|
||||
bdcr.modify(|w| {
|
||||
// Reset
|
||||
w.set_bdrst(false);
|
||||
|
||||
w.set_rtcen(true);
|
||||
w.set_rtcsel(reg.rtcsel());
|
||||
|
||||
// Restore bcdr
|
||||
w.set_lscosel(reg.lscosel());
|
||||
w.set_lscoen(reg.lscoen());
|
||||
|
||||
w.set_lseon(reg.lseon());
|
||||
w.set_lsedrv(reg.lsedrv());
|
||||
w.set_lsebyp(reg.lsebyp());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies the RTC config
|
||||
/// It this changes the RTC clock source the time will be reset
|
||||
pub(super) fn configure(&mut self, rtc_config: RtcConfig) {
|
||||
|
@ -14,6 +14,8 @@ use stm32_metapac::timer::regs;
|
||||
use crate::interrupt::typelevel::Interrupt;
|
||||
use crate::pac::timer::vals;
|
||||
use crate::rcc::sealed::RccPeripheral;
|
||||
#[cfg(feature = "low-power")]
|
||||
use crate::rtc::Rtc;
|
||||
use crate::timer::sealed::{Basic16bitInstance as BasicInstance, GeneralPurpose16bitInstance as Instance};
|
||||
use crate::{interrupt, peripherals};
|
||||
|
||||
@ -130,12 +132,14 @@ impl AlarmState {
|
||||
}
|
||||
}
|
||||
|
||||
struct RtcDriver {
|
||||
pub(crate) struct RtcDriver {
|
||||
/// Number of 2^15 periods elapsed since boot.
|
||||
period: AtomicU32,
|
||||
alarm_count: AtomicU8,
|
||||
/// Timestamp at which to fire alarm. u64::MAX if no alarm is scheduled.
|
||||
alarms: Mutex<CriticalSectionRawMutex, [AlarmState; ALARM_COUNT]>,
|
||||
#[cfg(feature = "low-power")]
|
||||
rtc: Mutex<CriticalSectionRawMutex, Cell<Option<&'static Rtc>>>,
|
||||
}
|
||||
|
||||
const ALARM_STATE_NEW: AlarmState = AlarmState::new();
|
||||
@ -144,6 +148,8 @@ embassy_time::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver {
|
||||
period: AtomicU32::new(0),
|
||||
alarm_count: AtomicU8::new(0),
|
||||
alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]),
|
||||
#[cfg(feature = "low-power")]
|
||||
rtc: Mutex::const_new(CriticalSectionRawMutex::new(), Cell::new(None)),
|
||||
});
|
||||
|
||||
impl RtcDriver {
|
||||
@ -259,6 +265,117 @@ impl RtcDriver {
|
||||
let f: fn(*mut ()) = unsafe { mem::transmute(alarm.callback.get()) };
|
||||
f(alarm.ctx.get());
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Set the rtc but panic if it's already been set
|
||||
pub(crate) fn set_rtc(&self, rtc: &'static Rtc) {
|
||||
critical_section::with(|cs| assert!(self.rtc.borrow(cs).replace(Some(rtc)).is_none()));
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Compute the approximate amount of time until the next alarm
|
||||
fn time_until_next_alarm(&self) -> embassy_time::Duration {
|
||||
critical_section::with(|cs| {
|
||||
let now = self.now() + 32;
|
||||
|
||||
embassy_time::Duration::from_ticks(
|
||||
self.alarms
|
||||
.borrow(cs)
|
||||
.iter()
|
||||
.map(|alarm: &AlarmState| alarm.timestamp.get().saturating_sub(now))
|
||||
.min()
|
||||
.unwrap_or(u64::MAX),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Add the given offset to the current time
|
||||
fn add_time(&self, offset: embassy_time::Duration) {
|
||||
let offset = offset.as_ticks();
|
||||
let cnt = T::regs_gp16().cnt().read().cnt() as u32;
|
||||
let period = self.period.load(Ordering::SeqCst);
|
||||
|
||||
// Correct the race, if it exists
|
||||
let period = if period & 1 == 1 && cnt < u16::MAX as u32 / 2 {
|
||||
period + 1
|
||||
} else {
|
||||
period
|
||||
};
|
||||
|
||||
// Normalize to the full overflow
|
||||
let period = (period / 2) * 2;
|
||||
|
||||
// Add the offset
|
||||
let period = period + 2 * (offset / u16::MAX as u64) as u32;
|
||||
let cnt = cnt + (offset % u16::MAX as u64) as u32;
|
||||
|
||||
let (cnt, period) = if cnt > u16::MAX as u32 {
|
||||
(cnt - u16::MAX as u32, period + 2)
|
||||
} else {
|
||||
(cnt, period)
|
||||
};
|
||||
|
||||
let period = if cnt > u16::MAX as u32 / 2 { period + 1 } else { period };
|
||||
|
||||
self.period.store(period, Ordering::SeqCst);
|
||||
T::regs_gp16().cnt().write(|w| w.set_cnt(cnt as u16));
|
||||
|
||||
// Now, recompute all alarms
|
||||
critical_section::with(|cs| {
|
||||
for i in 0..ALARM_COUNT {
|
||||
let alarm_handle = unsafe { AlarmHandle::new(i as u8) };
|
||||
let alarm = self.get_alarm(cs, alarm_handle);
|
||||
|
||||
self.set_alarm(alarm_handle, alarm.timestamp.get());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Stop the wakeup alarm, if enabled, and add the appropriate offset
|
||||
fn stop_wakeup_alarm(&self) {
|
||||
critical_section::with(|cs| {
|
||||
if let Some(offset) = self.rtc.borrow(cs).get().unwrap().stop_wakeup_alarm() {
|
||||
self.add_time(offset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Pause the timer if ready; return err if not
|
||||
pub(crate) fn pause_time(&self) -> Result<(), ()> {
|
||||
/*
|
||||
If the wakeup timer is currently running, then we need to stop it and
|
||||
add the elapsed time to the current time
|
||||
*/
|
||||
self.stop_wakeup_alarm();
|
||||
|
||||
let time_until_next_alarm = self.time_until_next_alarm();
|
||||
if time_until_next_alarm < embassy_time::Duration::from_millis(250) {
|
||||
Err(())
|
||||
} else {
|
||||
critical_section::with(|cs| {
|
||||
self.rtc
|
||||
.borrow(cs)
|
||||
.get()
|
||||
.unwrap()
|
||||
.start_wakeup_alarm(time_until_next_alarm);
|
||||
});
|
||||
|
||||
T::regs_gp16().cr1().modify(|w| w.set_cen(false));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
/// Resume the timer with the given offset
|
||||
pub(crate) fn resume_time(&self) {
|
||||
self.stop_wakeup_alarm();
|
||||
|
||||
T::regs_gp16().cr1().modify(|w| w.set_cen(true));
|
||||
}
|
||||
}
|
||||
|
||||
impl Driver for RtcDriver {
|
||||
@ -329,6 +446,11 @@ impl Driver for RtcDriver {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "low-power")]
|
||||
pub(crate) fn get_driver() -> &'static RtcDriver {
|
||||
&DRIVER
|
||||
}
|
||||
|
||||
pub(crate) fn init() {
|
||||
DRIVER.init()
|
||||
}
|
||||
|
@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 0.1.3 - 2023-08-28
|
||||
|
||||
- Update `embedded-hal-async` to `1.0.0-rc.1`
|
||||
- Update `embedded-hal v1` to `1.0.0-rc.1`
|
||||
|
||||
## 0.1.2 - 2023-07-05
|
||||
|
||||
- Update `embedded-hal-async` to `0.2.0-alpha.2`.
|
||||
@ -26,4 +31,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## 0.1.0 - 2022-08-26
|
||||
|
||||
- First release
|
||||
- First release
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "embassy-time"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
edition = "2021"
|
||||
description = "Instant and Duration for embedded no-std systems, with async timer support"
|
||||
repository = "https://github.com/embassy-rs/embassy"
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../../../embassy-nrf", features = ["time-driver-rtc1", "gpiote", "nightly"] }
|
||||
embassy-boot = { version = "0.1.0", path = "../../../../embassy-boot/boot", features = ["nightly"] }
|
||||
embassy-boot-nrf = { version = "0.1.0", path = "../../../../embassy-boot/nrf", features = ["nightly"] }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../../../embassy-rp", features = ["time-driver", "unstable-traits", "nightly"] }
|
||||
embassy-boot-rp = { version = "0.1.0", path = "../../../../embassy-boot/rp", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f303re", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32f767zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync" }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32h743zi", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l072cz", "time-driver-any", "exti", "memory-x"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l151cb-a", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32l475vg", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../../../embassy-time", features = ["nightly", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../../../embassy-stm32", features = ["unstable-traits", "nightly", "stm32wl55jc-cm4", "time-driver-any", "exti"] }
|
||||
embassy-boot-stm32 = { version = "0.1.0", path = "../../../../embassy-boot/stm32", features = ["nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../../../embassy-embedded-hal" }
|
||||
|
@ -18,7 +18,7 @@ log = [
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync" }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "rtos-trace", "rtos-trace-interrupt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time" }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
|
||||
|
@ -9,7 +9,7 @@ rtic = { version = "2", features = ["thumbv7-backend"] }
|
||||
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "generic-queue"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["nightly", "unstable-traits", "defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -31,7 +31,7 @@ nightly = [
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet"], optional = true }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt", "msos-descriptor",], optional = true }
|
||||
@ -67,4 +67,4 @@ microfft = "0.5.0"
|
||||
debug = 2
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
|
@ -14,7 +14,7 @@ embassy-executor = { version = "0.3.0", path = "../../embassy-executor", feature
|
||||
"defmt",
|
||||
"integrated-timers",
|
||||
] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = [
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = [
|
||||
"defmt",
|
||||
"defmt-timestamp-uptime",
|
||||
] }
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal", features = ["defmt"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
|
||||
@ -57,4 +57,4 @@ rand = { version = "0.8.5", default-features = false }
|
||||
debug = 2
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["log"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-std", "executor-thread", "log", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "std", "nightly"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["log", "std", "nightly"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features=[ "std", "nightly", "log", "medium-ethernet", "medium-ip", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6"] }
|
||||
embassy-net-tuntap = { version = "0.1.0", path = "../../embassy-net-tuntap" }
|
||||
embassy-net-ppp = { version = "0.1.0", path = "../../embassy-net-ppp", features = ["log"]}
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32c031c6", "memory-x", "unstable-pac", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
@ -16,7 +16,7 @@ defmt-rtt = "0.4"
|
||||
panic-probe = "0.3"
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
static_cell = { version = "1.1", features = ["nightly"]}
|
||||
|
||||
[profile.release]
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-any", "unstable-traits" ] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc", "chrono"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
|
||||
|
||||
|
@ -5,13 +5,17 @@
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
let mut config = Config::default();
|
||||
config.rcc.rtc = Option::Some(RtcClockSource::LSI);
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
info!("Hello World!");
|
||||
|
||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||
@ -23,8 +27,11 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||
|
||||
// In reality the delay would be much longer
|
||||
Timer::after(Duration::from_millis(20000)).await;
|
||||
loop {
|
||||
let now: NaiveDateTime = rtc.now().unwrap().into();
|
||||
|
||||
let _then: NaiveDateTime = rtc.now().unwrap().into();
|
||||
info!("{}", now.timestamp());
|
||||
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f767zi", "memory-x", "unstable-pac", "time-driver-any", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
embedded-io-async = { version = "0.5.0" }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g071rb", "memory-x", "unstable-pac", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "time-driver-any", "stm32g491re", "memory-x", "unstable-pac", "exti"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h563zi", "memory-x", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] }
|
||||
embedded-io-async = { version = "0.5.0" }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
|
||||
embassy-net = { path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet", "proto-ipv6"] }
|
||||
embedded-io-async = { version = "0.5.0" }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
@ -14,7 +14,7 @@ nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstab
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true }
|
||||
lora-phy = { version = "1", optional = true }
|
||||
lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
|
||||
@ -39,4 +39,4 @@ static_cell = "1.1"
|
||||
debug = 2
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
|
@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32l151cb-a", "time-driver-any", "memory-x"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l4s5qi", "memory-x", "time-driver-any", "exti", "unstable-traits", "chrono"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768", "unstable-traits", "nightly"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768", "unstable-traits", "nightly"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net-adin1110 = { version = "0.1.0", path = "../../embassy-net-adin1110", default-features = false }
|
||||
|
@ -23,7 +23,7 @@ async fn main(_spawner: Spawner) {
|
||||
PLLMul::Mul20,
|
||||
None,
|
||||
);
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSE;
|
||||
embassy_stm32::init(config)
|
||||
};
|
||||
info!("Hello World!");
|
||||
|
@ -84,7 +84,7 @@ async fn main(spawner: Spawner) {
|
||||
None,
|
||||
);
|
||||
config.rcc.hsi48 = true; // needed for rng
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSI32;
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSI;
|
||||
|
||||
let dp = embassy_stm32::init(config);
|
||||
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32l552ze", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "dhcpv4", "medium-ethernet"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "stm32u585ai", "time-driver-any", "memory-x" ] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -10,7 +10,7 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["
|
||||
embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "udp", "proto-ipv6", "medium-ieee802154", "nightly"], optional=true }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
|
||||
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"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
||||
lora-phy = { version = "1" }
|
||||
@ -32,4 +32,4 @@ chrono = { version = "^0.4", default-features = false }
|
||||
debug = 2
|
||||
|
||||
[patch.crates-io]
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "1323eccc1c470d4259f95f4f315d1be830d572a3"}
|
||||
|
@ -5,8 +5,8 @@
|
||||
use chrono::{NaiveDate, NaiveDateTime};
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::rcc::{self, ClockSrc};
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_stm32::rcc::ClockSrc;
|
||||
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
@ -16,7 +16,7 @@ async fn main(_spawner: Spawner) {
|
||||
let p = {
|
||||
let mut config = Config::default();
|
||||
config.rcc.mux = ClockSrc::HSE32;
|
||||
config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
|
||||
config.rcc.rtc_mux = RtcClockSource::LSE;
|
||||
config.rcc.enable_rtc_apb = true;
|
||||
embassy_stm32::init(config)
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ crate-type = ["cdylib"]
|
||||
[dependencies]
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["log"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-wasm", "executor-thread", "log", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["log", "wasm", "nightly"] }
|
||||
|
||||
wasm-logger = "0.2.0"
|
||||
wasm-bindgen = "0.2"
|
||||
|
@ -10,7 +10,7 @@ teleprobe-meta = "1"
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt", "nightly"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] }
|
||||
embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
|
||||
embedded-io-async = { version = "0.5.0" }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
|
||||
@ -25,4 +25,4 @@ defmt-rtt = "0.4"
|
||||
|
||||
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
|
||||
cortex-m-rt = "0.7.0"
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
|
@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
|
||||
critical-section = { version = "1.1.1", features = ["restore-state-bool"] }
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync" }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["arch-riscv32", "nightly", "executor-thread"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time" }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time" }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
|
||||
riscv-rt = "0.11"
|
||||
|
@ -9,7 +9,7 @@ teleprobe-meta = "1.1"
|
||||
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits"] }
|
||||
embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics", "run-from-ram"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "nightly", "tcp", "udp", "dhcpv4", "medium-ethernet"] }
|
||||
|
@ -7,7 +7,7 @@ autobins = false
|
||||
|
||||
[features]
|
||||
stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] # Blue Pill
|
||||
stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "can", "not-gpdma", "dac-adc-pin"] # Nucleo "sdmmc"
|
||||
stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "stop", "can", "not-gpdma", "dac-adc-pin"] # Nucleo "sdmmc"
|
||||
stm32g071rb = ["embassy-stm32/stm32g071rb", "not-gpdma", "dac-adc-pin"] # Nucleo
|
||||
stm32c031c6 = ["embassy-stm32/stm32c031c6", "not-gpdma"] # Nucleo
|
||||
stm32g491re = ["embassy-stm32/stm32g491re", "not-gpdma"] # Nucleo
|
||||
@ -17,6 +17,7 @@ stm32h563zi = ["embassy-stm32/stm32h563zi"] # Nucleo
|
||||
stm32u585ai = ["embassy-stm32/stm32u585ai"] # IoT board
|
||||
|
||||
sdmmc = []
|
||||
stop = ["embassy-stm32/low-power"]
|
||||
chrono = ["embassy-stm32/chrono", "dep:chrono"]
|
||||
can = []
|
||||
ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/ble"]
|
||||
@ -30,7 +31,7 @@ teleprobe-meta = "1"
|
||||
|
||||
embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||
embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "tick-hz-32_768", "defmt-timestamp-uptime"] }
|
||||
embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "tick-hz-32_768", "defmt-timestamp-uptime"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "unstable-pac", "memory-x", "time-driver-any"] }
|
||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||
embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] }
|
||||
@ -47,6 +48,7 @@ micromath = "2.0.0"
|
||||
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||
rand_core = { version = "0.6", default-features = false }
|
||||
rand_chacha = { version = "0.3", default-features = false }
|
||||
static_cell = {version = "1.1", features = ["nightly"] }
|
||||
|
||||
chrono = { version = "^0.4", default-features = false, optional = true}
|
||||
|
||||
@ -87,6 +89,11 @@ name = "spi_dma"
|
||||
path = "src/bin/spi_dma.rs"
|
||||
required-features = []
|
||||
|
||||
[[bin]]
|
||||
name = "stop"
|
||||
path = "src/bin/stop.rs"
|
||||
required-features = [ "stop", "chrono",]
|
||||
|
||||
[[bin]]
|
||||
name = "timer"
|
||||
path = "src/bin/timer.rs"
|
||||
|
@ -10,7 +10,8 @@ use chrono::{NaiveDate, NaiveDateTime};
|
||||
use common::*;
|
||||
use defmt::assert;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
||||
use embassy_stm32::rcc::RtcClockSource;
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_time::{Duration, Timer};
|
||||
|
||||
#[embassy_executor::main]
|
||||
|
54
tests/stm32/src/bin/stop.rs
Normal file
54
tests/stm32/src/bin/stop.rs
Normal file
@ -0,0 +1,54 @@
|
||||
// required-features: stop,chrono
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#[path = "../common.rs"]
|
||||
mod common;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use common::*;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::low_power::{stop_with_rtc, Executor};
|
||||
use embassy_stm32::rcc::RtcClockSource;
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use static_cell::make_static;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let executor = Executor::take();
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(async_main(spawner)));
|
||||
});
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn async_main(_spawner: Spawner) {
|
||||
let mut config = config();
|
||||
|
||||
config.rcc.rtc = Some(RtcClockSource::LSI);
|
||||
|
||||
let p = embassy_stm32::init(config);
|
||||
info!("Hello World!");
|
||||
|
||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||
.unwrap()
|
||||
.and_hms_opt(10, 30, 15)
|
||||
.unwrap();
|
||||
|
||||
let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
|
||||
|
||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||
|
||||
let rtc = make_static!(rtc);
|
||||
|
||||
stop_with_rtc(rtc);
|
||||
|
||||
info!("Waiting 5 seconds");
|
||||
Timer::after(Duration::from_secs(5)).await;
|
||||
|
||||
info!("Test OK");
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
Reference in New Issue
Block a user