PWM not working at a BBB with Debian Boolseye 11 and Adafruit Blinka library

Hello. I installed Blinka Adafruit librbay, on a Beaglebone Black Rev. C board. The board was flashed with the following official Debian image, am335x-eMMC-flasher-debian-11.7-iot-armhf-2023-09-02-4gb.img.xz.
Fort the moment I have tested the digitalio and the pwmio libraries. The first works fine with the GPIOs. The second is not working. I used the example program from the library examples at Adafruit web page. I replaced the “D4” pin of the original program, with “P9_14”, to activate this pin on BBB.

I got the following error message

tucer@BeagleBone:~/tests/Blinka$ sudo python3 PWM.py
[sudo] password for tucer:
Traceback (most recent call last):
File “/home/tucer/tests/Blinka/PWM.py”, line 5, in
led = pwmio.PWMOut(board.P9_14, frequency=5000, duty_cycle=0)
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py”, line 68, in init
self._open(pin, duty_cycle, frequency, variable_frequency)
File “/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/am335x/sysfs_pwmout.py”, line 88, in _open
raise RuntimeError(“No PWM channel found for this Pin”)
RuntimeError: No PWM channel found for this Pin

I checked this forum and the #240, #200, #201, #168 issues, at the Adafruit Blinka (github) repository and tried to do some debugging from the user space in a terminal but nothing worked!

1 Like

Just for kicks, I am going to try.

What python3 version do you have and where are your PWM channels listed and are they listed as they are listed in the source when called in the adafruit_blinka repo?

I think most python3 versions will work together with minimal effort on debugging but…

