diff options
| author | Matous Hybl <[email protected]> | 2022-02-23 11:52:02 +0100 |
|---|---|---|
| committer | Matous Hybl <[email protected]> | 2022-02-28 19:20:22 +0100 |
| commit | 0172ca5b81ab9041f5a16dc7e91ec3eca707d0dd (patch) | |
| tree | a400391b59b71591057102ba1e32951e8a40ce18 | |
| parent | b9a8d649cf8960ea834dd9e9387084b198234452 (diff) | |
stm32: Add support for using TIM12 and TIM15 as time driver
| -rw-r--r-- | embassy-stm32/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-stm32/build.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 23 |
3 files changed, 32 insertions, 1 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index cb35e7071..e45dfbacd 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -56,6 +56,8 @@ time-driver-tim2 = ["_time-driver"] | |||
| 56 | time-driver-tim3 = ["_time-driver"] | 56 | time-driver-tim3 = ["_time-driver"] |
| 57 | time-driver-tim4 = ["_time-driver"] | 57 | time-driver-tim4 = ["_time-driver"] |
| 58 | time-driver-tim5 = ["_time-driver"] | 58 | time-driver-tim5 = ["_time-driver"] |
| 59 | time-driver-tim12 = ["_time-driver"] | ||
| 60 | time-driver-tim15 = ["_time-driver"] | ||
| 59 | 61 | ||
| 60 | # Enable nightly-only features | 62 | # Enable nightly-only features |
| 61 | nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"] | 63 | nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"] |
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index e67c4b983..737b62476 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -720,6 +720,8 @@ fn main() { | |||
| 720 | Some("tim3") => println!("cargo:rustc-cfg=time_driver_tim3"), | 720 | Some("tim3") => println!("cargo:rustc-cfg=time_driver_tim3"), |
| 721 | Some("tim4") => println!("cargo:rustc-cfg=time_driver_tim4"), | 721 | Some("tim4") => println!("cargo:rustc-cfg=time_driver_tim4"), |
| 722 | Some("tim5") => println!("cargo:rustc-cfg=time_driver_tim5"), | 722 | Some("tim5") => println!("cargo:rustc-cfg=time_driver_tim5"), |
| 723 | Some("tim12") => println!("cargo:rustc-cfg=time_driver_tim12"), | ||
| 724 | Some("tim15") => println!("cargo:rustc-cfg=time_driver_tim15"), | ||
| 723 | Some("any") => { | 725 | Some("any") => { |
| 724 | if singletons.contains(&"TIM2".to_string()) { | 726 | if singletons.contains(&"TIM2".to_string()) { |
| 725 | println!("cargo:rustc-cfg=time_driver_tim2"); | 727 | println!("cargo:rustc-cfg=time_driver_tim2"); |
| @@ -729,8 +731,12 @@ fn main() { | |||
| 729 | println!("cargo:rustc-cfg=time_driver_tim4"); | 731 | println!("cargo:rustc-cfg=time_driver_tim4"); |
| 730 | } else if singletons.contains(&"TIM5".to_string()) { | 732 | } else if singletons.contains(&"TIM5".to_string()) { |
| 731 | println!("cargo:rustc-cfg=time_driver_tim5"); | 733 | println!("cargo:rustc-cfg=time_driver_tim5"); |
| 734 | } else if singletons.contains(&"TIM12".to_string()) { | ||
| 735 | println!("cargo:rustc-cfg=time_driver_tim12"); | ||
| 736 | } else if singletons.contains(&"TIM15".to_string()) { | ||
| 737 | println!("cargo:rustc-cfg=time_driver_tim15"); | ||
| 732 | } else { | 738 | } else { |
| 733 | panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4 or TIM5.") | 739 | panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM12 or TIM15.") |
| 734 | } | 740 | } |
| 735 | } | 741 | } |
| 736 | _ => panic!("unknown time_driver {:?}", time_driver), | 742 | _ => panic!("unknown time_driver {:?}", time_driver), |
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 08796acd5..5b3efca72 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -18,8 +18,12 @@ use crate::rcc::sealed::RccPeripheral; | |||
| 18 | use crate::timer::sealed::Basic16bitInstance as BasicInstance; | 18 | use crate::timer::sealed::Basic16bitInstance as BasicInstance; |
| 19 | use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; | 19 | use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; |
| 20 | 20 | ||
| 21 | #[cfg(not(any(time_driver_tim12, time_driver_tim15)))] | ||
| 21 | const ALARM_COUNT: usize = 3; | 22 | const ALARM_COUNT: usize = 3; |
| 22 | 23 | ||
| 24 | #[cfg(any(time_driver_tim12, time_driver_tim15))] | ||
| 25 | const ALARM_COUNT: usize = 1; | ||
| 26 | |||
| 23 | #[cfg(time_driver_tim2)] | 27 | #[cfg(time_driver_tim2)] |
| 24 | type T = peripherals::TIM2; | 28 | type T = peripherals::TIM2; |
| 25 | #[cfg(time_driver_tim3)] | 29 | #[cfg(time_driver_tim3)] |
| @@ -29,6 +33,11 @@ type T = peripherals::TIM4; | |||
| 29 | #[cfg(time_driver_tim5)] | 33 | #[cfg(time_driver_tim5)] |
| 30 | type T = peripherals::TIM5; | 34 | type T = peripherals::TIM5; |
| 31 | 35 | ||
| 36 | #[cfg(time_driver_tim12)] | ||
| 37 | type T = peripherals::TIM12; | ||
| 38 | #[cfg(time_driver_tim15)] | ||
| 39 | type T = peripherals::TIM15; | ||
| 40 | |||
| 32 | foreach_interrupt! { | 41 | foreach_interrupt! { |
| 33 | (TIM2, timer, $block:ident, UP, $irq:ident) => { | 42 | (TIM2, timer, $block:ident, UP, $irq:ident) => { |
| 34 | #[cfg(time_driver_tim2)] | 43 | #[cfg(time_driver_tim2)] |
| @@ -58,6 +67,20 @@ foreach_interrupt! { | |||
| 58 | DRIVER.on_interrupt() | 67 | DRIVER.on_interrupt() |
| 59 | } | 68 | } |
| 60 | }; | 69 | }; |
| 70 | (TIM12, timer, $block:ident, UP, $irq:ident) => { | ||
| 71 | #[cfg(time_driver_tim12)] | ||
| 72 | #[interrupt] | ||
| 73 | fn $irq() { | ||
| 74 | DRIVER.on_interrupt() | ||
| 75 | } | ||
| 76 | }; | ||
| 77 | (TIM15, timer, $block:ident, UP, $irq:ident) => { | ||
| 78 | #[cfg(time_driver_tim15)] | ||
| 79 | #[interrupt] | ||
| 80 | fn $irq() { | ||
| 81 | DRIVER.on_interrupt() | ||
| 82 | } | ||
| 83 | }; | ||
| 61 | } | 84 | } |
| 62 | 85 | ||
| 63 | // Clock timekeeping works with something we call "periods", which are time intervals | 86 | // Clock timekeeping works with something we call "periods", which are time intervals |
