Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM32 SimplePwm: Fix regression and re-enable output pin #2670

Merged

Conversation

jr-oss
Copy link
Contributor

@jr-oss jr-oss commented Mar 7, 2024

PR #2499 implemented timer hierarchy, but removed enable_outputs() from trait CaptureCompare16bitInstance and from SimplePwm.

This functions is required for advanced timers to set bit BDTR.MOE and to enable the output signal.

@jr-oss
Copy link
Contributor Author

jr-oss commented Mar 7, 2024

I left comments in Issue #2409 with my understanding what happened.
It's still unclear to me, whether this approach fits the new timer hierarchy.

Since this is the second time, that enable_outputs() got removed from SimplePwm, I added a lengthy comment.
I hope, this is ok.

@eZioPan
Copy link
Contributor

eZioPan commented Mar 8, 2024

I left comments in Issue #2409 with my understanding what happened.
It's still unclear to me, whether this approach fits the new timer hierarchy.

Ah, I'm terribly sorry for this mess. I didn't notice that SimplePwm is implemented on TIM_GP16 at that time, thus adding enable_output() to TIM_1CH_CMP is useless for this situation.

You approach is correct on both old and new timer hierarchy. It requires a empty implement enable_output for TIM_GP16, and enable MOE inside the method for TIM_1CH_CMP / TIM_2CH_CMP / TIM_ADV.

Comment on lines 441 to 445

/// Enable timer outputs.
fn enable_outputs(&self) {
Self::regs_1ch_cmp().bdtr().modify(|w| w.set_moe(true));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you restore this method? MOE existed on all TIM_1CH_CMP TIM_2CH_CMP and TIM_ADV.

Copy link
Contributor

@eZioPan eZioPan Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even better, rename this method to something like fn set_moe(&self, enable: bool), and call this method in public trait implement.

If you do so, please don't forget to adjust the doc for the new method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced enable_outputs()by fn set_moe(&self, enable: bool)

// SimplePwm<'d, T> is implemented for T: CaptureCompare16bitInstance
// Advanced timers implement this trait, but the output needs to be
// enabled explicitly.
// To support basic and advanced timers, this function is added
Copy link
Contributor

@eZioPan eZioPan Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It better to say

"To support general-purpose and advanced timer, ..."

since there is already another timer called BasicInstance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I changed the comment accordingly

Comment on lines 953 to 957
/// Enable timer outputs.
fn enable_outputs(&self) {
use crate::timer::sealed::AdvancedControlInstance;
let r = Self::regs_advanced();
r.bdtr().modify(|w| w.set_moe(true));
Copy link
Contributor

@eZioPan eZioPan Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to copy this code (or .set_moe(true)) to other 2 blocks: ($inst:ident, timer, TIM_1CH_CMP, UP, $irq:ident), ($inst:ident, timer, TIM_2CH_CMP, UP, $irq:ident), to make sure they also enable MOE.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I would have missed these locations.
Added fn enable_outputs(&self) to these timers, also.

@jr-oss
Copy link
Contributor Author

jr-oss commented Mar 8, 2024

Thanks for your fast response and don't worry about the mess.
It's easy to miss the output enable behavior between basic and advanced timers and I only noticed, because I use it in my project.

I can squash the commits, if you agree to the current state.

@eZioPan
Copy link
Contributor

eZioPan commented Mar 8, 2024

I can squash the commits, if you agree to the current state.

Yeah! It looks good to me!

And I also test PWM output on my dev board with TIM1(ADV), TIM15(2CH_CMP), TIM16(1CH_CMP), they all output correct waveform.

PR embassy-rs#2499 implemented timer hierarchy, but removed enable_outputs()
from trait CaptureCompare16bitInstance and from SimplePwm.

This functions is required for advanced timers to set bit BDTR.MOE
and to enable the output signal.
@jr-oss jr-oss force-pushed the fix_regression_simple_pwm_output_enable branch from d96926f to b7bb4b2 Compare March 8, 2024 10:20
@jr-oss
Copy link
Contributor Author

jr-oss commented Mar 8, 2024

Thanks. I squashed the commits.

@Dirbaio Dirbaio added this pull request to the merge queue Mar 8, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 8, 2024
@Dirbaio Dirbaio added this pull request to the merge queue Mar 8, 2024
Merged via the queue into embassy-rs:main with commit 7718d66 Mar 8, 2024
6 checks passed
@jr-oss jr-oss deleted the fix_regression_simple_pwm_output_enable branch March 8, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants