636: stm32: Add support for using TIM12 and TIM15 as time driver r=Dirbaio a=matoushybl

I am not sure what the effect of reducing the number of alarms will be, but these are the only timers I have available on my board.

Co-authored-by: Matous Hybl <hyblmatous@gmail.com>
This commit is contained in:
bors[bot] 2022-02-28 18:25:13 +00:00 committed by GitHub
commit 35636953b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -56,6 +56,8 @@ time-driver-tim2 = ["_time-driver"]
time-driver-tim3 = ["_time-driver"] time-driver-tim3 = ["_time-driver"]
time-driver-tim4 = ["_time-driver"] time-driver-tim4 = ["_time-driver"]
time-driver-tim5 = ["_time-driver"] time-driver-tim5 = ["_time-driver"]
time-driver-tim12 = ["_time-driver"]
time-driver-tim15 = ["_time-driver"]
# Enable nightly-only features # Enable nightly-only features
nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"] nightly = ["embassy/nightly", "embedded-hal-1", "embedded-hal-async"]

View File

@ -720,6 +720,8 @@ fn main() {
Some("tim3") => println!("cargo:rustc-cfg=time_driver_tim3"), Some("tim3") => println!("cargo:rustc-cfg=time_driver_tim3"),
Some("tim4") => println!("cargo:rustc-cfg=time_driver_tim4"), Some("tim4") => println!("cargo:rustc-cfg=time_driver_tim4"),
Some("tim5") => println!("cargo:rustc-cfg=time_driver_tim5"), Some("tim5") => println!("cargo:rustc-cfg=time_driver_tim5"),
Some("tim12") => println!("cargo:rustc-cfg=time_driver_tim12"),
Some("tim15") => println!("cargo:rustc-cfg=time_driver_tim15"),
Some("any") => { Some("any") => {
if singletons.contains(&"TIM2".to_string()) { if singletons.contains(&"TIM2".to_string()) {
println!("cargo:rustc-cfg=time_driver_tim2"); println!("cargo:rustc-cfg=time_driver_tim2");
@ -729,8 +731,12 @@ fn main() {
println!("cargo:rustc-cfg=time_driver_tim4"); println!("cargo:rustc-cfg=time_driver_tim4");
} else if singletons.contains(&"TIM5".to_string()) { } else if singletons.contains(&"TIM5".to_string()) {
println!("cargo:rustc-cfg=time_driver_tim5"); println!("cargo:rustc-cfg=time_driver_tim5");
} else if singletons.contains(&"TIM12".to_string()) {
println!("cargo:rustc-cfg=time_driver_tim12");
} else if singletons.contains(&"TIM15".to_string()) {
println!("cargo:rustc-cfg=time_driver_tim15");
} else { } else {
panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4 or TIM5.") panic!("time-driver-any requested, but the chip doesn't have TIM2, TIM3, TIM4, TIM5, TIM12 or TIM15.")
} }
} }
_ => panic!("unknown time_driver {:?}", time_driver), _ => panic!("unknown time_driver {:?}", time_driver),

View File

@ -18,8 +18,12 @@ use crate::rcc::sealed::RccPeripheral;
use crate::timer::sealed::Basic16bitInstance as BasicInstance; use crate::timer::sealed::Basic16bitInstance as BasicInstance;
use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; use crate::timer::sealed::GeneralPurpose16bitInstance as Instance;
#[cfg(not(any(time_driver_tim12, time_driver_tim15)))]
const ALARM_COUNT: usize = 3; const ALARM_COUNT: usize = 3;
#[cfg(any(time_driver_tim12, time_driver_tim15))]
const ALARM_COUNT: usize = 1;
#[cfg(time_driver_tim2)] #[cfg(time_driver_tim2)]
type T = peripherals::TIM2; type T = peripherals::TIM2;
#[cfg(time_driver_tim3)] #[cfg(time_driver_tim3)]
@ -29,6 +33,11 @@ type T = peripherals::TIM4;
#[cfg(time_driver_tim5)] #[cfg(time_driver_tim5)]
type T = peripherals::TIM5; type T = peripherals::TIM5;
#[cfg(time_driver_tim12)]
type T = peripherals::TIM12;
#[cfg(time_driver_tim15)]
type T = peripherals::TIM15;
foreach_interrupt! { foreach_interrupt! {
(TIM2, timer, $block:ident, UP, $irq:ident) => { (TIM2, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim2)] #[cfg(time_driver_tim2)]
@ -58,6 +67,20 @@ foreach_interrupt! {
DRIVER.on_interrupt() DRIVER.on_interrupt()
} }
}; };
(TIM12, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim12)]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
(TIM15, timer, $block:ident, UP, $irq:ident) => {
#[cfg(time_driver_tim15)]
#[interrupt]
fn $irq() {
DRIVER.on_interrupt()
}
};
} }
// Clock timekeeping works with something we call "periods", which are time intervals // Clock timekeeping works with something we call "periods", which are time intervals