Enabling PWM on BeagleBone Black

I’m having difficulty getting PWM working on my Beaglebone Black, recently flashed with balenaOS 2.29.2+rev3, kernel version 4.14.53+. The device overlays were supposedly added back in balenaOS v2.7.5+rev1.

The usual methods of enabling capes and such don’t seem to be working. I SSH’d into the host, and can’t find uEnv.txt (looked in /boot and /resin-boot), and “echo BB-PWM0 > /sys/devices/platform/bone_capemgr/slots” fails with “-sh: echo: write error: No such file or directory” (I can read the slots file just fine, though).

If it helps, my end goal is to extend the functionality of an existing Python app which is currently using the Adafruit BBIO library to control some LED drivers.

1 Like

Hi

it seems the file that you need to create / edit to enable capes is /mnt/boot/resinOS_uEnv.txt
I just tried this on a beaglebone green with balena-os following this forum thread Beaglebone cape support and it appears to work.
The difference to the above thread is that it is not /mnt/boot/uEnv.txt but /mnt/boot/resinOS_uEnv.txt which is being processed on boot.
Cheers Thomas

Yup, there it is! Does the file have to be “resinOS_uEnv.txt”? The regular uEnv.txt is there, and I tested out making changes to that, and it seems to work.

I can get one pin from one overlay at a time to work (using the Adafruit_BBIO library, working from a minimal container with the base image resin/beaglebone-black-python:3 and the library installed with pip). I tried manually writing to the files in /sys/devices/platform/ without any luck as well.

I’ve tried a few combinations of the three PWM overlays (PWM0, 1, and 2 in /boot/overlays/ BB-PWMx-00A0.dtbo), each of which runs two pins, and it’s a mixed bag of results. In a couple cases, the first pin works, and the other errors out with “Problem with a sysfs file”. In another case, both pins in the overlay work, but then I get “Could not write to the frequency file” when trying to change the frequency. In the case with both PWM1 and PWM2 enabled, PWM2 works (only P8_13), and starting up PWM1 produces no errors for either pin, but also produces no output.

Here are the contents of my /mnt/boot/uEnv.txt file:

enable_uboot_overlays=1
uboot_overlay_addr0=/boot/overlays/BB-PWM1-00A0.dtbo
uboot_overlay_addr1=/boot/overlays/BB-PWM2-00A0.dtbo

checking this information with our engineers and will get back to you when we have more information.

Hi. Please see https://stackoverflow.com/questions/50203064/pwm-on-beaglebone-black-v4-14 (and https://github.com/beagleboard/linux/issues/139 as original info)

1 Like

Okay, working with the system files seems to work reliably. The Python library has been hit or miss for me. It seems like PWM doesn’t work right out of the box, as mentioned in the StackOverflow post, but they just have to be enabled in uEnv.txt.

To summarize the information from @samothx and @floion, at least for what worked for me:

  • Edit /mnt/boot/uEnv.txt to enable U-Boot overlays and add the overlay(s) needed.
  • Edit the files at /sys/class/pwm like normal.
  • Results may vary with the Adafruit_BBIO Python library

Thanks for the help!