aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/stm32f3/Cargo.toml5
-rw-r--r--examples/stm32wba6/src/bin/rtc.rs63
2 files changed, 66 insertions, 2 deletions
diff --git a/examples/stm32f3/Cargo.toml b/examples/stm32f3/Cargo.toml
index 4349e8055..e624b4092 100644
--- a/examples/stm32f3/Cargo.toml
+++ b/examples/stm32f3/Cargo.toml
@@ -7,7 +7,7 @@ publish = false
7 7
8[dependencies] 8[dependencies]
9# Change stm32f303ze to your chip name, if necessary. 9# Change stm32f303ze to your chip name, if necessary.
10embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f303ze", "unstable-pac", "memory-x", "time-driver-tim2", "exti"] } 10embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "stm32f302r8", "unstable-pac", "memory-x", "time-driver-tim2", "exti"] }
11embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } 11embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] }
12embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] } 12embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt"] }
13embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 13embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
@@ -27,7 +27,8 @@ embedded-storage = "0.3.1"
27static_cell = "2" 27static_cell = "2"
28 28
29[profile.release] 29[profile.release]
30debug = 2 30debug = false
31opt-level = 'z'
31 32
32[package.metadata.embassy] 33[package.metadata.embassy]
33build = [ 34build = [
diff --git a/examples/stm32wba6/src/bin/rtc.rs b/examples/stm32wba6/src/bin/rtc.rs
new file mode 100644
index 000000000..1e5634c60
--- /dev/null
+++ b/examples/stm32wba6/src/bin/rtc.rs
@@ -0,0 +1,63 @@
1#![no_std]
2#![no_main]
3
4// use chrono::{NaiveDate, NaiveDateTime};
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::Config;
8use embassy_stm32::rcc::*;
9use embassy_stm32::rtc::{DateTime, DayOfWeek, Rtc, RtcConfig};
10use embassy_time::Timer;
11use {defmt_rtt as _, panic_probe as _};
12
13pub fn pll_init(config: &mut Config) {
14 config.rcc.pll1 = Some(embassy_stm32::rcc::Pll {
15 source: PllSource::HSI,
16 prediv: PllPreDiv::DIV1, // PLLM = 1 → HSI / 1 = 16 MHz
17 mul: PllMul::MUL30, // PLLN = 30 → 16 MHz * 30 = 480 MHz VCO
18 divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk)
19 // divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz (NOT USED)
20 divq: None,
21 divp: Some(PllDiv::DIV30), // PLLP = 30 → 16 MHz (USBOTG)
22 frac: Some(0), // Fractional part (enabled)
23 });
24
25 config.rcc.ahb_pre = AHBPrescaler::DIV1;
26 config.rcc.apb1_pre = APBPrescaler::DIV1;
27 config.rcc.apb2_pre = APBPrescaler::DIV1;
28 config.rcc.apb7_pre = APBPrescaler::DIV1;
29 config.rcc.ahb5_pre = AHB5Prescaler::DIV4;
30
31 // voltage scale for max performance
32 config.rcc.voltage_scale = VoltageScale::RANGE1;
33 // route PLL1_P into the USB‐OTG‐HS block
34 config.rcc.sys = Sysclk::PLL1_R;
35}
36
37#[embassy_executor::main]
38async fn main(_spawner: Spawner) {
39 let mut config = Config::default();
40
41 pll_init(&mut config);
42
43 let p = embassy_stm32::init(config);
44
45 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
46
47 // Setting datetime
48 let initial_datetime = DateTime::from(2025, 12, 9, DayOfWeek::Tuesday, 11, 00, 00, 0).unwrap();
49 match rtc.0.set_datetime(initial_datetime) {
50 Ok(()) => info!("RTC set successfully."),
51 Err(e) => error!("Failed to set RTC date/time: {:?}", e),
52 }
53
54 // Reading datetime every 1s
55 loop {
56 match rtc.1.now() {
57 Ok(result) => info!("{}", result),
58 Err(e) => error!("Failed to set RTC date/time: {:?}", e),
59 }
60
61 Timer::after_millis(1000).await;
62 }
63}