Rpi4 hardware pwm dtoverlay need kernel module?

Hi all!

Really loving the Nerves system :slight_smile: I am trying to get hardware PWM working on Nerves on a RPI4. I had this working on Raspbian before. For Nerves, I was able to customize things to get the dtoverlay added in /boot/config.txt and having the pwm.dtbo file copied into /boot/overlays as well - these by using the custom fwup.conf etc.

But after this I still don’t have a /sys/class/pwm present in my sysfs.

I tried adding dtdebug=1 to config.txt too, but that didn’t give me more info in dmesg.

So I am now thinking that I’m missing the appropriate kernel module, thinking I need to have the pwm-bcm2835.ko which is not present in kernel/drivers.

I also checked the linux-4.19.defconfig and nerves_defconfig in the nerves_system_rpi4 repo and could not find any mention of CONFIG_PWM_BCM2835.

Does this mean I will have to clone the nerves_system_rpi4 repo, make my own changes and have the kernel recompiled in order to get this kernel module ?

Did someone else try to make this work earlier ?

Hoping to get some more info before I go down this rabbithole only to find out there’s an easier way :slight_smile:



Hi Leon,

The current answer for adding that option is yes, you’ll need to clone nerves_system_rpi4 and make a custom system. We’re aware that this is a lot of work for making a one line kernel configuration change.

Having said that, I think that it’s an oversight that the hardware PWM kernel module isn’t being built in the official RPi4 Nerves system. While our systems aim to be minimal, for the Raspberry Pi ones, we have been trying to error on the side of including the basics for attaching hardware devices. If you would like to send a PR to the repository that enables it, that would be appreciated.

There’s also some history on PWM support on the Raspberry Pi. Since the Pi has so few hardware PWM pins, most people (myself included) had either used an I2C->PWM module or used pigpio's DMA controller-based PWM support. pigpio is included in the default Nerves systems for Raspberry Pi specifically for PWM support. If you go the I2C->PWM module route, there are quite a few options. Pololu, Adafruit, and Sparkfun all have modules for them and sometimes have servo connectors if that’s why you’re interested in PWM.

Hope this helps!

1 Like

Hi Frank,

Thanks for your response. I now have a custom nerves_system_rpi4 built and am currently experimenting with it. I cannot go the i2c route and have to use the hardware pwm as this is targeted to work with an existing daughterboard on the rpi4. I’ll create a PR for the nerves_system_rpi4 as soon as it works.

I never heard of the pigpio dma solution, right now I’m getting a 10khz frequency (from what I remember) on the hardware pwm pin 18 (gpio 12) which is working nice for led dimming. I’ll experiment with pigpio later too, thanks for the tip.