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

JohSchneider 04/02/2016 at 11:032 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


Alex Gonzalez wrote 5 days ago 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