cpu/stm32: implement periph_gpio_ll_switch_dir#20805
Merged
maribu merged 3 commits intoRIOT-OS:masterfrom Aug 9, 2024
Merged
Conversation
7469811 to
d42aa66
Compare
benpicco
reviewed
Aug 5, 2024
0a23efb to
e7def57
Compare
1 task
It turns out that the feature to switch the GPIO direction quickly is not only a way to emulate open drain / open source mode for less sophisticated GPIO peripherals that do not natively support it. It also enables tri-state output (push-pull high, push-pull low, high impedance), which is useful e.g. for driven charlieplexed LEDs quickly. This changes the API by introducing a `gpio_ll_prepare_switch_dir()` function that prepares the value used to identify which pins should be switched to input or to output mode. This is useful for GPIO peripherals in which the GPIO mode register does not allocate one bit per pin (so that only the direction is given there), such as the one for STM32. This allows an STM32 implementation in which preparing the bitmask needed to modify the direction of pins is not trivial.
In all other tests we added a delay after writing to the output buffer of GPIO A before expected the input buffer of GPIO B (connected to A) to reflect the change, but not in test_switch_dir(). This adds the delay here as well to make the test more robust in regard to GPIO peripherals that react not as fast as the CPU can query them.
909f536 to
994d05c
Compare
benpicco
approved these changes
Aug 8, 2024
5f39c0b to
00e12c9
Compare
Member
Author
|
I forgot about the legacy STM32F1 GPIO peripheral. It is not trivial to provide the feature there, as the configuration is spread over multiple registers. For now, the feature is provided only by STM32 families other than F1. |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 8, 2024
…_gpio_ll_switch_dir cpu/stm32: implement `periph_gpio_ll_switch_dir`
This implements periph_gpio_ll_switch_dir for STM32 except for STM32F1, which has a different register layout.
00e12c9 to
8839ccb
Compare
Member
Author
|
Thx! |
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.
Contribution description
This changes the API of the
periph_gpio_ll_switch_dirfeature, so thatgpio_ll_switch_dir_output()andgpio_ll_switch_dir_input()no longer directly take a bitmask indicating with GPIO pins to switch, but the output ofgpio_ll_prepare_switch_dir()that takes this bitmask.The reason for this change is that on STM32 (except for F1) the GPIO periphal has no direction register (with one bit per pin), but a mode register (with two bits per pin). This required some non-trivial bit operation to prepare the bitmask to write to the mode register from the bitmask specifying the pins to change. Splitting out the preparation allows to cache the result and switch directions fast anyway.
An implementation for STM32F1 is not provided yet.
A default implementation for
gpio_ll_prepare_switch_dir()is provided that returns the argument unmodified, so that no overhead is introduced on the platforms already supportingperiph_gpio_ll_switch_dir.Testing procedure
Issues/PRs references
None