准备驱动电机,前面在YU6LL上用IO模拟的,会出现波形失真的现象,这次准备用硬件pwm进行调试。前面偿试了好多次没有成功,这次在飞凌王老师的指点下,成功开启了。这里记录一下。
修改设备树
从原理图上看出开发板引出了几路pwm。能方便做排针引线的pwm14、pwm3。这两组分别是给两个显示做背光调试的。
修改文件:OK3568-linux-source/kernel/arch/arm64/boot/dts/rockchip/OK3568-C-common.dtsi
注释掉pwms =<&pwm14 0 2000 0>这一行。
在OK3568-C-soure下单独编译kernel
./build.sh kernel
在kernel目录下生成boot.img。把boot.img拷到win上面,打开烧写工具,进行烧写模式,增加一项烧写:
手工驱动PWM
下载后重启成功,用cat /sys/kernel/debug/pwm/察看到pwm设备情况:
[root@ok3568:/]# cat /sys/kernel/debug/pwm
platform/fe700020.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
platform/fe6e0010.pwm, 1 PWM device
pwm-0 (dsi1-backlight ): requested period: 20000 ns duty: 0 ns polarity: normal
platform/fdd70030.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
根据手册的提示pwm14为pwmchip2,进入/sys/class/pwm/pwmchip2
echo 0 > export
然后进入pwm0目录,逐步进行频率、占空比、使能、查看pwm信息等操作,具体如下:
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2]
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
period
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
pwm-0 (sysfs ): requested period: 10000 ns duty: 0 ns polarity: inverse
platform/fe6e0010.pwm, 1 PWM device
pwm-0 (dsi1-backlight ): requested period: 20000 ns duty: 0 ns polarity: normal
platform/fdd70030.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
duty_cycle
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
pwm-0 (sysfs ): requested period: 10000 ns duty: 5000 ns polarity: inverse
platform/fe6e0010.pwm, 1 PWM device
pwm-0 (dsi1-backlight ): requested period: 20000 ns duty: 0 ns polarity: normal
platform/fdd70030.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
> polarity
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
pwm-0 (sysfs ): requested period: 10000 ns duty: 5000 ns polarity: normal
platform/fe6e0010.pwm, 1 PWM device
pwm-0 (dsi1-backlight ): requested period: 20000 ns duty: 0 ns polarity: normal
platform/fdd70030.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
ble
[root@ok3568:/sys/devices/platform/fe700020.pwm/pwm/pwmchip2/pwm0]
nel/debug/pwm
platform/fe700020.pwm, 1 PWM device
pwm-0 (sysfs ): requested enabled period: 10000 ns duty: 5000 ns polarity: normal
platform/fe6e0010.pwm, 1 PWM device
pwm-0 (dsi1-backlight ): requested period: 20000 ns duty: 0 ns polarity: normal
platform/fdd70030.pwm, 1 PWM device
pwm-0 ((null) ): period: 0 ns duty: 0 ns polarity: inverse
到此看到pwm14已经配置好100KHZ占空比为50%的信号输出。用万用表量了一下,电压为1.66V,用示波器测量也是正确的
至此,已经成功驱动pwm。
这次再次感谢飞凌的技术指导,非常专业的公司!