Pi Zero PWM Audio - device tree overlay

A project log for PiBoy-Zero

yet another portable console! ;-) roughly the size of a gameboy micro, with a 2.2" display

JohSchneiderJohSchneider 04/02/2016 at 11:033 Comments

the adafruit guide for pwm-audio on the pi-zero ( ) configures the gpio-alt functions on the fly to remap the audio-pwm pins from hidden ones to pins on the gpio-pinheader
after reading up on

device tree configurations and tracking down all necessary pieces, i got this this code snippet/overlay to do the same at boot-time:


/ {
  compatible = "brcm,bcm2708";

  fragment@0 {
    target = <&gpio>;
    __overlay__ {
      pinctrl-names = "default";
      pinctrl-0 = <&pwm_audio_pins>;

    pwm_audio_pins: pwm_audio_pins {
	brcm,pins = <13 18>;   /* gpio no ('BCM' number) */
	brcm,function = <4 2>; /* 0:in, 1:out, 2: alt5, 3: alt4, 4: alt0, 5: alt1, 6: alt2, 7: alt3 */
	brcm,pull = <0 0>;     /* 2:up 1:down 0:none */

this maps the left channel to pin 33 (BCM=13) and the right channel to pin 12 (BCM=18)

compiled with:

dtc -@ -I dts -O dtb -o pwm-audio-pi-zero-overlay.dtb pwm-audio-pi-zero-overlay.dts
and enabled by appending this line to the /boot/config.txt:

helpful links: - pins and alt functions for the pi-zeros cpu - the other adafruit guide, touching opi-zero pwm audio - general documentation on devicetrees on raspberry,bcm2835-gpio.txt - documentation on the gpio pinconfig via dtoverlay - good example of gpio config via dt-overlay


Louise wrote 03/08/2018 at 22:32 point

so, does this work if I try using another pins as PWM and filtering the output myself?

  Are you sure? yes | no

Alex Gonzalez wrote 10/17/2017 at 22:31 point

Do you add this to the bottom of boot config txt

  Are you sure? yes | no

Andy wrote 01/11/2017 at 20:41 point

This helped! It didn't quite work to set the alt modes, but I was able to do so from a service file after applying this.  Thanks!

  Are you sure? yes | no