MX6UL如何修改PWM输出


 

采用lcd电阻触摸一路GPIO1_IO04用作PWM控制,并输出2.4K的方波。

 

CPU默认可输出8路PWM,默认背光采用的为PWM1,增加GPIO1_IO04复用为PWM3。

驱动默认已经加载,驱动路径为drivers/pwm/pwm-imx.c。

 

修改设备树,修改imx6ul.dtsi中

pwm3: pwm@02088000 {

compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";

reg = <0x02088000 0x4000>;

interrupts = <GIC_SPI 85IRQ_TYPE_LEVEL_HIGH>;

clocks = <&clks IMX6UL_CLK_DUMMY>,

<&clks IMX6UL_CLK_DUMMY>;

clock-names = "ipg", "per";

#pwm-cells = <2>;

};


pwm3: pwm@02088000 {

compatible = "fsl,imx6ul-pwm", "fsl,imx27-pwm";

reg = <0x02088000 0x4000>;

interrupts = <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>;

clocks = <&clks IMX6UL_CLK_PWM3>,

<&clks IMX6UL_CLK_PWM3>;

clock-names = "ipg", "per";

#pwm-cells = <2>;

};


在imx6ul-14x14-evk.dts中添加:

&pwm3 {

pinctrl-names = "default";

pinctrl-0 = <&pinctrl_pwm3>;

status = "okay";

};

添加pinctl_pwm3

pinctrl_pwm3: pwm3grp {

fsl,pins = <

MX6UL_PAD_GPIO1_IO04__PWM3_OUT 0x110b0

>;

};

并将GPIO1_IO04其他复用的地方取消或者注释掉。

tsc中status = “disabled”;

编译设备树,替换开发板中设备树,并选择此设备树。

在开发板启动之后,命令行输入:

root@freescale ~$ echo 0 > /sys/class/pwm/pwmchip2/export

root@freescale ~$ echo 1 >/sys/class/pwm/pwmchip2/pwm0/enable

root@freescale ~$ echo 416667 > /sys/class/pwm/pwmchip2/pwm0/period

root@freescale ~$ echo 208333 > /sys/class/pwm/pwmchip2/pwm0/duty_cycle

此时GPIO1_IO04输出2.4K方波。

如果输出1KHz方波,命令如下:

root@freescale ~$echo 1000000 > /sys/class/pwm/pwmchip1/pwm0/period

root@freescale ~$echo 500000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

sitemap