aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src/bin/stop.rs
blob: f38924c90cb1a63d97e158a1e8d32eb10e96d304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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::LsConfig;
use embassy_stm32::rtc::{Rtc, RtcConfig};
use embassy_stm32::Config;
use embassy_time::Timer;
use static_cell::make_static;

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

#[embassy_executor::task]
async fn task_1() {
    for _ in 0..9 {
        info!("task 1: waiting for 500ms...");
        Timer::after_millis(500).await;
    }
}

#[embassy_executor::task]
async fn task_2() {
    for _ in 0..5 {
        info!("task 2: waiting for 1000ms...");
        Timer::after_millis(1000).await;
    }

    info!("Test OK");
    cortex_m::asm::bkpt();
}

#[embassy_executor::task]
async fn async_main(spawner: Spawner) {
    let _ = config();

    let mut config = Config::default();
    config.rcc.ls = LsConfig::default_lse();

    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);

    spawner.spawn(task_1()).unwrap();
    spawner.spawn(task_2()).unwrap();
}