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

A simple_pwm update event interrupt to be able to synchronize with pwm #2172

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

smeenka
Copy link
Contributor

@smeenka smeenka commented Nov 10, 2023

To able to synchronize with a pwm (for example sample motor current with ADC) I propose hereby an update interrupt for simple_pwm.
A test can be found in stm32g0 example directory, which shows the functionality.

@@ -0,0 +1,43 @@
[default.probe]
Copy link
Member

Choose a reason for hiding this comment

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

examples don't use cargo-embed, please don't add an Embed.toml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove. Also change the implementation, not to use the global static signal, but a signal in interrupt state context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a reset function to pwm to be able to synchronize multiple timers to have the same phase.

@Dirbaio
Copy link
Member

Dirbaio commented Nov 19, 2023

LGTM, except could you change State to contain an AtomicWaker instead of a Signal? t's slightly faster/smaller.

This means you'll have to use a manually-written poll_fn from the non-interrupt code:

  • Enable interrupt
  • poll_fn that does
    • register waker
    • if interrupt flag is set, clear it, return Poll::Ready
    • else return Poll::Pending

and the interrupt handler doe

  • disable interrupt (NOT clear the interrupt flag like you'd usually do, leave it there so the task can see it)

This pattern is used by a lot of drivers in embassy-stm32 to handle interrupts.

@Dirbaio Dirbaio marked this pull request as draft December 3, 2023 21:21
@brunob45 brunob45 mentioned this pull request May 6, 2024
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.

2 participants