cpu/esp32: fix of gpio_read for output ports#11950
Merged
miri64 merged 2 commits intoRIOT-OS:masterfrom Sep 24, 2019
Merged
Conversation
While testing the Arduino example for ESP32 boards, the problem of gpio_read for output ports was figured out. During these tests, also the wrong comment has been fixed.
Although it isn't explicitly specified in API, gpio_read should return the last written output value for output ports. Since the handling of inputs and outputs is strictly separated by several registers in ESP32, gpio_read returned always the initial value of the input register. Therefore, a case distinction had to make. While for input ports the real value has to be read from the input register, the last written value for the output port has to be read from the output register.
Member
|
@gschorcht would like to see this merged for 2019.10, but we need someone to confirm the fix. @yegorich, did you actually test this? |
Contributor
Author
Since it is a fix of a real bug, I would say yes. |
Contributor
|
I've tested this PR on a TTGO T-Beam board (#11418). And everything is working as expected. |
yegorich
approved these changes
Sep 23, 2019
Member
|
Thanks for testing, @yegorich! Let me see if I can motivate a maintainer to inspect the code. |
leandrolanzieri
approved these changes
Sep 24, 2019
Contributor
leandrolanzieri
left a comment
There was a problem hiding this comment.
Changes make sense. I tested this on the esp32-wroom-32, both for pins below and above number 32, inputs and outputs, and works as expected. ACK!
Contributor
|
Rebuilding once more just in case |
Contributor
Author
|
Thank you all for testing and merging. |
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
Although it isn't explicitly specified in API,
gpio_readshould return the last written output value for output ports. Since the handling of inputs and outputs is strictly separated by several registers in ESP32,gpio_readreturned always the initial value of the input register. Therefore,gpio_readalways returned0for output ports.This PR fixes this problem. For this purpose, a case distinction is made in
gpio_read. While for input ports the real value are read from the ESP32 input register, the last written value for the output port is read from the ESP32 output register.Testing procedure
Flash
tests/periph_gpiowith to ESP32 board, for example:Use the following commands:
Without this fix
read 0 4would always returnGPIO_PIN(0.04) is LOW.Issues/PRs references