PWM Gpio
1) Make image :
First, you need to use kernel 2.6.37.6, because it supports pwm class.
Edit file target/linux/rdc/Makefile and change :
LINUX_VERSION:=2.6.32.20
by :
LINUX_VERSION:=2.6.37.6
In kernel_menuconfig, add PWM support :
Device Drivers --->
<*> PWM Support --->
<*> PWM emulation using GPIO
In menuconfig, add package :
Kernel modules --->
Other modules --->
<*> kmod-pwm-gpio-custom
2) How to use PWM :
Load module on desired gpio (here we use gpio 12) :
# insmod pwm-gpio-custom bus0=0,12
Init @tick_hz at 1000000000UL (hardcoded) :
# cat /sys/class/pwm/gpio_pwm.0\:0/request
Define 100hz period :
# echo 10000000 > /sys/class/pwm/gpio_pwm.0\:0/period_ns
Define percent when gpio goes polarity for one tick :
Base polarity is 0, so here 10% of tick is 0v, 90% is +3.3v.
If you set polarity to 1, gpio goes 10% to 3.3v, and 90% to 0v.
# echo 1000000 > /sys/class/pwm/gpio_pwm.0\:0/duty_ns
Start pwm :
# echo 1 > /sys/class/pwm/gpio_pwm.0\:0/run
Stop pwm :
# echo 0 > /sys/class/pwm/gpio_pwm.0\:0/run
You can change value without relaunch pwm.
With polarity at 0 :
With polarity at 1 :