the adafruit guide for pwm-audio on the pi-zero ( https://learn.adafruit.com/adding-basic-audio-ouput-to-raspberry-pi-zero/pi-zero-pwm-audio ) 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:
/dts-v1/;
/plugin/;
/ {
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:dtoverlay=pwm-audio-pi-zero
helpful links:
http://elinux.org/RPi_BCM2835_GPIOs - pins and alt functions for the pi-zeros cpu
https://learn.adafruit.com/introducing-the-raspberry-pi-zero/audio-outputs - the other adafruit guide, touching opi-zero pwm audio
https://www.raspberrypi.org/documentation/configuration/pin-configuration.md
https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt - documentation on the gpio pinconfig via dtoverlay
https://github.com/fivdi/onoff/wiki/Enabling-Pullup-and-Pulldown-Resistors-on-The-Raspberry-Pi - good example of gpio config via dt-overlay
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
so, does this work if I try using another pins as PWM and filtering the output myself?
Are you sure? yes | no
Do you add this to the bottom of boot config txt
Are you sure? yes | no
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