Search code examples
raspberry-pigpiopwm

Looking for library supporting hardware PWM on RPi3 (not using sysfs)


I wrote years ago a short c program for a Raspberry Pi (RPi3) using the pigpio library to send an infrared signal to a heating system. Still in use. The carrier frequency is 450 kHz, i.e., pretty fast for a RPi. Thus, I use hardware PWM and only need to switch PWM off and on (i.e., duty cycle 0% and 50%, respectively).

Since the latest RPiOS ("Raspbian") update, this no longer works; likely because the pigpio library uses the obsolete sysfs interface. I can confirm on the commandline that sysfs is no longer supported (while the same command works on another, not yet upgraded RPi):

~# uname --kernel-name --kernel-release --kernel-version
Linux 6.6.31+rpt-rpi-v7 #1 SMP Raspbian 1:6.6.31-1+rpt1 (2024-05-29)
~# echo 23 > /sys/class/gpio/export
-bash: echo: write error: Invalid argument

To my question: is there a library that supports hardware PWM and uses the character device interface? pigpio and RPi.GPIO (for Python) seem to use sysfs. libgpiod and wiringPi use the character device interface but I found no support for hardware PWM. Library bcm2835 only supports RPi1 and RPi2.


Solution

  • Short answer - No.

    The GPIO character device interface is strictly that - GPIO. PWM is a different kernel subsystem and has a totally separate interface.

    While the GPIO sysfs interface has been deprecated in favour of the character device interface, for PWM you still use the PWM sysfs interface.

    There is talk of adding a PWM character device/ioctl interface, but that has not even hit the mainline kernel yet (as of Linux 6.10), much less the Raspberry Pi branch, so you wont find a PWM character device/ioctl interface in current kernels.