From adc810d24ba25972bb8c886fce9c67ec7de4ac00 Mon Sep 17 00:00:00 2001 From: Ralf Date: Fri, 13 Oct 2023 17:38:40 +0200 Subject: [PATCH 1/2] STM32: Fix regression in advanced timer to enable output of PWM signal by partly reverting commit 74eb519 --- embassy-stm32/src/timer/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 1e0999ed..9f37b805 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -173,7 +173,7 @@ pub(crate) mod sealed { } }); } - fn enable_outputs(&mut self, _enable: bool) {} + fn enable_outputs(&mut self, _enable: bool); fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { let r = Self::regs_gp16(); @@ -401,7 +401,9 @@ macro_rules! impl_32bit_timer { #[allow(unused)] macro_rules! impl_compare_capable_16bit { ($inst:ident) => { - impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {} + impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { + fn enable_outputs(&mut self, _enable: bool) {} + } }; } @@ -450,7 +452,13 @@ foreach_interrupt! { impl CaptureCompare16bitInstance for crate::peripherals::$inst {} impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} impl AdvancedControlInstance for crate::peripherals::$inst {} - impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {} + impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { + fn enable_outputs(&mut self, enable: bool) { + use crate::timer::sealed::AdvancedControlInstance; + let r = Self::regs_advanced(); + r.bdtr().modify(|w| w.set_moe(enable)); + } + } impl sealed::ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { fn regs_gp16() -> crate::pac::timer::TimGp16 { From 9a7fda87b0335471e2944a57af684cf4b184ce07 Mon Sep 17 00:00:00 2001 From: Ralf Date: Fri, 13 Oct 2023 18:50:54 +0200 Subject: [PATCH 2/2] STM32: timer enable_output does not take bool, but just enables the output --- embassy-stm32/src/timer/complementary_pwm.rs | 2 +- embassy-stm32/src/timer/mod.rs | 8 ++++---- embassy-stm32/src/timer/simple_pwm.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 9349a6fa..e1baf6b2 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs @@ -71,7 +71,7 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> { this.inner.set_frequency(freq); this.inner.start(); - this.inner.enable_outputs(true); + this.inner.enable_outputs(); this.inner .set_output_compare_mode(Channel::Ch1, OutputCompareMode::PwmMode1); diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 9f37b805..4b88834c 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -173,7 +173,7 @@ pub(crate) mod sealed { } }); } - fn enable_outputs(&mut self, _enable: bool); + fn enable_outputs(&mut self); fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) { let r = Self::regs_gp16(); @@ -402,7 +402,7 @@ macro_rules! impl_32bit_timer { macro_rules! impl_compare_capable_16bit { ($inst:ident) => { impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { - fn enable_outputs(&mut self, _enable: bool) {} + fn enable_outputs(&mut self) {} } }; } @@ -453,10 +453,10 @@ foreach_interrupt! { impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} impl AdvancedControlInstance for crate::peripherals::$inst {} impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { - fn enable_outputs(&mut self, enable: bool) { + fn enable_outputs(&mut self) { use crate::timer::sealed::AdvancedControlInstance; let r = Self::regs_advanced(); - r.bdtr().modify(|w| w.set_moe(enable)); + r.bdtr().modify(|w| w.set_moe(true)); } } impl sealed::ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {} diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index 18ecc196..01773ff3 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs @@ -70,7 +70,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { this.inner.set_frequency(freq); this.inner.start(); - this.inner.enable_outputs(true); + this.inner.enable_outputs(); this.inner .set_output_compare_mode(Channel::Ch1, OutputCompareMode::PwmMode1);