Skip to content

Instantly share code, notes, and snippets.

@oliora
Last active February 28, 2026 08:57
Show Gist options
  • Select an option

  • Save oliora/81139a236395d616b4838965fed9da13 to your computer and use it in GitHub Desktop.

Select an option

Save oliora/81139a236395d616b4838965fed9da13 to your computer and use it in GitHub Desktop.
RaspberryPi 5 DeviceTree Overlays for 4 channel PWM0 (choose one of the two available GPIO pin mappings for PWM)
// SPDX-License-Identifier: GPL-2.0-only
// This file is released under the GPL v2.0 License, and comes without warranty, express or implied.
// (C) Andrey Upadyshev, 2026
/*
This overlay activates four PWM0 channels of RaspberryPi 5 on the following GPIO pins:
GPIO 12: PWM0_CHAN0 (Alt0)
GPIO 13: PWM0_CHAN1 (Alt0)
GPIO 18: PWM0_CHAN2 (Alt3)
GPIO 19: PWM0_CHAN3 (Alt3)
Alternatively use:
- `pwm-4chan-pi5` overlay to activate 4 PWM0 channels on pins 12, 13, 14 and 15
- `pwm-2chan` and `pwm` overlays to activate 2 and 1 PWM channels accordingly
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2712";
fragment@0 {
target = <&gpio>;
__overlay__ {
pwm_pins: pwm_pins {
function = "pwm0";
pins = "gpio12", "gpio13", "gpio18", "gpio19";
};
};
};
fragment@1 {
target = <&rp1_pwm0>;
frag1: __overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&pwm_pins>;
status = "okay";
};
};
};
// SPDX-License-Identifier: GPL-2.0-only
// This file is released under the GPL v2.0 License, and comes without warranty, express or implied.
// (C) Andrey Upadyshev, 2026
/*
This overlay activates four PWM0 channels of RaspberryPi 5 on the following GPIO pins:
GPIO 12: PWM0_CHAN0 (Alt0)
GPIO 13: PWM0_CHAN1 (Alt0)
GPIO 14: PWM0_CHAN2 (Alt0)
GPIO 15: PWM0_CHAN3 (Alt0)
Alternatively use:
- `pwm-4chan-alt-pi5` overlay to activate 4 PWM0 channels on pins 12, 13, 18 and 19
- `pwm-2chan` and `pwm` overlays to activate 2 and 1 PWM channels accordingly
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2712";
fragment@0 {
target = <&gpio>;
__overlay__ {
pwm_pins: pwm_pins {
function = "pwm0";
pins = "gpio12", "gpio13", "gpio14", "gpio15";
};
};
};
fragment@1 {
target = <&rp1_pwm0>;
frag1: __overlay__ {
pinctrl-names = "default";
pinctrl-0 = <&pwm_pins>;
status = "okay";
};
};
};
@oliora
Copy link
Author

oliora commented Feb 23, 2026

Before using, compile the above overlay source files and copy the result DTBOs to the overlays directory (/boot/overlays by default):

dtc -@ -I dts -O dtb -o pwm-4chan-pi5.dtbo pwm-4chan-pi5.dts && \
dtc -@ -I dts -O dtb -o pwm-4chan-alt-pi5.dtbo pwm-4chan-alt-pi5.dts && \
sudo cp pwm-4chan-pi5.dtbo pwm-4chan-alt-pi5.dtbo /boot/overlays/

Enable either by adding dtoverlay=pwm-4chan-pi5 line to /boot/firmware/config.txt (preferably under [pi5] section) or dynamic via sudo dtoverlay pwm-4chan-pi5 command.

Note that you cannot remove PWM overlays dynamically via dtoverlay -r. The removal causes a kernel segfault which requires a reboot to fix the system. This may be fixed in newer version of the kernel/PWM driver

Note that only one PWM overlay can be activated at the same time time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment