rp2/rp2_pio: Add support for the origin directive in PIO programs. - #19618
Open
agatti wants to merge 1 commit into
Open
rp2/rp2_pio: Add support for the origin directive in PIO programs.#19618agatti wants to merge 1 commit into
agatti wants to merge 1 commit into
Conversation
This commit adds a new parameter to the PIO program decorator, to indicate an explicit program origin in the PIO memory area. There was no possibility to pass an origin position in the PIO constructor, and that would create some problems for PIO programs that use computed jump offsets. By default the state machine program loader does not guarantee a specific start position inside the PIO memory block, which makes things unpredictable for jump tables. Now the decorator allows for an `origin` parameter that takes an integer containing the required offset in PIO memory. Without that parameter behaviour is unchanged. An example showing the usage of this parameter is supplied, `examples/rp2/pio_quadencoder.py`. That is a direct port from `quadrature_encoder.pio` in the Raspberry Pi Pico samples repository into MicroPython's own PIO assembler. Relevant documentation was also updated to keep track of the new decorator signature. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19618 +/- ##
=======================================
Coverage 98.58% 98.58%
=======================================
Files 182 182
Lines 23322 23322
Branches 5 5
=======================================
Hits 22993 22993
Misses 328 328
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code size report: |
Octoprobe PR report
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new parameter to the PIO program decorator, to indicate an explicit program origin in the PIO memory area.
There was no possibility to pass an origin position in the PIO constructor, and that would create some problems for PIO programs that use computed jump offsets. By default the state machine program loader does not guarantee a specific start position inside the PIO memory block, which makes things unpredictable for jump tables.
Now the decorator allows for an
originparameter that takes an integer containing the required offset in PIO memory. Without that parameter behaviour is unchanged.An example showing the usage of this parameter is supplied,
examples/rp2/pio_quadencoder.py. That is a direct port fromquadrature_encoder.pioin the Raspberry Pi Pico samples repository into MicroPython's own PIO assembler.Relevant documentation was also updated to keep track of the new decorator signature.
This closes #11531.
Testing
Although I don't have an encoder available (who knows where the rotary switches went...), the clock frequency is high enough that when running the example code on a RP2040 shorting either pin 16 or pin 17 to ground triggers an increment/decrement response, demonstrating that the PIO program origin was actually picked up correctly (plus you can debug your own way through and see the value coming out :)).
Trade-offs and Alternatives
Size increase is minimal, but this might probably be the least amount of code needed to pull this off.
There are a few PRs that are supposed to improve the state of things w.r.t. PIO, but none of those actually implement origin support. If somebody else with a more complete PR wants to take these changes in to merge with theirs, that's fine by me.
Generative AI
I did not use generative AI tools when creating this PR.