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

Segmentation fault error #3

Closed
alexanderhiam opened this issue May 29, 2012 · 7 comments
Closed

Segmentation fault error #3

alexanderhiam opened this issue May 29, 2012 · 7 comments

Comments

@alexanderhiam
Copy link
Member

From <ahref="https://github.com/alexanderhiam/PyBBIO/issues/1">Issue 1:
"If I try the following with a photoresistor plugged-in I get a real value.
cat /sys/bus/platform/devices/tsc/ain1

But if I run an PyBBIO code that accesses any of the analog-inputs and then try to run the above cat I get a Segmentation fault error."

The problem seems to be that the _analog_cleanup() routine is at the moment restoring the ADC module to its default reset state, and the kernel's file system interface expects it to be in whatever state it is put into when the Beaglebone boots up. Once I figure out the state it wants to be in I'll set it in _analog_cleanup(), but for now to use the filesystem to access the ADC requires a reboot after using PyBBIO.

@omundy
Copy link

omundy commented May 30, 2012

I checked mrBBIO which unexports this way:

fw = file("/sys/class/gpio/unexport", "w")
fw.write("%d" % (pin))

@alexanderhiam
Copy link
Member Author

Owen, thanks for you continued help on this bug!

The unexporting only applies to the digital pins, so it's unfortunately not that simple. However, I did discover the root of the problem:

When I started writing PyBBIO I was using an older Angstrom image, and it was not enabling the ADC module clock and subsystem when the BeagleBone booted. Because of this I was shutting the module back off in the _analog_cleanup() routine when a PyBBIO program exited. On more recent images, however, the ADC is turned on at boot, and that is how the kernel's ADC interface expects it to be. After running a PyBBIO program the ADC module clock would be disabled, causing segmentation faults when the kernel tried to accessed the ADC control registers.

I changed the analog cleanup routine to leave the ADC system enabled, and all appears to be working happily now on my BeagleBone, but let me know if this doesn't fix it for you.

@omundy
Copy link

omundy commented Jun 1, 2012

Hi Alexander, I tried the new version and seem to have similar problems. Once I ran this file: https://gist.github.com/2698550 I was unable to access the analog pins with the same error.

root@beaglebone:~/tests/PyBBIO-2/examples# python analog_test_simple.py 
-----
AIN0 [P9.39] - 5
AIN1 [P9.40] - 5
AIN2 [P9.37] - 3
AIN3 [P9.38] - 16
AIN4 [P9.33] - 2
AIN5 [P9.36] - 5
AIN6 [P9.35] - 0
-----
AIN0 [P9.39] - 2
AIN1 [P9.40] - 8
AIN2 [P9.37] - 8
AIN3 [P9.38] - 9
AIN4 [P9.33] - 5
AIN5 [P9.36] - 9
AIN6 [P9.35] - 8
-----
AIN0 [P9.39] - 2
AIN1 [P9.40] - 10
AIN2 [P9.37] - 5
AIN3 [P9.38] - 5
AIN4 [P9.33] - 2
^C
root@beaglebone:~/tests/PyBBIO-2/examples# cat /sys/bus/platform/devices/tsc/a1n1
Segmentation fault

@alexanderhiam
Copy link
Member Author

Did you run the install script after pulling the changes?

@omundy
Copy link

omundy commented Jun 1, 2012

Oh sweet. #cat works great after running and values read match other methods I'm using. So pull files and run the script each time there are changes? Thanks again.

# python PyBBIO-2/examples/analog_test_simple.py
AIN0 [P9.39] - 4 - photoresitor
AIN1 [P9.40] - 1981
AIN2 [P9.37] - 2275
AIN3 [P9.38] - 94
AIN4 [P9.33] - 181
AIN5 [P9.36] - 884 - temp
AIN6 [P9.35] - 420
# cat /sys/bus/platform/devices/tsc/ain1
6

@alexanderhiam
Copy link
Member Author

Glad to hear it's working!

Any changes to bbio.py or the config file require a reinstall because they both need to be copied to other locations. Other changes, like new libraries or examples, will work fine with just a pull, but it doesn't hurt to reinstall every time just to be safe.

@omundy
Copy link

omundy commented Jun 1, 2012

Got it. I've already switched back to using it. Thanks again.

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

No branches or pull requests

2 participants