aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-03-08 13:05:20 +0000
committerGitHub <[email protected]>2024-03-08 13:05:20 +0000
commit7718d66053f6b8aef7c5d56652e29d7142eee072 (patch)
treed9ca29795f82cadfea7e53ca805451e2da31942e
parentb2d236ee390081ec6aeef1a27da06098f9febbf9 (diff)
parentb7bb4b23f8e59e90cff4773cc1e93e493d72ae56 (diff)
Merge pull request #2670 from jr-oss/fix_regression_simple_pwm_output_enable
STM32 SimplePwm: Fix regression and re-enable output pin
-rw-r--r--embassy-stm32/src/timer/mod.rs37
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs1
2 files changed, 32 insertions, 6 deletions
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 8530c5229..ef893c7f5 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -439,9 +439,9 @@ pub(crate) mod sealed {
439 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_dtg(value)); 439 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_dtg(value));
440 } 440 }
441 441
442 /// Enable timer outputs. 442 /// Set state of MOE-bit in BDTR register to en-/disable output
443 fn enable_outputs(&self) { 443 fn set_moe(&self, enable: bool) {
444 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_moe(true)); 444 Self::regs_1ch_cmp().bdtr().modify(|w| w.set_moe(enable));
445 } 445 }
446 } 446 }
447 447
@@ -685,6 +685,13 @@ pub trait CaptureCompare16bitInstance:
685 + sealed::GeneralPurpose16bitInstance 685 + sealed::GeneralPurpose16bitInstance
686 + 'static 686 + 'static
687{ 687{
688 // SimplePwm<'d, T> is implemented for T: CaptureCompare16bitInstance
689 // Advanced timers implement this trait, but the output needs to be
690 // enabled explicitly.
691 // To support general-purpose and advanced timers, this function is added
692 // here defaulting to noop and overwritten for advanced timers.
693 /// Enable timer outputs.
694 fn enable_outputs(&self) {}
688} 695}
689 696
690#[cfg(not(stm32l0))] 697#[cfg(not(stm32l0))]
@@ -911,7 +918,13 @@ foreach_interrupt! {
911 impl_1ch_cmp_timer!($inst); 918 impl_1ch_cmp_timer!($inst);
912 impl_2ch_cmp_timer!($inst); 919 impl_2ch_cmp_timer!($inst);
913 impl BasicInstance for crate::peripherals::$inst {} 920 impl BasicInstance for crate::peripherals::$inst {}
914 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 921 impl CaptureCompare16bitInstance for crate::peripherals::$inst {
922 /// Enable timer outputs.
923 fn enable_outputs(&self) {
924 use crate::timer::sealed::GeneralPurpose1ChannelComplementaryInstance;
925 self.set_moe(true);
926 }
927 }
915 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 928 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
916 }; 929 };
917 ($inst:ident, timer, TIM_1CH_CMP, CC, $irq:ident) => { 930 ($inst:ident, timer, TIM_1CH_CMP, CC, $irq:ident) => {
@@ -929,7 +942,13 @@ foreach_interrupt! {
929 impl_1ch_cmp_timer!($inst); 942 impl_1ch_cmp_timer!($inst);
930 impl_2ch_cmp_timer!($inst); 943 impl_2ch_cmp_timer!($inst);
931 impl BasicInstance for crate::peripherals::$inst {} 944 impl BasicInstance for crate::peripherals::$inst {}
932 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 945 impl CaptureCompare16bitInstance for crate::peripherals::$inst {
946 /// Enable timer outputs.
947 fn enable_outputs(&self) {
948 use crate::timer::sealed::GeneralPurpose1ChannelComplementaryInstance;
949 self.set_moe(true);
950 }
951 }
933 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 952 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
934 }; 953 };
935 ($inst:ident, timer, TIM_2CH_CMP, CC, $irq:ident) => { 954 ($inst:ident, timer, TIM_2CH_CMP, CC, $irq:ident) => {
@@ -947,7 +966,13 @@ foreach_interrupt! {
947 impl_1ch_cmp_timer!($inst); 966 impl_1ch_cmp_timer!($inst);
948 impl_2ch_cmp_timer!($inst); 967 impl_2ch_cmp_timer!($inst);
949 impl BasicInstance for crate::peripherals::$inst {} 968 impl BasicInstance for crate::peripherals::$inst {}
950 impl CaptureCompare16bitInstance for crate::peripherals::$inst {} 969 impl CaptureCompare16bitInstance for crate::peripherals::$inst {
970 /// Enable timer outputs.
971 fn enable_outputs(&self) {
972 use crate::timer::sealed::GeneralPurpose1ChannelComplementaryInstance;
973 self.set_moe(true);
974 }
975 }
951 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} 976 impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
952 }; 977 };
953 ($inst:ident, timer, TIM_ADV, CC, $irq:ident) => { 978 ($inst:ident, timer, TIM_ADV, CC, $irq:ident) => {
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index 1acba504e..6df2f66ec 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -82,6 +82,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
82 82
83 this.inner.set_counting_mode(counting_mode); 83 this.inner.set_counting_mode(counting_mode);
84 this.set_frequency(freq); 84 this.set_frequency(freq);
85 this.inner.enable_outputs(); // Required for advanced timers, see CaptureCompare16bitInstance for details
85 this.inner.start(); 86 this.inner.start();
86 87
87 [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4] 88 [Channel::Ch1, Channel::Ch2, Channel::Ch3, Channel::Ch4]