embassy-stm32

Crates

git

Versions

stm32g484ce

Flavors

embassy_stm32

Module low_power

Source
Expand description

Low-power support.

The STM32 line of microcontrollers support various deep-sleep modes which exploit clock-gating to reduce power consumption. embassy-stm32 provides a low-power executor, Executor which can use knowledge of which peripherals are currently blocked upon to transparently and safely enter such low-power modes (currently, only STOP2) when idle.

The executor determines which peripherals are active by their RCC state; consequently, low-power states can only be entered if all peripherals have been drop’d. There are a few exceptions to this rule:

  • GPIO
  • RTC

Since entering and leaving low-power modes typically incurs a significant latency, the low-power executor will only attempt to enter when the next timer event is at least [time_driver::MIN_STOP_PAUSE] in the future.

Currently there is no macro analogous to embassy_executor::main for this executor; consequently one must define their entrypoint manually. Moreover, you must relinquish control of the RTC peripheral to the executor. This will typically look like

use embassy_executor::Spawner;
use embassy_stm32::low_power::Executor;
use embassy_stm32::rtc::{Rtc, RtcConfig};
use static_cell::StaticCell;

#[cortex_m_rt::entry]
fn main() -> ! {
    Executor::take().run(|spawner| {
        unwrap!(spawner.spawn(async_main(spawner)));
    });
}

#[embassy_executor::task]
async fn async_main(spawner: Spawner) {
    // initialize the platform...
    let mut config = embassy_stm32::Config::default();
    // when enabled the power-consumption is much higher during stop, but debugging and RTT is working
    config.enable_debug_during_sleep = false;
    let p = embassy_stm32::init(config);

    // give the RTC to the executor...
    let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
    static RTC: StaticCell<Rtc> = StaticCell::new();
    let rtc = RTC.init(rtc);
    embassy_stm32::low_power::stop_with_rtc(rtc);

    // your application here...
}

Structs§

  • Thread mode executor, using WFE/SEV.

Enums§

Functions§