Linux's Kernel-Level Software PWM Support Arrives on the Raspberry Pi's GPIO Pins

Backported from Linux 6.11 the kernel-level PWM diver "blows most userspace libraries out of the water," says Philip Howard.

Gareth Halfacree
28 days ago β€’ HW101

Raspberry Pi users working with pulse-width modulation (PWM) signals on the popular boards' general-purpose input/output (GPIO) pins can now benefit from a new driver based on a high-resolution timer β€” unlocking the functionality on any pin.

"Add a software PWM which toggles a GPIO from a high-resolution timer," developer Vincent Whitchurch writes of the feature, which is included in the Linux 6.11 kernel. "This will naturally not be as accurate or as efficient as a hardware PWM, but it is useful in some cases. I have for example used it for evaluating LED brightness handling (via leds-pwm) on a board where the LED was just hooked up to a GPIO, and for a simple verification of the timer frequency on another platform."

The ability to have high-quality software PWM on any GPIO pin will be welcomed by Raspberry Pi users, with one caveat: Raspberry Pi does not yet provided a kernel based on Linux 6.11. Thankfully, a pull request to merge the feature into the rpi-6.6.y kernel branch has been accepted β€” and the feature should be available through rpi-update by the time you read this article.

"It worked OK on a [Raspberry] Pi 5 with an MG946 servo and seemed solid under normal loads," writes Raspberry Pi's principal software engineer Tim Gover of his testing. "Maxing out the PCIe [PCI Express] link can cause a very small but observable wobble on the servo."

"After many months of gentle nudging and poking it seems like Linux GPIO PWM is finally making it to [Raspberry] Pi," developer Philip Howard adds in a comment on Mastodon. "That's PWM on arbitrary GPIO pins using a kernel level software driver β€” blows most userspace libraries out of the water."

More information is available in the pull request on the Raspberry Pi Linux GitHub repository.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles