PWM
RK3588(S) provides multiple hardware PWM channels. Which channels are routed to the 40-pin header, and on which pins, is board-specific — see your board's pinout and interface page under Boards. Typical uses: servo motors, backlight dimming, buzzer and fan speed control. Enabling PWM consumes the GPIO on the same pin.
Enabling a channel
PWM channels are off by default. Enable the matching pwm node in the board
DTS (select the pin muxing via pinctrl-0 and declare the channel count),
rebuild the kernel with ./build.sh kernel, flash the new boot.img and
reboot. Channels already used by an onboard function (fan curve, panel
backlight) must not be re-claimed; the board page
lists which channels are free.
Using PWM
When a channel is enabled by the device tree it appears under
/sys/class/pwm/. Values are in nanoseconds:
ls /sys/class/pwm/ # pwmchipN entries
cat /sys/class/pwm/pwmchip2/npwm # how many channels this chip has
echo 0 > /sys/class/pwm/pwmchip2/export
ls /sys/class/pwm/pwmchip2/pwm0/
Configure and start the output:
echo 20000 > /sys/class/pwm/pwmchip2/pwm0/period # 20 ms frame (50 Hz)
echo 1500 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle # 1.5 ms pulse
echo normal > /sys/class/pwm/pwmchip2/pwm0/polarity
echo 1 > /sys/class/pwm/pwmchip2/pwm0/enable
Rules that trip people up:
duty_cyclemust be smaller thanperiod, otherwise the write fails withEINVAL. Writeperiodfirst.- A channel cannot be disabled while
duty_cycleequalsperiod; lower it first, then write0toenable. - Chip and channel numbers depend on the device tree configuration. Confirm with
ls -l /sys/class/pwm/andcat .../npwminstead of assumingpwmchip0.
Servo and backlight examples
| Target | Period | Duty cycle |
|---|---|---|
| Hobby servo (SG90) | 20 ms | 0.5 ms (0°) … 2.5 ms (180°) |
| LED dimming | 1 ms | 0 % … 100 % of period |
| PC fan (4-wire) | 25 kHz | 20 % … 100 % (below 20 % many fans stall) |
| Passive buzzer | 1 / frequency | 50 % for the loudest tone |
For a buzzer, the period sets the tone: 1 kHz → period = 1000000 ns.