diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-08-04 12:05:22 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-08-05 19:14:09 +0200 |
| commit | b1d631d63941e0bca49ec349147c041f04f3eafb (patch) | |
| tree | 73b763c20546b9c2b10ef45ec32ecf164855485b | |
| parent | 0ea6a2d8905a146c8899239fe52e739404f13e7e (diff) | |
stm32/time: add Cargo features to choose tim2/tim3
| -rw-r--r-- | embassy-stm32/Cargo.toml | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 20 | ||||
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32h7/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32l0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32l4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32wb55/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32wb55/src/bin/blinky.rs | 16 |
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" | |||
| 6 | resolver = "2" | 6 | resolver = "2" |
| 7 | 7 | ||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy = { version = "0.1.0", path = "../embassy", features = ["time-tick-32768hz"] } | 9 | embassy = { version = "0.1.0", path = "../embassy" } |
| 10 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } | 10 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } |
| 11 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 11 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 12 | embassy-traits = {version = "0.1.0", path = "../embassy-traits" } | 12 | embassy-traits = {version = "0.1.0", path = "../embassy-traits" } |
| @@ -44,6 +44,12 @@ sdmmc-rs = ["embedded-sdmmc"] | |||
| 44 | net = ["embassy-net", "vcell"] | 44 | net = ["embassy-net", "vcell"] |
| 45 | memory-x = ["stm32-metapac/memory-x"] | 45 | memory-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"] | ||
| 50 | time-driver-tim2 = ["_time-driver"] | ||
| 51 | time-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; | |||
| 20 | pub mod dma; | 20 | pub mod dma; |
| 21 | pub mod gpio; | 21 | pub mod gpio; |
| 22 | pub mod rcc; | 22 | pub mod rcc; |
| 23 | #[cfg(feature = "_time-driver")] | ||
| 23 | mod time_driver; | 24 | mod 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; | |||
| 17 | use self::sealed::Instance as _; | 17 | use self::sealed::Instance as _; |
| 18 | 18 | ||
| 19 | const ALARM_COUNT: usize = 3; | 19 | const ALARM_COUNT: usize = 3; |
| 20 | |||
| 21 | #[cfg(feature = "time-driver-tim2")] | ||
| 22 | type T = peripherals::TIM2; | ||
| 23 | #[cfg(feature = "time-driver-tim3")] | ||
| 20 | type T = peripherals::TIM3; | 24 | type T = peripherals::TIM3; |
| 21 | 25 | ||
| 26 | #[cfg(feature = "time-driver-tim2")] | ||
| 27 | #[interrupt] | ||
| 28 | fn TIM2() { | ||
| 29 | STATE.on_interrupt() | ||
| 30 | } | ||
| 31 | #[cfg(feature = "time-driver-tim3")] | ||
| 32 | #[interrupt] | ||
| 33 | fn 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] | ||
| 279 | fn TIM3() { | ||
| 280 | STATE.on_interrupt() | ||
| 281 | } | ||
| 282 | |||
| 283 | pub(crate) fn init() { | 293 | pub(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" | |||
| 15 | panic-probe = { version = "0.2.0" } | 15 | panic-probe = { version = "0.2.0" } |
| 16 | rtt-target = { version = "0.3", features = ["cortex-m"] } | 16 | rtt-target = { version = "0.3", features = ["cortex-m"] } |
| 17 | embassy = { path = "../../embassy", features = ["defmt"] } | 17 | embassy = { path = "../../embassy", features = ["defmt"] } |
| 18 | embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4"] } | 18 | embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4", "time-driver-tim3"] } |
| 19 | 19 | ||
| 20 | [features] | 20 | [features] |
| 21 | default = [ | 21 | default = [ |
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] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi", "unstable-pac", "memory-x"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-tim2"] } |
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 24 | 24 | ||
| 25 | defmt = "0.2.0" | 25 | defmt = "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] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32h743zi", "net", "memory-x"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32h743zi", "net", "memory-x", "time-driver-tim2"] } |
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 24 | embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt-debug", "defmt", "tcp", "medium-ethernet", "pool-16"] } | 24 | embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt-debug", "defmt", "tcp", "medium-ethernet", "pool-16"] } |
| 25 | stm32-metapac = { path = "../../stm32-metapac", features = ["stm32h743zi"] } | 25 | stm32-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] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz", "time-driver-tim3"] } |
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 24 | 24 | ||
| 25 | defmt = "0.2.0" | 25 | defmt = "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] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "unstable-pac", "stm32l4s5vi", "time-driver-tim2"] } |
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 24 | 24 | ||
| 25 | defmt = "0.2.0" | 25 | defmt = "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] |
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } |
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32wb55cc"] } | 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32wb55cc", "time-driver-tim2"] } |
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 24 | 24 | ||
| 25 | defmt = "0.2.0" | 25 | defmt = "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"] |
| 8 | mod example_common; | 8 | mod example_common; |
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy::time::{Duration, Timer}; | ||
| 11 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | 12 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 13 | use embassy_stm32::Peripherals; | ||
| 10 | use embedded_hal::digital::v2::OutputPin; | 14 | use embedded_hal::digital::v2::OutputPin; |
| 11 | use example_common::*; | 15 | use example_common::*; |
| 12 | 16 | ||
| 13 | use cortex_m_rt::entry; | 17 | #[embassy::main] |
| 14 | 18 | async fn main(_spawner: Spawner, p: Peripherals) { | |
| 15 | #[entry] | ||
| 16 | fn 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 | } |
