Skip to content

boards/raspberrypi-4b: PWM audio support#19406

Merged
xiaoxiang781216 merged 5 commits into
apache:masterfrom
linguini1:rpi4b-pwm
Jul 12, 2026
Merged

boards/raspberrypi-4b: PWM audio support#19406
xiaoxiang781216 merged 5 commits into
apache:masterfrom
linguini1:rpi4b-pwm

Conversation

@linguini1

Copy link
Copy Markdown
Contributor

Summary

This PR introduces support for PWM-based audio on the Raspberry Pi 4B:

  • PWM driver support for both channels of PWM0 and PWM1 (audio jack PWM)
  • Oneshot timer support for the (4) BCM2711 system timers
  • Device driver registration for PWM and audio tone drivers
  • A configuration with the PWM example to test audio, which is documented

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:

nsh> oneshot                                                                                      
oneshot_ioctl: cmd=5664 arg=004de0a0                                                              
oneshot_ioctl: cmd=5665 arg=004de0b0                                                              
bcm2711_tim_irq_en: Interrupt for timer 0 enabled.                                                
Opening /dev/oneshot0                                                                             
Maximum delay is 18446744073709551615                                                             
Starting oneshot timer with delay 2000000 microseconds                                            
Waiting...                                                                                        
bcm2711_tim_irq_en: Interrupt for timer 0 disabled.                                               
bcm2711_tim_handler: Callback...                                                                  
bcm2711_tim_handler: Callback called for oneshot 0.                                               
Finished                                                    

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:

swappy-20260708_201755

linguini1 added 3 commits July 9, 2026 10:29
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>
@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm64 labels Jul 11, 2026
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Comment thread boards/arm64/bcm2711/raspberrypi-4b/configs/audio_tone/defconfig
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>
@xiaoxiang781216 xiaoxiang781216 merged commit 618119e into apache:master Jul 12, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm64 Issues related to ARM64 (64-bit) architecture Area: Documentation Improvements or additions to documentation Board: arm64 Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] RPi4B audio jack support over PWM [FEATURE] RPi 4B PWM support

4 participants