How to Enable and Control PWM on Libre Computer ROC-RK3328-CC

ROC-RK3328-CC Renegade has one available hardware PWM on pin 12 called pwm2.

The Linux kernel interface can be accessed via sysfs.

sudo ldto enable pwm2
ls -al /sys/class/pwm # see the pwmchip{n} to hardware mapping
echo {0,1} | sudo tee /sys/class/pwm/pwmchip{n}/export
echo 1000000 | sudo tee /sys/class/pwm/pwmchip{n}/pwm{n}/period
echo 500000 | sudo tee /sys/class/pwm/pwmchip{n}/pwm{n}/duty_cycle
echo 1 | sudo tee /sys/class/pwm/pwmchip{n}/pwm{n}/enable