If adafruit_blinka calls /sys/class/pwm/pwmchip3/* and on your board is where the peripheral is located and it is in file /dev/bone/pwm/*, then yeppers.

That may entail errors.

A couple steps to debug:

  1. Check /dev/bone/
  2. Are the usable PWM peripherals in /dev/bone/?
  3. If so, can you alter the source of adafruit_blinka and required libs that are attached to handle the exchange in file usage?

So, instead of P9_14, it may be 1 or 2 in /dev/bone/pwm/../*. That is really all I am getting towards for now. I will need to review the source and see where their PWM originates to call it down the line.

Seth

P.S. So, I see on line 88 in sysfs_pwmout.py, there may be some clues. Line 68 too of the same file may show why it is that way in the init of the required file(s). And then, maybe your source could be switched up due to however adafruit_blinka is situated in specified files. hearsay for now. I understand. I had to stop using that lib a while back because I kept having an installation issue during the switch from 2 to 3.

Sorry if this is not quite what you are expecting from community help. Reply at will and I will keep trying to see how far I can get before I have to stop again.

That link shows, board and pwmio as the two main files for importing. I have been out of this game for a while. Give me a break I guess. I will try to update myself here shortly.

I will start with board and pwmio and see how far I get.

Seth

@savvas.piperidis ,

Okay! We got lift off!

Line 32 shows the way /sys/class/pwm/ is called in that class.

The entire class of PWMOut is listed on that page file in sysfs_pwmout.py.

So, it is really rooted in something more. I see an import os in the file and then it basically goes straight to the class PWMOut portion of the source.

Luckily, exchanging out some lines may prove valuable (highly untested) but a good hunch for now. I am not sure what image and the fs your image is using for now. I have a BBB I can test soon. Give me a while and take some time to know the files in blinka and we can discuss it. Right? Right!

Seth

Hello and thanks a lot for the (long) answer. The Python 3.9.2 version is installed at my BeagleBoneBlack. The PWM channels are listed, as expected, at /dev/bone/pwm:

tucer@BeagleBone:~$ ls /dev/bone/pwm/
0  1  2

As you see at the next command everything looks right:

tucer@BeagleBone:~$ ls /dev/bone/pwm/0/a
capture  duty_cycle  enable  period  polarity  power  uevent

At the same time:

tucer@BeagleBone:~$ ls /sys/class/pwm
pwmchip0  pwmchip1  pwmchip2  pwmchip3  pwmchip5  pwmchip7
tucer@BeagleBone:~$ ls /sys/class/pwm/pwmchip0/
device  export  npwm  power  pwm0  subsystem  uevent  unexport

If I try to activate a PWM channel, from the command line, I will not get any error messages, still the channel will remain off.:

tucer@BeagleBone:/dev/bone/pwm$ cd 0
tucer@BeagleBone:/dev/bone/pwm/0$ ls -al
total 0
drwxr-xr-x 2 root root  80 Apr 26 18:43 .
drwxr-xr-x 5 root root 100 Apr 26 18:43 ..
lrwxrwxrwx 1 root root  29 Apr 26 18:43 a -> /sys/class/pwm/pwmchip3/pwm0/
lrwxrwxrwx 1 root root  29 Apr 26 18:43 b -> /sys/class/pwm/pwmchip3/pwm1/

and

tucer@BeagleBone:/dev/bone/pwm/0/a$ ls
capture  duty_cycle  enable  period  polarity  power  uevent
tucer@BeagleBone:/dev/bone/pwm/0/a$ echo 900 > period 
tucer@BeagleBone:/dev/bone/pwm/0/a$ echo 250 > duty_cycle 
tucer@BeagleBone:/dev/bone/pwm/0/a$ echo 1 > enable

… but no PWM signal.

At last, I remind that the BBB board was flashed with the am335x-eMMC-flasher-debian-11.7-iot-armhf-2023-09-02-4gb.img.xz, Debian image, dowloaded from the official Beagleboard repository.

Hmm.

I will need to test. I will on my board and see how far I get. Do you have a uEnv.txt file in the /boot/ file?

If so, maybe uncomment what is not needed, i.e. as some of the PWM signals may be used by the HDMI and wireless peripherals onboard the BBB. I will get back to you later. I have to go and mow some yard. BBL.

$ echo 10000 > period
$ echo 6000 > duty_cycle
$ echo 1 > enable

Setting the PWM frequency to 100 kHz and setting the duty cycle to 60 kHz is what the above shell commands do. Try that instead or try 5000 for the duty cycle depending on whatever you are testing with currently, i.e. motor, DMM, MM, LED, Oscilloscope, etc.

Seth

P.S. There are many tutorials online about how to call in scripting like you have but with an altered state of frequency and Hz. Oh and I am near a BBB and I will test soon and report back!

You are right so far to me. Now, my board does not respect /opt/source/MY_KERNEL-ti/src/arm/ files.

I will keep trying. On to another route of ideas…

Okay. I am on to nothing so far: what does ./show-pins show as output on your board?

here: :/opt/source/bbb-pin-utils$ ./show-pins

For instance: I am using P8_13 which is /dev/bone/pwm/2/b/* on my machine (BBB) from this chart:

# | Pin   | pwm | channel
# | P9_31 | 0   | a
# | P9_29 | 0   | b
# | P9_14 | 1   | a
# | P9_16 | 1   | b
# | P8_19 | 2   | a
# | P8_13 | 2   | b

I got that chart from the docs pages. Anyway, I am also seeing this line on P8_13 via ./show-pins:

P8.13 9 fast rx down 7 gpio 0.23 << lo P8_13 (pinmux_P8_13_default_pin)

Right now, I do not know how to read this idea because gpioinfo states something different.

Keep with it and I will keep trying…

It’s not immediately obvious by your discussion so far, but have you guys put some thought into the state of the PINMUXes?

I am aware of all that.
I replied just for showing the /boot/uEnv.txt file:

At my board:

tucer@BeagleBone:~$ ls -al /opt/source/
total 44
drwxr-xr-x 10 debian debian 4096 Sep  2  2023 .
drwxr-xr-x  9 root   root   4096 Sep  2  2023 ..
drwxr-xr-x 15 debian debian 4096 Sep  2  2023 adafruit-beaglebone-io-python
drwxr-xr-x 11 debian debian 4096 Sep  2  2023 bb.org-overlays
drwxr-xr-x  4 debian debian 4096 Sep  2  2023 bbb-pin-utils
drwxr-xr-x  7 debian debian 4096 Sep  2  2023 dtb-5.10-ti
drwxr-xr-x  6 debian debian 4096 Sep  2  2023 dtb-5.15
-rw-r--r--  1 debian debian  610 Sep  2  2023 list.txt
drwxr-xr-x  7 debian debian 4096 Sep  2  2023 overlay-utils
drwxr-xr-x  8 debian debian 4096 Sep  2  2023 py-uio
drwxr-xr-x  3 debian debian 4096 Sep  2  2023 spidev-test

Also, regarding the pins:

tucer@BeagleBone:/opt/source/bbb-pin-utils$ ./show-pins 
P8.25 / eMMC d0                    0 fast rx  up  1 mmc 1 d0         mmc@481d8000 (pinmux_emmc_pins)
P8.24 / eMMC d1                    1 fast rx  up  1 mmc 1 d1         mmc@481d8000 (pinmux_emmc_pins)
P8.05 / eMMC d2                    2 fast rx  up  1 mmc 1 d2         mmc@481d8000 (pinmux_emmc_pins)
P8.06 / eMMC d3                    3 fast rx  up  1 mmc 1 d3         mmc@481d8000 (pinmux_emmc_pins)
P8.23 / eMMC d4                    4 fast rx  up  1 mmc 1 d4         mmc@481d8000 (pinmux_emmc_pins)
P8.22 / eMMC d5                    5 fast rx  up  1 mmc 1 d5         mmc@481d8000 (pinmux_emmc_pins)
P8.03 / eMMC d6                    6 fast rx  up  1 mmc 1 d6         mmc@481d8000 (pinmux_emmc_pins)
P8.04 / eMMC d7                    7 fast rx  up  1 mmc 1 d7         mmc@481d8000 (pinmux_emmc_pins)
P8.19                              8 fast rx down 7 gpio 0.22 << lo  P8_19 (pinmux_P8_19_default_pin)
P8.13                              9 fast rx down 7 gpio 0.23 << lo  P8_13 (pinmux_P8_13_default_pin)
P8.14                             10 fast rx down 7 gpio 0.26 << lo  P8_14 (pinmux_P8_14_default_pin)
P8.17                             11 fast rx down 7 gpio 0.27 << lo  P8_17 (pinmux_P8_17_default_pin)
P8.12                             12 fast rx down 7 gpio 1.12 << lo  P8_12 (pinmux_P8_12_default_pin)
P8.11                             13 fast rx down 7 gpio 1.13 << lo  P8_11 (pinmux_P8_11_default_pin)
P8.16                             14 fast rx down 7 gpio 1.14 << lo  P8_16 (pinmux_P8_16_default_pin)
P8.15                             15 fast rx down 7 gpio 1.15 << lo  P8_15 (pinmux_P8_15_default_pin)
P9.15                             16 fast rx down 7 gpio 1.16 << hi  P9_15 (pinmux_P9_15_default_pin)
P9.23                             17 fast rx down 7 gpio 1.17 << lo  P9_23 (pinmux_P9_23_default_pin)
P9.14                             18 fast rx down 7 gpio 1.18 << lo  P9_14 (pinmux_P9_14_default_pin)
P9.16                             19 fast rx down 7 gpio 1.19 << lo  P9_16 (pinmux_P9_16_default_pin)
P9.11                             28 fast rx  up  7 gpio 0.30 << hi  P9_11 (pinmux_P9_11_default_pin)
P9.13                             29 fast rx  up  7 gpio 0.31 << hi  P9_13 (pinmux_P9_13_default_pin)
P9.12                             30 fast rx  up  7 gpio 1.28 << hi  P9_12 (pinmux_P9_12_default_pin)
P8.26                             31 fast rx  up  7 gpio 1.29 << hi  P8_26 (pinmux_P8_26_default_pin)
P8.21 / eMMC clk                  32 fast rx  up  2 mmc 1 clk        mmc@481d8000 (pinmux_emmc_pins)
P8.20 / eMMC cmd                  33 fast rx  up  2 mmc 1 cmd        mmc@481d8000 (pinmux_emmc_pins)
P9.15                             34 fast rx  up  7 gpio 2.00       
P8.18                             35 fast rx down 7 gpio 2.01 << lo  P8_18 (pinmux_P8_18_default_pin)
P8.07                             36 fast rx  up  7 gpio 2.02 << hi  P8_07 (pinmux_P8_07_default_pin)
P8.08                             37 fast rx  up  7 gpio 2.03 << hi  P8_08 (pinmux_P8_08_default_pin)
P8.10                             38 fast rx  up  7 gpio 2.04 << hi  P8_10 (pinmux_P8_10_default_pin)
P8.09                             39 fast rx  up  7 gpio 2.05 << hi  P8_09 (pinmux_P8_09_default_pin)
P8.45 / hdmi / sysboot 0          40 fast rx down 7 gpio 2.06 << lo  P8_45 (pinmux_P8_45_default_pin)
P8.46 / hdmi / sysboot 1          41 fast rx down 7 gpio 2.07 << lo  P8_46 (pinmux_P8_46_default_pin)
P8.43 / hdmi / sysboot 2          42 fast rx down 7 gpio 2.08 << lo  P8_43 (pinmux_P8_43_default_pin)
P8.44 / hdmi / sysboot 3          43 fast rx down 7 gpio 2.09 << lo  P8_44 (pinmux_P8_44_default_pin)
P8.41 / hdmi / sysboot 4          44 fast rx down 7 gpio 2.10 << lo  P8_41 (pinmux_P8_41_default_pin)
P8.42 / hdmi / sysboot 5          45 fast rx down 7 gpio 2.11 << lo  P8_42 (pinmux_P8_42_default_pin)
P8.39 / hdmi / sysboot 6          46 fast rx down 7 gpio 2.12 << lo  P8_39 (pinmux_P8_39_default_pin)
P8.40 / hdmi / sysboot 7          47 fast rx down 7 gpio 2.13 << lo  P8_40 (pinmux_P8_40_default_pin)
P8.37 / hdmi / sysboot 8          48 fast rx down 7 gpio 2.14 << lo  P8_37 (pinmux_P8_37_default_pin)
P8.38 / hdmi / sysboot 9          49 fast rx down 7 gpio 2.15 << lo  P8_38 (pinmux_P8_38_default_pin)
P8.36 / hdmi / sysboot 10         50 fast rx down 7 gpio 2.16 << lo  P8_36 (pinmux_P8_36_default_pin)
P8.34 / hdmi / sysboot 11         51 fast rx down 7 gpio 2.17 << lo  P8_34 (pinmux_P8_34_default_pin)
P8.35 / hdmi / sysboot 12         52 fast rx down 7 gpio 0.08 << lo  P8_35 (pinmux_P8_35_default_pin)
P8.33 / hdmi / sysboot 13         53 fast rx down 7 gpio 0.09 << lo  P8_33 (pinmux_P8_33_default_pin)
P8.31 / hdmi / sysboot 14         54 fast rx down 7 gpio 0.10 << lo  P8_31 (pinmux_P8_31_default_pin)
P8.32 / hdmi / sysboot 15         55 fast rx down 7 gpio 0.11 << lo  P8_32 (pinmux_P8_32_default_pin)
P8.27 / hdmi                      56 fast rx down 7 gpio 2.22 << lo  P8_27 (pinmux_P8_27_default_pin)
P8.29 / hdmi                      57 fast rx down 7 gpio 2.23 << lo  P8_29 (pinmux_P8_29_default_pin)
P8.28 / hdmi                      58 fast rx down 7 gpio 2.24 << lo  P8_28 (pinmux_P8_28_default_pin)
P8.30 / hdmi                      59 fast rx down 7 gpio 2.25 << lo  P8_30 (pinmux_P8_30_default_pin)
P9.22 / spi boot clk              84 fast rx  up  7 gpio 0.02 << hi  P9_22 (pinmux_P9_22_default_pin)
P9.21 / spi boot in               85 fast rx  up  7 gpio 0.03 << hi  P9_21 (pinmux_P9_21_default_pin)
P9.18 / spi boot out              86 fast rx  up  7 gpio 0.04 << hi  P9_18 (pinmux_P9_18_default_pin)
P9.17 / spi boot cs               87 fast rx  up  7 gpio 0.05 << hi  P9_17 (pinmux_P9_17_default_pin)
P9.42                             89 fast rx down 7 gpio 0.07 << lo  P9_42 (pinmux_P9_42_default_pin)
P9.20 / cape i²c sda              94 fast rx  up  3 i²c 2 sda        ocp/P9_20_pinmux (pinmux_P9_20_default_pin)
P9.19 / cape i²c scl              95 fast rx  up  3 i²c 2 scl        ocp/P9_19_pinmux (pinmux_P9_19_default_pin)
P9.26                             96 fast rx  up  7 gpio 0.14 << hi  P9_26 (pinmux_P9_26_default_pin)
P9.24                             97 fast rx  up  7 gpio 0.15 << hi  P9_24 (pinmux_P9_24_default_pin)
P9.31 / hdmi audio clk           100 fast rx down 7 gpio 3.14 << lo  P9_31 (pinmux_P9_31_default_pin)
P9.29 / hdmi audio fs            101 fast rx down 7 gpio 3.15 << lo  P9_29 (pinmux_P9_29_default_pin)
P9.30                            102 fast rx down 7 gpio 3.16 << lo  P9_30 (pinmux_P9_30_default_pin)
P9.28 / hdmi audio data          103 fast rx down 7 gpio 3.17 << lo  P9_28 (pinmux_P9_28_default_pin)
P9.42                            104 fast rx down 7 gpio 3.18 << lo  P9_92 (pinmux_P9_92_default_pin)
P9.27                            105 fast rx down 7 gpio 3.19 << lo  P9_27 (pinmux_P9_27_default_pin)
P9.41                            106 fast rx down 7 gpio 3.20 << lo  P9_91 (pinmux_P9_91_default_pin)
P9.25 / audio osc                107 fast rx down 7 gpio 3.21 << lo  P9_25 (pinmux_P9_25_default_pin)
P9.41 / jtag emu3                109 fast rx down 7 gpio 0.20 << lo  P9_41 (pinmux_P9_41_default_pin)

As you can see above, the PWM pins like P9_14, P9_16, P8_13, P8_19 are “down”. Some other PWM pins, like P9_29 and P9_31 according to the list are used for hdmi audio and are also “down”, It is strange because I have disabled the video, audio and wireless overlays, as you can see at the attached /boot/uEnv.txt file.
uEnv.txt (1.7 KB)

I am sorry. I was away today. I am not sure so far as to what to do. Before I checked for you, they were working fine. Now, not so much. Like @lranders stated, we may need to set up overlay(s) for a pinmux for the PWM definitions.

Right now, I am just not sure. Excuse me…

Hello again. I do not know if this will help, but when I tried the following program for UART communication, I also got an error. Here is the program code:

import board
import busio
uart = busio.UART(board.P9_24, board.P9_26, baudrate=9600, timeout=10)

and here is the result:

Traceback (most recent call last):
  File "/home/tucer/tests/Blinka/UART.py", line 19, in <module>
    uart = busio.UART(board.P9_24, board.P9_26, baudrate=9600, timeout=10)
  File "/usr/local/lib/python3.9/dist-packages/busio.py", line 504, in __init__
    raise RuntimeError(
RuntimeError: busio.UART not supported on this platform. Please use pyserial instead.

Hope this helps.

Okay…

So, the .py file for the BBB is located at the first link. busio.py is for circuitpython and/or micropython.

sudo apt install python3-serial will get you the Debian version of serial libraries that they made available. python3 -m pip install pyserial will get the install of pip3 for pyserial.

If you are NOT using a venv, I suggest you do if you are using the pip3 versioning.

Although my logical explanations are trivial now, since I do not know the answer now, I think using pyserial will benefit you in using UART on the BBB…

On the BBB, from what I remember, there was some work being done to handle /dev/bone/uart/ files just like with /dev/bone/pwm/ but now…

  1. Since pwm is not working on the BBB, I am not sure uart will work either
  2. It may be helpful to learn about the DTS at /opt/source/dtb-5.10-ti/src/arm/overlays/
  3. From what I remember, git pull to get the latest-greatest or leave it as is…

I may have some time soon. Although this is a history lesson and no so much on viable, current workings, I may soon be out of answers.

So, there is something called nvmem that will need further investigation which can be found here:

https://www.kernel.org/doc/html/v5.6/driver-api/nvmem.html

Also, Adafruit_BBIO needs an install on the system which, from what I remember, is not being developed or kept up-to-date. I am sorry…

Seth

P.S. I will try a bit but I am afraid without specifics on installs that are up-to-date and readily available, this library might never work as is…