-
Notifications
You must be signed in to change notification settings - Fork 2k
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
cpu/samd21: implement gpio_toggle properly #2696
Conversation
gpio_toggle relies on gpio_read, so it can't work if gpio_read is not
working.
I'm surprised that the samd21 doesn't have a hardware toggle register.
|
I didn't read the datasheet, just looked what |
I'm not opposed to this PR, and I don't have a samd21 anyway, but I think
|
@gebart there I fixed it. |
@LudwigOrtmann nice work, sorry if I sounded snarky before, I didn't mean to cause you extra work. |
@gebart I didn't feel offended in any way and I'm grateful for your hint. |
switch (dev) { | ||
#if GPIO_0_EN | ||
case GPIO_0: | ||
(&GPIO_0_DEV)->OUTTGL.reg = 1 << GPIO_0_PIN; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste
@PeterKietzmann looks like something else is driving the pin as well |
@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 |
Do you have any pull resistors on any of the lines or are you reading floating inputs on the logic analyzer? |
I have some strange behavior here that I need to handle first. But I just realized that |
My analyzer is floating. |
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:
|
OK, so shall I squash? |
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? |
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.
30b9739
to
1572c94
Compare
squashed. @PeterKietzmann |
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 |
I feel like travis will never do the job. Anyone against merging without waiting for travis? |
I went through Travis' build queue and killed off a bunch of outdated PRs
|
I'd open an issue / follow up PR for addressing #2696 (comment) in all the places it occurs. |
@LudwigOrtmann do you know if it is specific to the samd21 port or if it is widespread? |
Not yet. |
I ran the compile tests and the static tests locally, there was nothing related to this PR so ACK. |
cpu/samd21: implement gpio_toggle properly
Issue created: #2726 |
edit:
implement
gpio_toggle
properly, the original method usedgpio_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 asoutput only.
gpio_toggle
relies on gpio_read, so it can't work ifgpio_read
is notworking.
Tested withtests/periph_gpio
which didn't work before and works now.