aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-08-04 12:05:22 +0200
committerDario Nieuwenhuis <[email protected]>2021-08-05 19:14:09 +0200
commitb1d631d63941e0bca49ec349147c041f04f3eafb (patch)
tree73b763c20546b9c2b10ef45ec32ecf164855485b
parent0ea6a2d8905a146c8899239fe52e739404f13e7e (diff)
stm32/time: add Cargo features to choose tim2/tim3
-rw-r--r--embassy-stm32/Cargo.toml8
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--embassy-stm32/src/time_driver.rs20
-rw-r--r--examples/stm32f0/Cargo.toml2
-rw-r--r--examples/stm32f4/Cargo.toml2
-rw-r--r--examples/stm32h7/Cargo.toml2
-rw-r--r--examples/stm32l0/Cargo.toml2
-rw-r--r--examples/stm32l4/Cargo.toml2
-rw-r--r--examples/stm32wb55/Cargo.toml2
-rw-r--r--examples/stm32wb55/src/bin/blinky.rs16
10 files changed, 39 insertions, 19 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 6f8691c3e..9b9db0f0c 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2018"
6resolver = "2" 6resolver = "2"
7 7
8[dependencies] 8[dependencies]
9embassy = { version = "0.1.0", path = "../embassy", features = ["time-tick-32768hz"] } 9embassy = { version = "0.1.0", path = "../embassy" }
10embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } 10embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] }
11embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 11embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
12embassy-traits = {version = "0.1.0", path = "../embassy-traits" } 12embassy-traits = {version = "0.1.0", path = "../embassy-traits" }
@@ -44,6 +44,12 @@ sdmmc-rs = ["embedded-sdmmc"]
44net = ["embassy-net", "vcell"] 44net = ["embassy-net", "vcell"]
45memory-x = ["stm32-metapac/memory-x"] 45memory-x = ["stm32-metapac/memory-x"]
46 46
47# Features starting with `_` are for internal use only. They're not intended
48# to be enabled by other crates, and are not covered by semver guarantees.
49_time-driver = ["embassy/time-tick-32768hz"]
50time-driver-tim2 = ["_time-driver"]
51time-driver-tim3 = ["_time-driver"]
52
47# Reexport stm32-metapac at `embassy_stm32::pac`. 53# Reexport stm32-metapac at `embassy_stm32::pac`.
48# This is unstable because semver-minor (non-breaking) releases of embassy-stm32 may major-bump (breaking) the stm32-metapac version. 54# This is unstable because semver-minor (non-breaking) releases of embassy-stm32 may major-bump (breaking) the stm32-metapac version.
49# If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC. 55# If this is an issue for you, you're encouraged to directly depend on a fixed version of the PAC.
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 28bfcbaac..8a213b680 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -20,6 +20,7 @@ pub mod time;
20pub mod dma; 20pub mod dma;
21pub mod gpio; 21pub mod gpio;
22pub mod rcc; 22pub mod rcc;
23#[cfg(feature = "_time-driver")]
23mod time_driver; 24mod time_driver;
24 25
25// Sometimes-present hardware 26// Sometimes-present hardware
@@ -88,6 +89,7 @@ pub fn init(config: Config) -> Peripherals {
88 rcc::init(config.rcc); 89 rcc::init(config.rcc);
89 90
90 // must be after rcc init 91 // must be after rcc init
92 #[cfg(feature = "_time-driver")]
91 time_driver::init(); 93 time_driver::init();
92 } 94 }
93 95
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index 16c871e8d..226e5e39c 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -17,8 +17,23 @@ use crate::rcc::sealed::RccPeripheral;
17use self::sealed::Instance as _; 17use self::sealed::Instance as _;
18 18
19const ALARM_COUNT: usize = 3; 19const ALARM_COUNT: usize = 3;
20
21#[cfg(feature = "time-driver-tim2")]
22type T = peripherals::TIM2;
23#[cfg(feature = "time-driver-tim3")]
20type T = peripherals::TIM3; 24type T = peripherals::TIM3;
21 25
26#[cfg(feature = "time-driver-tim2")]
27#[interrupt]
28fn TIM2() {
29 STATE.on_interrupt()
30}
31#[cfg(feature = "time-driver-tim3")]
32#[interrupt]
33fn TIM3() {
34 STATE.on_interrupt()
35}
36
22// Clock timekeeping works with something we call "periods", which are time intervals 37// Clock timekeeping works with something we call "periods", which are time intervals
23// of 2^15 ticks. The Clock counter value is 16 bits, so one "overflow cycle" is 2 periods. 38// of 2^15 ticks. The Clock counter value is 16 bits, so one "overflow cycle" is 2 periods.
24// 39//
@@ -275,11 +290,6 @@ impl Driver for RtcDriver {
275 } 290 }
276} 291}
277 292
278#[interrupt]
279fn TIM3() {
280 STATE.on_interrupt()
281}
282
283pub(crate) fn init() { 293pub(crate) fn init() {
284 STATE.init() 294 STATE.init()
285} 295}
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
index cc2c3f2b7..c5730de80 100644
--- a/examples/stm32f0/Cargo.toml
+++ b/examples/stm32f0/Cargo.toml
@@ -15,7 +15,7 @@ defmt-rtt = "0.2.0"
15panic-probe = { version = "0.2.0" } 15panic-probe = { version = "0.2.0" }
16rtt-target = { version = "0.3", features = ["cortex-m"] } 16rtt-target = { version = "0.3", features = ["cortex-m"] }
17embassy = { path = "../../embassy", features = ["defmt"] } 17embassy = { path = "../../embassy", features = ["defmt"] }
18embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4"] } 18embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4", "time-driver-tim3"] }
19 19
20[features] 20[features]
21default = [ 21default = [
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 84b1e30ee..c254573f8 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -19,7 +19,7 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi", "unstable-pac", "memory-x"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-tim2"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24 24
25defmt = "0.2.0" 25defmt = "0.2.0"
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index 0868be75d..c7761ee85 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -19,7 +19,7 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32h743zi", "net", "memory-x"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32h743zi", "net", "memory-x", "time-driver-tim2"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt-debug", "defmt", "tcp", "medium-ethernet", "pool-16"] } 24embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt-debug", "defmt", "tcp", "medium-ethernet", "pool-16"] }
25stm32-metapac = { path = "../../stm32-metapac", features = ["stm32h743zi"] } 25stm32-metapac = { path = "../../stm32-metapac", features = ["stm32h743zi"] }
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 47d23d08f..6c594df66 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -19,7 +19,7 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz", "time-driver-tim3"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24 24
25defmt = "0.2.0" 25defmt = "0.2.0"
diff --git a/examples/stm32l4/Cargo.toml b/examples/stm32l4/Cargo.toml
index 8c6207676..3f6b34679 100644
--- a/examples/stm32l4/Cargo.toml
+++ b/examples/stm32l4/Cargo.toml
@@ -19,7 +19,7 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi", "time-driver-tim2"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24 24
25defmt = "0.2.0" 25defmt = "0.2.0"
diff --git a/examples/stm32wb55/Cargo.toml b/examples/stm32wb55/Cargo.toml
index 4d6f7789c..ee2432cb2 100644
--- a/examples/stm32wb55/Cargo.toml
+++ b/examples/stm32wb55/Cargo.toml
@@ -19,7 +19,7 @@ defmt-error = []
19[dependencies] 19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } 20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32wb55cc"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32wb55cc", "time-driver-tim2"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24 24
25defmt = "0.2.0" 25defmt = "0.2.0"
diff --git a/examples/stm32wb55/src/bin/blinky.rs b/examples/stm32wb55/src/bin/blinky.rs
index 2eba361ae..5ffef9b38 100644
--- a/examples/stm32wb55/src/bin/blinky.rs
+++ b/examples/stm32wb55/src/bin/blinky.rs
@@ -6,27 +6,29 @@
6 6
7#[path = "../example_common.rs"] 7#[path = "../example_common.rs"]
8mod example_common; 8mod example_common;
9use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer};
11use embassy_stm32::dbgmcu::Dbgmcu;
9use embassy_stm32::gpio::{Level, Output, Speed}; 12use embassy_stm32::gpio::{Level, Output, Speed};
13use embassy_stm32::Peripherals;
10use embedded_hal::digital::v2::OutputPin; 14use embedded_hal::digital::v2::OutputPin;
11use example_common::*; 15use example_common::*;
12 16
13use cortex_m_rt::entry; 17#[embassy::main]
14 18async fn main(_spawner: Spawner, p: Peripherals) {
15#[entry]
16fn main() -> ! {
17 info!("Hello World!"); 19 info!("Hello World!");
18 20
19 let p = embassy_stm32::init(Default::default()); 21 unsafe { Dbgmcu::enable_all() };
20 22
21 let mut led = Output::new(p.PB0, Level::High, Speed::Low); 23 let mut led = Output::new(p.PB0, Level::High, Speed::Low);
22 24
23 loop { 25 loop {
24 info!("high"); 26 info!("high");
25 led.set_high().unwrap(); 27 led.set_high().unwrap();
26 cortex_m::asm::delay(10_000_000); 28 Timer::after(Duration::from_millis(500)).await;
27 29
28 info!("low"); 30 info!("low");
29 led.set_low().unwrap(); 31 led.set_low().unwrap();
30 cortex_m::asm::delay(10_000_000); 32 Timer::after(Duration::from_millis(500)).await;
31 } 33 }
32} 34}