aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-02-26 12:08:32 +0000
committerGitHub <[email protected]>2024-02-26 12:08:32 +0000
commitd5a2b3be58185384fca86391e9e16b219f2711ed (patch)
tree6cca8ec9c0e53e3806a10e1d28148b4e41604ffa
parent3499806a3d897d7ed245bf58ac3eefdd5b2ec5f7 (diff)
parent5c45723777dbd7d9d23188f5b5a2adc417e29292 (diff)
Merge pull request #2614 from MaxiluxSystems/time_driver_tim1
stm32: time_driver: allow use of TIM1 for driver
-rw-r--r--embassy-stm32/Cargo.toml12
-rw-r--r--embassy-stm32/src/time_driver.rs38
-rw-r--r--embassy-stm32/src/timer/mod.rs19
3 files changed, 60 insertions, 9 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 7d21383c3..81b8e2f94 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -130,6 +130,8 @@ _time-driver = ["dep:embassy-time-driver", "time"]
130 130
131## Use any time driver 131## Use any time driver
132time-driver-any = ["_time-driver"] 132time-driver-any = ["_time-driver"]
133## Use TIM1 as time driver
134time-driver-tim1 = ["_time-driver"]
133## Use TIM2 as time driver 135## Use TIM2 as time driver
134time-driver-tim2 = ["_time-driver"] 136time-driver-tim2 = ["_time-driver"]
135## Use TIM3 as time driver 137## Use TIM3 as time driver
@@ -138,18 +140,24 @@ time-driver-tim3 = ["_time-driver"]
138time-driver-tim4 = ["_time-driver"] 140time-driver-tim4 = ["_time-driver"]
139## Use TIM5 as time driver 141## Use TIM5 as time driver
140time-driver-tim5 = ["_time-driver"] 142time-driver-tim5 = ["_time-driver"]
143## Use TIM8 as time driver
144time-driver-tim8 = ["_time-driver"]
141## Use TIM9 as time driver 145## Use TIM9 as time driver
142time-driver-tim9 = ["_time-driver"] 146time-driver-tim9 = ["_time-driver"]
143## Use TIM11 as time driver
144time-driver-tim11 = ["_time-driver"]
145## Use TIM12 as time driver 147## Use TIM12 as time driver
146time-driver-tim12 = ["_time-driver"] 148time-driver-tim12 = ["_time-driver"]
147## Use TIM15 as time driver 149## Use TIM15 as time driver
148time-driver-tim15 = ["_time-driver"] 150time-driver-tim15 = ["_time-driver"]
151## Use TIM20 as time driver
152time-driver-tim20 = ["_time-driver"]
149## Use TIM21 as time driver 153## Use TIM21 as time driver
150time-driver-tim21 = ["_time-driver"] 154time-driver-tim21 = ["_time-driver"]
151## Use TIM22 as time driver 155## Use TIM22 as time driver
152time-driver-tim22 = ["_time-driver"] 156time-driver-tim22 = ["_time-driver"]
157## Use TIM23 as time driver
158time-driver-tim23 = ["_time-driver"]
159## Use TIM24 as time driver
160time-driver-tim24 = ["_time-driver"]
153 161
154 162
155#! ## Analog Switch Pins (Pxy_C) on STM32H7 series 163#! ## Analog Switch Pins (Pxy_C) on STM32H7 series
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index a1f54307d..37b2e7526 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -16,6 +16,8 @@ use crate::pac::timer::vals;
16use crate::rcc::sealed::RccPeripheral; 16use crate::rcc::sealed::RccPeripheral;
17#[cfg(feature = "low-power")] 17#[cfg(feature = "low-power")]
18use crate::rtc::Rtc; 18use crate::rtc::Rtc;
19#[cfg(any(time_driver_tim1, time_driver_tim8, time_driver_tim20))]
20use crate::timer::sealed::AdvancedControlInstance;
19use crate::timer::sealed::{CoreInstance, GeneralPurpose16bitInstance as Instance}; 21use crate::timer::sealed::{CoreInstance, GeneralPurpose16bitInstance as Instance};
20use crate::{interrupt, peripherals}; 22use crate::{interrupt, peripherals};
21 23
@@ -38,7 +40,7 @@ cfg_if::cfg_if! {
38 } 40 }
39} 41}
40 42
41#[cfg(time_drvier_tim1)] 43#[cfg(time_driver_tim1)]
42type T = peripherals::TIM1; 44type T = peripherals::TIM1;
43#[cfg(time_driver_tim2)] 45#[cfg(time_driver_tim2)]
44type T = peripherals::TIM2; 46type T = peripherals::TIM2;
@@ -52,8 +54,6 @@ type T = peripherals::TIM5;
52type T = peripherals::TIM8; 54type T = peripherals::TIM8;
53#[cfg(time_driver_tim9)] 55#[cfg(time_driver_tim9)]
54type T = peripherals::TIM9; 56type T = peripherals::TIM9;
55#[cfg(time_driver_tim11)]
56type T = peripherals::TIM11;
57#[cfg(time_driver_tim12)] 57#[cfg(time_driver_tim12)]
58type T = peripherals::TIM12; 58type T = peripherals::TIM12;
59#[cfg(time_driver_tim15)] 59#[cfg(time_driver_tim15)]
@@ -78,6 +78,14 @@ foreach_interrupt! {
78 DRIVER.on_interrupt() 78 DRIVER.on_interrupt()
79 } 79 }
80 }; 80 };
81 (TIM1, timer, $block:ident, CC, $irq:ident) => {
82 #[cfg(time_driver_tim1)]
83 #[cfg(feature = "rt")]
84 #[interrupt]
85 fn $irq() {
86 DRIVER.on_interrupt()
87 }
88 };
81 (TIM2, timer, $block:ident, UP, $irq:ident) => { 89 (TIM2, timer, $block:ident, UP, $irq:ident) => {
82 #[cfg(time_driver_tim2)] 90 #[cfg(time_driver_tim2)]
83 #[cfg(feature = "rt")] 91 #[cfg(feature = "rt")]
@@ -118,6 +126,14 @@ foreach_interrupt! {
118 DRIVER.on_interrupt() 126 DRIVER.on_interrupt()
119 } 127 }
120 }; 128 };
129 (TIM8, timer, $block:ident, CC, $irq:ident) => {
130 #[cfg(time_driver_tim8)]
131 #[cfg(feature = "rt")]
132 #[interrupt]
133 fn $irq() {
134 DRIVER.on_interrupt()
135 }
136 };
121 (TIM9, timer, $block:ident, UP, $irq:ident) => { 137 (TIM9, timer, $block:ident, UP, $irq:ident) => {
122 #[cfg(time_driver_tim9)] 138 #[cfg(time_driver_tim9)]
123 #[cfg(feature = "rt")] 139 #[cfg(feature = "rt")]
@@ -150,6 +166,14 @@ foreach_interrupt! {
150 DRIVER.on_interrupt() 166 DRIVER.on_interrupt()
151 } 167 }
152 }; 168 };
169 (TIM20, timer, $block:ident, CC, $irq:ident) => {
170 #[cfg(time_driver_tim20)]
171 #[cfg(feature = "rt")]
172 #[interrupt]
173 fn $irq() {
174 DRIVER.on_interrupt()
175 }
176 };
153 (TIM21, timer, $block:ident, UP, $irq:ident) => { 177 (TIM21, timer, $block:ident, UP, $irq:ident) => {
154 #[cfg(time_driver_tim21)] 178 #[cfg(time_driver_tim21)]
155 #[cfg(feature = "rt")] 179 #[cfg(feature = "rt")]
@@ -283,6 +307,14 @@ impl RtcDriver {
283 <T as CoreInstance>::Interrupt::unpend(); 307 <T as CoreInstance>::Interrupt::unpend();
284 unsafe { <T as CoreInstance>::Interrupt::enable() }; 308 unsafe { <T as CoreInstance>::Interrupt::enable() };
285 309
310 #[cfg(any(time_driver_tim1, time_driver_tim8, time_driver_tim20))]
311 {
312 <T as AdvancedControlInstance>::CaptureCompareInterrupt::unpend();
313 unsafe {
314 <T as AdvancedControlInstance>::CaptureCompareInterrupt::enable();
315 }
316 }
317
286 r.cr1().modify(|w| w.set_cen(true)); 318 r.cr1().modify(|w| w.set_cen(true));
287 } 319 }
288 320
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 9397da2a1..c8f580101 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -464,6 +464,9 @@ pub(crate) mod sealed {
464 pub trait AdvancedControlInstance: 464 pub trait AdvancedControlInstance:
465 GeneralPurpose2ChannelComplementaryInstance + GeneralPurpose16bitInstance 465 GeneralPurpose2ChannelComplementaryInstance + GeneralPurpose16bitInstance
466 { 466 {
467 /// Capture compare interrupt for this timer.
468 type CaptureCompareInterrupt: interrupt::typelevel::Interrupt;
469
467 /// Get access to the advanced timer registers. 470 /// Get access to the advanced timer registers.
468 fn regs_advanced() -> crate::pac::timer::TimAdv; 471 fn regs_advanced() -> crate::pac::timer::TimAdv;
469 472
@@ -831,8 +834,10 @@ macro_rules! impl_2ch_cmp_timer {
831 834
832#[allow(unused)] 835#[allow(unused)]
833macro_rules! impl_adv_timer { 836macro_rules! impl_adv_timer {
834 ($inst:ident) => { 837 ($inst:ident, $irq:ident) => {
835 impl sealed::AdvancedControlInstance for crate::peripherals::$inst { 838 impl sealed::AdvancedControlInstance for crate::peripherals::$inst {
839 type CaptureCompareInterrupt = crate::interrupt::typelevel::$irq;
840
836 fn regs_advanced() -> crate::pac::timer::TimAdv { 841 fn regs_advanced() -> crate::pac::timer::TimAdv {
837 unsafe { crate::pac::timer::TimAdv::from_ptr(crate::pac::$inst.as_ptr()) } 842 unsafe { crate::pac::timer::TimAdv::from_ptr(crate::pac::$inst.as_ptr()) }
838 } 843 }
@@ -905,11 +910,13 @@ foreach_interrupt! {
905 impl_gp16_timer!($inst); 910 impl_gp16_timer!($inst);
906 impl_1ch_cmp_timer!($inst); 911 impl_1ch_cmp_timer!($inst);
907 impl_2ch_cmp_timer!($inst); 912 impl_2ch_cmp_timer!($inst);
908 impl_adv_timer!($inst);
909 impl BasicInstance for crate::peripherals::$inst {} 913 impl BasicInstance for crate::peripherals::$inst {}
910 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 914 impl CaptureCompare16bitInstance for crate::peripherals::$inst {}
911 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 915 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
912 }; 916 };
917 ($inst:ident, timer, TIM_1CH_CMP, CC, $irq:ident) => {
918 impl_adv_timer!($inst, $irq);
919 };
913 920
914 921
915 ($inst:ident, timer, TIM_2CH_CMP, UP, $irq:ident) => { 922 ($inst:ident, timer, TIM_2CH_CMP, UP, $irq:ident) => {
@@ -921,11 +928,13 @@ foreach_interrupt! {
921 impl_gp16_timer!($inst); 928 impl_gp16_timer!($inst);
922 impl_1ch_cmp_timer!($inst); 929 impl_1ch_cmp_timer!($inst);
923 impl_2ch_cmp_timer!($inst); 930 impl_2ch_cmp_timer!($inst);
924 impl_adv_timer!($inst);
925 impl BasicInstance for crate::peripherals::$inst {} 931 impl BasicInstance for crate::peripherals::$inst {}
926 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 932 impl CaptureCompare16bitInstance for crate::peripherals::$inst {}
927 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 933 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
928 }; 934 };
935 ($inst:ident, timer, TIM_2CH_CMP, CC, $irq:ident) => {
936 impl_adv_timer!($inst, $irq);
937 };
929 938
930 939
931 ($inst:ident, timer, TIM_ADV, UP, $irq:ident) => { 940 ($inst:ident, timer, TIM_ADV, UP, $irq:ident) => {
@@ -937,11 +946,13 @@ foreach_interrupt! {
937 impl_gp16_timer!($inst); 946 impl_gp16_timer!($inst);
938 impl_1ch_cmp_timer!($inst); 947 impl_1ch_cmp_timer!($inst);
939 impl_2ch_cmp_timer!($inst); 948 impl_2ch_cmp_timer!($inst);
940 impl_adv_timer!($inst);
941 impl BasicInstance for crate::peripherals::$inst {} 949 impl BasicInstance for crate::peripherals::$inst {}
942 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 950 impl CaptureCompare16bitInstance for crate::peripherals::$inst {}
943 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 951 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
944 }; 952 };
953 ($inst:ident, timer, TIM_ADV, CC, $irq:ident) => {
954 impl_adv_timer!($inst, $irq);
955 };
945} 956}
946 957
947// Update Event trigger DMA for every timer 958// Update Event trigger DMA for every timer