Skip to content

Error handling for setting up pinmux mode in gpio.setup() #152

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

Merged
merged 2 commits into from
Aug 23, 2017

Conversation

zserg8
Copy link

@zserg8 zserg8 commented Jul 31, 2017

I added error handling for the gpio.setup() method in the part where it sets up the pinmux mode. Before it just silently failed if it was unable to write to the corresponding sysfs file.
I also altered underlying set_pin_mode() C function to provide debug output (as it is done in other places) when library is built/run in debug mode

@pdp7
Copy link
Collaborator

pdp7 commented Aug 1, 2017

@zsserg Thanks for creating this pull request. I'll test it out tonight.

@pdp7
Copy link
Collaborator

pdp7 commented Aug 6, 2017

@zsserg Unfortunately, I'm traveling right now, but I will review and respond when I'm back home on Thursday (Aug 10). Thanks.

@pdp7
Copy link
Collaborator

pdp7 commented Aug 12, 2017

Testing with @zsserg repo at e86acc4

debian@beaglebone:/tmp/adafruit-beaglebone-io-python$ git log -2 --oneline
e86acc4 * Added debug output to set_pin_mode()
a9e745d * Added error checking for setting pin direction in gpio.setup() (Python)
debian@beaglebone:/tmp/adafruit-beaglebone-io-python$ sudo pytest
==================================================================== test session starts =====================================================================
platform linux2 -- Python 2.7.9, pytest-3.1.2, py-1.4.34, pluggy-0.4.0
rootdir: /tmp/adafruit-beaglebone-io-python, inifile:
collected 58 items 

test/test_adc.py ......
test/test_gpio_input.py ..
test/test_gpio_output.py ......
test/test_gpio_setup.py ...F......
test/test_led.py ..
test/test_pwm_setup.py ...........................
test/test_spi.py ..
test/test_uart.py ...

========================================================================== FAILURES ==========================================================================
______________________________________________________________ TestSetup.test_setup_input_name _______________________________________________________________

self = <test_gpio_setup.TestSetup instance at 0xb65428f0>

    def test_setup_input_name(self):
>       GPIO.setup("TIMER6", GPIO.IN)
E       ValueError: Set gpio mode failed, missing file or invalid permissions.

test/test_gpio_setup.py:37: ValueError
============================================================ 1 failed, 57 passed in 8.60 seconds =============================================================

The issue seems to be with P8_10:

./source/common.c: { "TIMER6", "P8_10", 68, -1, -1},

@pdp7
Copy link
Collaborator

pdp7 commented Aug 12, 2017

Trying to track down the issue with TIMER6 in GPIO.setup():

FAIL: TIMER6

debian@beaglebone:~$ sudo strace -o /tmp/test-pr152-timer6.txt -f python test-pr152-timer6.py
Traceback (most recent call last):
  File "test-pr152-timer6.py", line 3, in <module>
    GPIO.setup("TIMER6", GPIO.IN)
ValueError: Set gpio mode failed, missing file or invalid permissions.

debian@beaglebone:~$ cat test-pr152-timer6.py
import Adafruit_BBIO.GPIO as GPIO

GPIO.setup("TIMER6", GPIO.IN)

PASS: P8_10

debian@beaglebone:~$ sudo strace -o /tmp/test-pr152-p8-10.txt -f python test-pr152-p8-10.py

debian@beaglebone:~$ cat test-pr152-p8-10.py
import Adafruit_BBIO.GPIO as GPIO

GPIO.setup("P8_10", GPIO.IN)

strace for P8_10

6043  access("/sys/class/gpio/gpio68", R_OK|W_OK|X_OK) = 0
6043  open("/sys/class/gpio/gpio68/direction", O_WRONLY) = 4
6043  write(4, "in", 2)                 = 2
6043  close(4)                          = 0
6043  open("/sys/devices/platform/ocp/ocp:P8_10_pinmux/state", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 4
6043  fstat64(4, {st_mode=S_IFREG|0664, st_size=4096, ...}) = 0
6043  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f7f000
6043  write(4, "gpio", 4)               = 4
6043  close(4)                          = 0

strace for TIMER6

6020  access("/sys/class/gpio/gpio68", R_OK|W_OK|X_OK) = 0
6020  open("/sys/class/gpio/gpio68/direction", O_WRONLY) = 4
6020  write(4, "in", 2)                 = 2
6020  close(4)                          = 0
6020  open("/sys/devices/platform/ocp/ocp:TIMER_pinmux/state", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)

Summary

So it appears that /sys/devices/platform/ocp/ocp:P8_10_pinmux/state is correct while /sys/devices/platform/ocp/ocp:TIMER_pinmux/state is invalid.

@pdp7
Copy link
Collaborator

pdp7 commented Aug 12, 2017

The test of GPIO.setup("TIMER6", GPIO.IN) has been in test/test_gpio_setup.py for years (9903992).

To double check, I just installed the latest revision from adafruit repo's master branch and pytest completed without any issues.

However, when I investigated with strace, I have found that it is just failing silently. The regression makes sense given the nature of this PR.

6613  access("/sys/class/gpio/gpio68", R_OK|W_OK|X_OK) = 0
6613  open("/sys/class/gpio/gpio68/direction", O_WRONLY) = 4
6613  write(4, "in", 2)                 = 2
6613  close(4)                          = 0
6613  open("/sys/devices/platform/ocp/ocp:TIMER_pinmux/state", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory)

@zsserg I'm going to investigate how to resolve the TIMERn path issue. If not a simple fix, I will probably just remove that specific test, merge this PR and then look to address the TIMERn path issue.

@zserg8
Copy link
Author

zserg8 commented Aug 14, 2017

What kernel for BB are you using? There have been some breaking changes in sysFS paths between 3.9-4.0 (or 4.0-4.1, I dion't remember exactly). For example, the udev-non-root-gpio-permissions.sh script provided with this repo is not valid any more for 4.4 kernels as some of the sysFS paths are now different.

@pdp7
Copy link
Collaborator

pdp7 commented Aug 15, 2017

@zsserg The kernel is 4.4.68-ti-r111 on the BBB I'm testing on. Thanks for the idea, I'll check that out.

@pdp7 pdp7 merged commit 3dad90d into adafruit:master Aug 23, 2017
pdp7 added a commit that referenced this pull request Aug 23, 2017
Replace GPIO for test "TIMER6" with "P8_10" as TIMERn syntax
is not working on newer kernels such as 4.4.

This is a valid path:
/sys/devices/platform/ocp/ocp:P8_10_pinmux/state

while this path is invalid:
/sys/devices/platform/ocp/ocp:TIMER_pinmux/state

Originally discovered while testing Pull Request #152.
See issue #156 for details.
@pdp7
Copy link
Collaborator

pdp7 commented Aug 23, 2017

@zsserg thanks. I've merged this and created #156 to address the failed test for GPIO TIMER6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy