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

cpu: stm32_common: always do gpio_read() from input register #8556

Merged
merged 1 commit into from
Mar 6, 2018

Conversation

kaspar030
Copy link
Contributor

Contribution description

Current stm32 gpio_read() returns the value of the output register (ODR), if the pin is configured as output.

According to the datasheet (of stm32f401):

When the I/O port is programmed as Input:
• The data present on the I/O pin are sampled into the input data register every AHB
clock cycle
• A read access to the input data register provides the I/O State

When the I/O port is programmed as output:
• The data present on the I/O pin are sampled into the input data register every AHB
clock cycle
• A read access to the input data register gets the I/O state
• A read access to the output data register gets the last written value

When the I/O port is programmed as alternate function:
• The data present on the I/O pin are sampled into the input data register every AHB
clock cycle
• A read access to the input data register gets the I/O state

Thus the input register always contains the actual pin state. The output register only what was last set, which for alternate functions (PWM) is always 0.

This PR changes the read to always return the pins IDR.

@kaspar030 kaspar030 added Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 13, 2018
@vincent-d
Copy link
Member

Looks legit. And it seems that's how it's implemented in st libraries.

Copy link
Member

@vincent-d vincent-d left a comment

Choose a reason for hiding this comment

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

ACK

@vincent-d
Copy link
Member

Tested on a nucleo144-f413 with example/default. I won't merge now as the request for comments tag as been set, but I'm OK with these changes.

Copy link
Contributor

@haukepetersen haukepetersen left a comment

Choose a reason for hiding this comment

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

ACK

@haukepetersen haukepetersen removed the Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR label Mar 6, 2018
@haukepetersen
Copy link
Contributor

all green -> go

@haukepetersen haukepetersen merged commit e78b055 into RIOT-OS:master Mar 6, 2018
@haukepetersen haukepetersen deleted the stm32_gpio_read branch March 6, 2018 14:30
@kaspar030
Copy link
Contributor Author

(@haukepetersen and I can't remember why this was implemented as it was before)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants