Skip to content

PWM Fails on PocketBeagle - "RuntimeError: Problem with the cape manager" #286

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

Closed
ansarid opened this issue Oct 12, 2018 · 15 comments
Closed
Assignees

Comments

@ansarid
Copy link

ansarid commented Oct 12, 2018

I have been trying to get PWM working on pins P2_01 and P2_03 on the PocketBeagle but have been unsuccessful. I am using Debian 9.5 and have installed the Adafruit-BBIO library. I do have digital outputs working but no PWM. I wrote a short program to test PWM as seen here:

import Adafruit_BBIO.PWM as PWM

pin_l = "P2_1"		# GPIO050 (A PWM1) - Left Motors Pin
pin_r = "P2_3"		# GPIO023 (B PWM2) - Right Motors Pin

DC_l = 100		# Duty Cycle in % from (0-100) - Left Motors Pin
DC_r = 100		# Duty Cycle in % from (0-100) - Right Motors Pin

PWM.start(pin_l, 0, 1000)	# Start PWM on Left Motors Pin
PWM.start(pin_r, 0, 1000)	# Start PWM on Right Motors Pin

while 1:

    PWM.set_duty_cycle(pin_l, DC_l)	# Set PWM on Left Motors Pin
    PWM.set_duty_cycle(pin_r, DC_r)	# Set PWM on Right Motors Pin

PWM.stop(pin_l)
PWM.stop(pin_r)
PWM.cleanup()

When I run this program I get the below error:

Traceback (most recent call last):
  File "/var/lib/cloud9/pwm.py", line 9, in <module>
    PWM.start(pin_l, 0, 1000)   # Start PWM on Left Motors Pin
RuntimeError: Problem with the cape manager

As you can see, the program fails when starting PWM on the first pin and I have been unable to solve this issue. Also, this code does work perfectly fine on the BeagleBone Black after changing the code to use its PWM pins.

@pdp7 pdp7 self-assigned this Oct 12, 2018
@pdp7
Copy link
Collaborator

pdp7 commented Oct 12, 2018

@ansarid Please run:
sudo /opt/scripts/tools/version.sh
and copy the output to this issue.

@ansarid
Copy link
Author

ansarid commented Oct 12, 2018

@ansarid Please run:
sudo /opt/scripts/tools/version.sh
and copy the output to this issue.

debian@beaglebone:~$ sudo /opt/scripts/tools/version.sh

git:/opt/scripts/:[1aa73453b2c980b75e31e83dab7dd8b6696f10c7]
eeprom:[A335PBGL00A21748EPB00801]
model:[TI_AM335x_PocketBeagle]
dogtag:[BeagleBoard.org Debian Image 2018-10-07]
bootloader:[microSD]:[/dev/mmcblk0]:[U-Boot 2018.09-00002-g0b54a51eee]:[location: dd MBR]
kernel:[4.14.71-ti-r80]
nodejs:[v6.14.4]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade <pkg>]
pkg:[bb-cape-overlays]:[4.4.20180928.0-0rcnee0~stretch+20180928]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0~stretch+20180517]
pkg:[kmod]:[23-2rcnee1~stretch+20171005]
pkg:[librobotcontrol]:[1.0.3-git20181005.0-0rcnee0~stretch+20181005]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee1~stretch+20180328]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[    1.099274] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[    1.107530] gpio-of-helper ocp:cape-universal: ready
END

@pdp7
Copy link
Collaborator

pdp7 commented Oct 12, 2018

@ansarid It looks like you are a running an update to image. The next step is for me to try to reproduce this issue. I will attempt to reproduce and followup here.

@ansarid
Copy link
Author

ansarid commented Oct 12, 2018

@ansarid It looks like you are a running an update to image. The next step is for me to try to reproduce this issue. I will attempt to reproduce and followup here.

Thank you for your help! As far as I remember all I have done is flashed Debian 9.5 to a microSD card and followed Adafruit's Adafruit_BBIO install guide for Debian.

@pdp7
Copy link
Collaborator

pdp7 commented Oct 16, 2018

Ok thanks. I just tried running this on a BeagleBone Black and got no exception. I should have access to a PocketBeagle later today to try running on that.

@ansarid
Copy link
Author

ansarid commented Oct 16, 2018

Ok thanks. I just tried running this on a BeagleBone Black and got no exception. I should have access to a PocketBeagle later today to try running on that.

Yes, the code works fine on the BeagleBone Black, but does not work on the PocketBeagle.

@pdp7
Copy link
Collaborator

pdp7 commented Oct 17, 2018

I have been able to replicate the issue on PocketBeagle:

debian@beaglebone:~$ sudo strace -f -o /tmp/a python3 ./pwm-issue286.py 
[sudo] password for debian: 
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
common.c: device_tree_loaded(): pocketbeagle(): TRUE
Traceback (most recent call last):
  File "./pwm-issue286.py", line 9, in <module>
    PWM.start(pin_l, 0, 1000)	# Start PWM on Left Motors Pin
RuntimeError: Problem with the cape manager
debian@beaglebone:~$ 

The print statement shows that it is skipping loading device tree overlays (e.g. "virtual capes") which is correct as the PocketBeagle has a complete device tree binding (DTB) at boot.

@pdp7
Copy link
Collaborator

pdp7 commented Oct 17, 2018

Related code in ./source/py_pwm.c:

    err = pwm_start(key, duty_cycle, frequency, polarity);
    switch (err) {
        case BBIO_OK:
            break;

        case BBIO_ACCESS:
            PyErr_SetString(PyExc_IOError, "could not access a necessary file");
            return NULL;

        case BBIO_SYSFS:
            PyErr_SetString(PyExc_RuntimeError, "Problem with a sysfs file");
            return NULL;

        case BBIO_CAPE:
            PyErr_SetString(PyExc_RuntimeError, "Problem with the cape manager");
            return NULL;

@pdp7
Copy link
Collaborator

pdp7 commented Oct 17, 2018

This might do the trick:

diff --git a/source/c_pwm.c b/source/c_pwm.c
index f983592..ec4183a 100644
--- a/source/c_pwm.c
+++ b/source/c_pwm.c
@@ -339,6 +339,10 @@ BBIO_err pwm_setup(const char *key, __attribute__ ((unused)) float duty, __attri
     // Make sure that one of the universal capes is loaded
     if( !uboot_overlay_enabled() // only check kernel overlays if u-boot overlays are not being used
         &&
+        !beaglebone_blue() // beaglebone blue has complete dtb file and does not need overlays 
+        &&
+        !pocketbeagle() // pocketbeagle has complete dtb file and does not need overlays
+        &&
         !( device_tree_loaded("cape-univ-audio") // from cdsteinkuehler/beaglebone-universal-io
         || device_tree_loaded("cape-univ-emmc")  // ""
         || device_tree_loaded("cape-univ-hdmi")  // ""

Testing it out

@pdp7
Copy link
Collaborator

pdp7 commented Oct 17, 2018

looks that did resolve the issue:

debian@beaglebone:~/ssh/adafruit-beaglebone-io-python$ sudo strace -f -o /tmp/a python3 ~/pwm-issue286.py 
Adafruit_BBIO: pwm_start: P2_1, 0.000000, 1000.000000, 0
Adafruit_BBIO: pwm_start: P2_3, 0.000000, 1000.000000, 0

I'll push a commit.

pdp7 added a commit that referenced this issue Oct 17, 2018
pocketbeagle and beaglebone blue have complete dtb file
and do not need overlays
@pdp7
Copy link
Collaborator

pdp7 commented Oct 17, 2018

@ansarid please try master branch which includes this fix c09ab8e

@ansarid
Copy link
Author

ansarid commented Oct 18, 2018

@ansarid please try master branch which includes this fix c09ab8e

It works now! Thank you!

@pdp7
Copy link
Collaborator

pdp7 commented Oct 18, 2018

I've created a new release:
Release 1.1.0
I published it to PyPI and is available to install via pip.

@ansarid
Copy link
Author

ansarid commented Oct 18, 2018 via email

@lifton
Copy link

lifton commented Oct 23, 2018

I just ran into the same problem and verified that @pdp7's fix works. Thanks!

@pdp7 pdp7 closed this as completed Oct 23, 2018
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

3 participants