BBB: Bullseye 22-07-01: pwm does not work

Hello,

I have recently updated my BBB to Debian Bullseye XFCE Image 2022-07-01. Serial I/O works but my application nicely running on older images gives errors when addressing pwm pins. My test script:
import Adafruit_BBIO.PWM as pwm
pwm.start(“P8_13”,50)
pwm.start(“P8_19”,60)
pwm.stop(“P8_13”)
pwm.stop(“P8_19”)

Gives the famous: RuntimeError: Unknown error. for line 2
I can run config-pin commands without problem.
Running the Python testscript in sudo or not does not make a difference.
Please advise,
Best regards,
Harke

Adafruit_BBIO has not been ported to v5.10.x-ti…

As long as you load the pwm overlay, you can echo those values into /dev/bone/pwm/*

Regards,

Hello Robert, thanks. I am afraid I am not sure what it means…
Regards,
Harke

Hi @yrrah53 first, there’s one package in 2022-07-01 that needs an update and it’ll be available in next week’s image with 2022-08-01…

Default: 2022-07-01

debian@BeagleBone:~$ tree /dev/bone/
/dev/bone/
├── i2c
│   ├── 0 -> ../../i2c-0
│   ├── 1 -> ../../i2c-1
│   └── 2 -> ../../i2c-2
├── spi
│   ├── 0.0 -> ../../spidev0.0
│   ├── 0.1 -> ../../spidev0.1
│   ├── 1.0 -> ../../spidev1.0
│   └── 1.1 -> ../../spidev1.1
└── uart
    ├── 0 -> ../../ttyS0
    ├── 1 -> ../../ttyS1
    ├── 2 -> ../../ttyS2
    ├── 3 -> ../../ttyS3
    ├── 4 -> ../../ttyS4
    └── 5 -> ../../ttyS5

3 directories, 13 files

First update bb-customizations package and enable it’s service file:

sudo apt update
sudo apt install --only-upgrade bb-customizations
sudo systemctl enable bb-symlinks.service

Then reboot…

sudo reboot

Now you will see the pwm symlinks…

debian@BeagleBone:~$ tree /dev/bone/
/dev/bone/
├── am335x
│   └── ecap
│       ├── 0 -> /sys/class/pwm/pwmchip0/pwm0
│       ├── 1 -> /sys/class/pwm/pwmchip1/pwm0
│       └── 2 -> /sys/class/pwm/pwmchip2/pwm0
├── counter
│   ├── counter0 -> /sys/bus/counter/devices/counter0
│   ├── counter1 -> /sys/bus/counter/devices/counter1
│   └── counter2 -> /sys/bus/counter/devices/counter2
├── i2c
│   ├── 0 -> ../../i2c-0
│   ├── 1 -> ../../i2c-1
│   └── 2 -> ../../i2c-2
├── pwm
│   ├── 0
│   │   ├── a -> /sys/class/pwm/pwmchip3/pwm0/
│   │   └── b -> /sys/class/pwm/pwmchip3/pwm1/
│   ├── 1
│   │   ├── a -> /sys/class/pwm/pwmchip5/pwm0/
│   │   └── b -> /sys/class/pwm/pwmchip5/pwm1/
│   └── 2
│       ├── a -> /sys/class/pwm/pwmchip7/pwm0/
│       └── b -> /sys/class/pwm/pwmchip7/pwm1/
├── spi
│   ├── 0.0 -> ../../spidev0.0
│   ├── 0.1 -> ../../spidev0.1
│   ├── 1.0 -> ../../spidev1.0
│   └── 1.1 -> ../../spidev1.1
└── uart
    ├── 0 -> ../../ttyS0
    ├── 1 -> ../../ttyS1
    ├── 2 -> ../../ttyS2
    ├── 3 -> ../../ttyS3
    ├── 4 -> ../../ttyS4
    └── 5 -> ../../ttyS5

22 directories, 13 files

Next, from: Beagleboard:BeagleBone cape interface spec - eLinux.org we see:

P8_13 -> /dev/bone/pwm/2/b
P8_19 -> /dev/bone/pwm/2/a

Now let’s configure, P8_13 & P8_19 for pwm output:

debian@BeagleBone:~$ config-pin -l P8_13

Available modes for P8_13 are: default gpio gpio_pu gpio_pd gpio_input pwm

debian@BeagleBone:~$ config-pin -l P8_19

Available modes for P8_19 are: default gpio gpio_pu gpio_pd gpio_input pwm
debian@BeagleBone:~$ config-pin P8_13 pwm

Current mode for P8_13 is:     pwm

debian@BeagleBone:~$ config-pin P8_19 pwm

Current mode for P8_19 is:     pwm

Then go under /dev/bone/pwm/2/b and /dev/bone/pwm/2/a and configure your pwm device!

debian@BeagleBone:/dev/bone/pwm/2/b$ tree
.
├── capture
├── duty_cycle
├── enable
├── period
├── polarity
├── power
│   ├── async
│   ├── autosuspend_delay_ms
│   ├── control
│   ├── runtime_active_kids
│   ├── runtime_active_time
│   ├── runtime_enabled
│   ├── runtime_status
│   ├── runtime_suspended_time
│   └── runtime_usage
└── uevent

1 directory, 15 files

at a minimal, you need duty_cycle, period, and enable…

Regards,

1 Like

Thank you Robert, can’t wait to download the next version… It all works like you wrote. But how can I change the value of enable, duty_cycle and period? I am not a programmer, I am a ham using a Beaglebone to control my EME antenna.
my best,
Harke

https://docs.kernel.org/driver-api/pwm.html#using-pwms-with-the-sysfs-interface

When a PWM channel is exported a pwmX directory will be created in the pwmchipN directory it is associated with, where X is the number of the channel that was exported. The following properties will then be available:

period
The total period of the PWM signal (read/write). Value is in nanoseconds and is the sum of the active and inactive time of the PWM.

duty_cycle
The active time of the PWM signal (read/write). Value is in nanoseconds and must be less than the period.

polarity
Changes the polarity of the PWM signal (read/write). Writes to this property only work if the PWM chip supports changing the polarity. The polarity can only be changed if the PWM is not enabled. Value is the string “normal” or “inversed”.

enable
Enable/disable the PWM signal (read/write).

0 - disabled

1 - enabled

On the board, just run:

debian@BeagleBone:/dev/bone/pwm/2/b$ echo 1000 > period 
debian@BeagleBone:/dev/bone/pwm/2/b$ echo 500 > duty_cycle 
debian@BeagleBone:/dev/bone/pwm/2/b$ echo 1 > enable 

as one example…

Regards,