From 4e2361c024187d2ddba8596b05f013ad8a52a28c Mon Sep 17 00:00:00 2001 From: shufps Date: Sun, 14 Jan 2024 22:31:19 +0100 Subject: [PATCH 1/3] adds timer-driver for tim21 and tim22 (on L0) --- embassy-stm32/Cargo.toml | 4 ++++ embassy-stm32/build.rs | 6 ++++++ embassy-stm32/src/time_driver.rs | 24 ++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index f1539229f..1280f372e 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -139,6 +139,10 @@ time-driver-tim11 = ["_time-driver"] time-driver-tim12 = ["_time-driver"] ## Use TIM15 as time driver time-driver-tim15 = ["_time-driver"] +## Use TIM21 as time driver +time-driver-tim22 = ["_time-driver"] +## Use TIM22 as time driver +time-driver-tim22 = ["_time-driver"] #! ## Analog Switch Pins (Pxy_C) on STM32H7 series diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index ef152acd1..948ce3aff 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -191,6 +191,8 @@ fn main() { Some("tim11") => "TIM11", Some("tim12") => "TIM12", Some("tim15") => "TIM15", + Some("tim21") => "TIM21", + Some("tim22") => "TIM22", Some("any") => { if singletons.contains(&"TIM2".to_string()) { "TIM2" @@ -208,6 +210,10 @@ fn main() { "TIM12" } else if singletons.contains(&"TIM15".to_string()) { "TIM15" + } else if singletons.contains(&"TIM21".to_string()) { + "TIM21" + } else if singletons.contains(&"TIM22".to_string()) { + "TIM22" } else { panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM9, TIM11, TIM12 or TIM15.") } diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 0dbadce0c..d613394ef 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -28,10 +28,10 @@ use crate::{interrupt, peripherals}; // available after reserving CC1 for regular time keeping. For example, TIM2 has four CC registers: // CC1, CC2, CC3, and CC4, so it can provide ALARM_COUNT = 3. -#[cfg(not(any(time_driver_tim12, time_driver_tim15)))] +#[cfg(not(any(time_driver_tim12, time_driver_tim15, time_driver_tim21, time_driver_tim22)))] const ALARM_COUNT: usize = 3; -#[cfg(any(time_driver_tim12, time_driver_tim15))] +#[cfg(any(time_driver_tim12, time_driver_tim15, time_driver_tim21, time_driver_tim22))] const ALARM_COUNT: usize = 1; #[cfg(time_driver_tim2)] @@ -50,6 +50,10 @@ type T = peripherals::TIM11; type T = peripherals::TIM12; #[cfg(time_driver_tim15)] type T = peripherals::TIM15; +#[cfg(time_driver_tim21)] +type T = peripherals::TIM21; +#[cfg(time_driver_tim22)] +type T = peripherals::TIM22; foreach_interrupt! { (TIM2, timer, $block:ident, UP, $irq:ident) => { @@ -116,6 +120,22 @@ foreach_interrupt! { DRIVER.on_interrupt() } }; + (TIM21, timer, $block:ident, UP, $irq:ident) => { + #[cfg(time_driver_tim21)] + #[cfg(feature = "rt")] + #[interrupt] + fn $irq() { + DRIVER.on_interrupt() + } + }; + (TIM22, timer, $block:ident, UP, $irq:ident) => { + #[cfg(time_driver_tim22)] + #[cfg(feature = "rt")] + #[interrupt] + fn $irq() { + DRIVER.on_interrupt() + } + }; } // Clock timekeeping works with something we call "periods", which are time intervals From 2b649136644eb49b8c22c3b1ddb98bcd6d043b3f Mon Sep 17 00:00:00 2001 From: shufps Date: Sun, 14 Jan 2024 22:48:50 +0100 Subject: [PATCH 2/3] fixed tim21 --- embassy-stm32/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 1280f372e..865970dfb 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -140,7 +140,7 @@ time-driver-tim12 = ["_time-driver"] ## Use TIM15 as time driver time-driver-tim15 = ["_time-driver"] ## Use TIM21 as time driver -time-driver-tim22 = ["_time-driver"] +time-driver-tim21 = ["_time-driver"] ## Use TIM22 as time driver time-driver-tim22 = ["_time-driver"] From e969b88e5ae1aa439b47f7b55e740d6ca78b9a0a Mon Sep 17 00:00:00 2001 From: shufps Date: Mon, 15 Jan 2024 11:23:41 +0100 Subject: [PATCH 3/3] fixed trailing white spaces --- embassy-stm32/src/time_driver.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index d613394ef..320b29ddb 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -127,7 +127,7 @@ foreach_interrupt! { fn $irq() { DRIVER.on_interrupt() } - }; + }; (TIM22, timer, $block:ident, UP, $irq:ident) => { #[cfg(time_driver_tim22)] #[cfg(feature = "rt")] @@ -135,7 +135,7 @@ foreach_interrupt! { fn $irq() { DRIVER.on_interrupt() } - }; + }; } // Clock timekeeping works with something we call "periods", which are time intervals