boards/raspberrypi-4b: PWM audio support#19406
Merged
Merged
Conversation
Implements the BCM2711 PWM driver. Works for PWM0 and PWM1. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
This commit implements a count-based oneshot timer driver for the BCM2711 system timers. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Brings up PWM interfaces for the RPi4B when enabled. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
acassis
requested changes
Jul 11, 2026
This configuration has PWM audio output over the audio jack and built-in examples to play with it. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
Documents the configuration which allows PWM audio. Signed-off-by: Matteo Golin <matteo.golin@gmail.com>
simbit18
approved these changes
Jul 11, 2026
acassis
approved these changes
Jul 12, 2026
xiaoxiang781216
approved these changes
Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces support for PWM-based audio on the Raspberry Pi 4B:
The PWM audio isn't the best sounding because it is PWM. There have been suggestions on how to improve NuttX's audio support to allow translating PCM audio to PWM with DMA, but for now that is beyond the scope of these improvements.
Impact
Closes #16950.
Closes #19374.
Part of my GSoC milestones, completing the audio jack support milestone.
Really hurts your ears if you wear earbuds to test; I recommend a device with its own analog volume control knob, and cautiously testing the volume of the sound before committing to wearing earbuds/headphones. I put this warning in the docs, but this is a warning to reviewers too!
Testing
Built the PWM audio configuration that is included in this PR and verified on the device that audio comes through the headphone jack. To my (not perfectly trained ears), the audio frequencies I set for a few notes (i.e. middle C) have sound which matches what my desktop computer played for a recording of middle C I found online.
I also registered the one-shot driver as a character driver and performed the one-shot test, which passed:
And finally, I checked the PWM0 interface output using my logic analyzer and both the frequency and duty cycle settings seem to work perfectly fine: