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/samd21: implement gpio_toggle properly #2696

Merged
merged 1 commit into from
Mar 27, 2015

Conversation

LudwigKnuepfer
Copy link
Member

edit:
implement gpio_toggle properly, the original method used gpio_read which is not possible if pins are configured as output.

old description:
With this change, gpio_init_out configures pins to buffer the input value,
which in turn allows gpio_read to work if a pin has been configured as
output only.

gpio_toggle relies on gpio_read, so it can't work if gpio_read is not
working.

Tested with tests/periph_gpio which didn't work before and works now.

@LudwigKnuepfer LudwigKnuepfer added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: ARM Platform: This PR/issue effects ARM-based platforms labels Mar 23, 2015
@jnohlgard
Copy link
Member

jnohlgard commented Mar 23, 2015 via email

@LudwigKnuepfer
Copy link
Member Author

I didn't read the datasheet, just looked what gpio_init_in does.

@jnohlgard
Copy link
Member

I'm not opposed to this PR, and I don't have a samd21 anyway, but I think
the gpio toggle function should use the hardware register for toggling the
pin instead of reading and then writing back. I found a register called
PORT_OUTTGL in the header which might be of interest.
On Mar 23, 2015 6:47 PM, "Ludwig Ortmann" notifications@github.com wrote:

I didn't read the datasheet, just looked what gpio_init_in does.


Reply to this email directly or view it on GitHub
#2696 (comment).

@LudwigKnuepfer
Copy link
Member Author

@gebart there I fixed it.

@LudwigKnuepfer LudwigKnuepfer changed the title cpu/samd21: fix gpio_toggle / gpio_init_out cpu/samd21: implement gpio_toggle properly Mar 23, 2015
@jnohlgard
Copy link
Member

@LudwigOrtmann nice work, sorry if I sounded snarky before, I didn't mean to cause you extra work.

@LudwigKnuepfer
Copy link
Member Author

@gebart I didn't feel offended in any way and I'm grateful for your hint.

@LudwigKnuepfer LudwigKnuepfer added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Mar 23, 2015
@PeterKietzmann
Copy link
Member

Here you see the output of GPIO_0, GPIO_1, GPIO_2, GPIO_3, GPIO_8running the tests/periph_gpio. GPIO_3 looks weird
bildschirmfoto vom 2015-03-24 09-06-08

switch (dev) {
#if GPIO_0_EN
case GPIO_0:
(&GPIO_0_DEV)->OUTTGL.reg = 1 << GPIO_0_PIN;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to take the address and dereference it?

Copy link
Member Author

Choose a reason for hiding this comment

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

copy paste

@LudwigKnuepfer
Copy link
Member Author

@PeterKietzmann looks like something else is driving the pin as well

@jnohlgard
Copy link
Member

@PeterKietzmann Run in GDB and set a breakpoint on the line after the closing brace of the for loop toggling the pin. OrIf that doesn't yield any clues, remove the hwtimer_wait inside the toggle loop and single step through it with the logic analyzer connected to see where it goes wrong.
Watchpoints on the output register might help too.

@LudwigKnuepfer
Copy link
Member Author

From my perspective, all other pins look weird on your screenshot. This is what it looks here:
logic

I guess it has to do with some electrical effect of reading pins that are configured as input?

@jnohlgard
Copy link
Member

Do you have any pull resistors on any of the lines or are you reading floating inputs on the logic analyzer?

@PeterKietzmann
Copy link
Member

I have some strange behavior here that I need to handle first. But I just realized that GPIO_3 (PA19) is connected to the LED.

@LudwigKnuepfer
Copy link
Member Author

My analyzer is floating.

@PeterKietzmann
Copy link
Member

I gave it a try again. I assume my analyzer has floating inputs but don't now how to find this out. It is a cheap Saleae 24MHz 8Ch. Here are some things I figured out:

  • I guess the unexpected behavior occurs because of LED connected to this pin. I measured the same strange thing on the stm32f4discovery on pins where LEDs are connected to
  • the last low-to-high transition (compare channel D3 in this pic) is caused by gpio_init_in(). I guess this is not wanted for the tests/periph_gpio
  • using the internal pull-down resistors here doesn't solve the problem
  • using an external 10k resistor solves the problem
  • using the internal pull-up resistors here leads to a picture similar to the on from @LudwigOrtmann

@LudwigKnuepfer
Copy link
Member Author

OK, so shall I squash?

@PeterKietzmann
Copy link
Member

To be honest I'm not sure if this behavior is reasonable or "acceptable". Any opinions from @gebart? Anyway, this is not caused by your PR so I'd say squash and we'll open an issue or so?

@jnohlgard
Copy link
Member

The issue that you are seeing is that you are measuring a floating input, which can give you either a 1, 0, none or both, depending on anything. You shouldn't be able to expect to see a deterministic behaviour across different boards when you are measuring the signal out from an input pin, this is to be expected. I agree with @PeterKietzmann , squash and merge. Disclaimer: I have no samd21 board to test this on so I trust your experiment results, @LudwigOrtmann and @PeterKietzmann .

Before, gpio_toggle relied on gpio_read which is inefficient and does not
work with GPIOs configured as outputs.
@LudwigKnuepfer
Copy link
Member Author

squashed.

@PeterKietzmann
I don't see a reason to open an issue for undefined behavior of floating pins either.

@LudwigKnuepfer LudwigKnuepfer removed the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Mar 25, 2015
@PeterKietzmann
Copy link
Member

Dammit now it finally "clicked" for me that I measured an INPUT pin. Still it is a bit confusing that I never see a low level on this one pin (connected to the LED) even when it is initialized as GPIO_PULLDOWN. Still ACK and giving Travis a chance until tomorrow morning

@PeterKietzmann
Copy link
Member

I feel like travis will never do the job. Anyone against merging without waiting for travis?

@jnohlgard
Copy link
Member

I went through Travis' build queue and killed off a bunch of outdated PRs
which were queued for build, but there are still a lot left for Travis to
go through.. I don't like merging without Travis, but it is possible to run
the tests locally by hand. Do you mind running the compile test and static
tests on your side?
On Mar 26, 2015 10:40 AM, "Peter Kietzmann" notifications@github.com
wrote:

I feel like travis will never do the job. Anyone against merging without
waiting for travis?


Reply to this email directly or view it on GitHub
#2696 (comment).

@LudwigKnuepfer
Copy link
Member Author

I'd open an issue / follow up PR for addressing #2696 (comment) in all the places it occurs.

@jnohlgard
Copy link
Member

@LudwigOrtmann do you know if it is specific to the samd21 port or if it is widespread?

@LudwigKnuepfer
Copy link
Member Author

Not yet.

@PeterKietzmann
Copy link
Member

I ran the compile tests and the static tests locally, there was nothing related to this PR so ACK.

PeterKietzmann added a commit that referenced this pull request Mar 27, 2015
cpu/samd21: implement gpio_toggle properly
@PeterKietzmann PeterKietzmann merged commit 37e6705 into RIOT-OS:master Mar 27, 2015
@LudwigKnuepfer LudwigKnuepfer deleted the pr/samd21-gpio-toggle branch March 27, 2015 15:30
@LudwigKnuepfer
Copy link
Member Author

Issue created: #2726

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: ARM Platform: This PR/issue effects ARM-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants