7.8.3. 调试指南¶
7.8.3.1. 调试开关¶
在luban根目录下执行 make kernel-menuconfig,进入kernel的功能配置,可以打开PWM模块的DEBUG选项:
Linux
Kernel hacking
Artinchip Debug
[*] PWM driver debug
此DEBUG选项打开的影响:
PWM 驱动以-O0编译
PWM 的pr_dbg()和dev_dbg()调试信息会被编译
在系统运行时,如果要打印pr_dbg()和dev_dbg()信息,还需要调整loglevel为8,两个方法:
在board.dts中修改bootargs,增加“loglevel=8”
在板子启动到Linux shell后,执行命令:
echo 8 > /proc/sys/kernel/printk
7.8.3.2. Sysfs 节点¶
7.8.3.2.1. 状态信息¶
在 PWM/EPWM 驱动初始化成功后,会在Sysfs中注册生成一个 status
节点,其中打印了当前的 PWM/EPWM 配置及状态信息:
pwm status 节点查看:
# cat /sys/devices/platform/soc/19240000.pwm/status
In PWM V1.00:
Module Enable: 1, IRQ Enable: 0x0
Ch En Mode Tb-clk-rate Def CBD CBU CAD CAU PRD ZRO
0 0 Up 0 0 - - - - - -
- - - - - -
1 0 Up 0 0 - - - - - -
- - - - - -
2 1 Up 24000000 0 - - - Hgh Low -
- - - Low Hgh -
3 0 Up 0 0 - - - - - -
- - - - - -
epwm status 节点查看:
# cat /sys/devices/platform/soc/18200000.epwm/status
Ch Mode Tb-clk-rate Def CBD CBU CAD CAU PRD ZRO
0 Up 24000000 1 - - - Hgh - Low
- Hgh - - - Low
1 Up 24000000 1 - - - Hgh - Low
- Hgh - - - Low
2 Up 24000000 1 - - - Hgh - Low
- Hgh - - - Low
3 Up 0 0 - - - - - -
- - - - - -
4 Up 0 0 - - - - - -
- - - - - -
5 Up 0 0 - - - - - -
- - - - - -
7.8.3.2.2. 设置背光¶
Linux Backlight子系统提供一些 Sysfs 节点,可用来获取、设置当前背光:
# cd /sys/class/backlight/backlight/
# ls /sys/class/backlight/backlight/
actual_brightness device/ subsystem/
bl_power max_brightness type
brightness scale uevent
# cat max_brightness
10
# cat brightness
8
# echo 9 > brightness
[ 146.913635] backlight: set brightness to 9
[ 154.054433] aic-pwm 19240000.pwm: ch0 duty 900000 period 1000000
# echo 10 > brightness
[ 192.145595] backlight: set brightness to 10
[ 192.151118] aic-pwm 19240000.pwm: ch0 duty 1000000 period 1000000
# echo 9 > brightness
[ 194.681923] backlight: set brightness to 9
[ 194.687264] aic-pwm 19240000.pwm: ch0 duty 900000 period 1000000
# echo 8 > brightness
[ 197.748816] backlight: set brightness to 8
[ 197.753606] aic-pwm 19240000.pwm: ch0 duty 800000 period 1000000
# echo 7 > brightness
7.8.3.2.3. 动态配置 PWM 通道¶
通常情况下,修改PWM通道的配置,方法是:
修改board.dts中的PWM通道参数;
编译uboot、镜像;
重启板子,下载最新镜像;
然后用示波器查看该PWM通道的信号输出是否符合预期。
为了提供调试的效率,PWM/EPWM 驱动设计了一个 config
节点,可实现 运行时动态修改任意 PWM/EPWM 通道的任意参数 ,并且立即生效,一步shell中的 echo
操作可实现上述1、2、3步骤的效果。如下:
pwm config 节点操作:
# echo "0 1 0 24000000 1 0 2 0 0 1 0" > /sys/devices/platform/soc/1924000.pwm/config
[aic@] # cat /sys/devices/platform/soc/19240000.pwm/status
In PWM V1.00:
Module Enable: 1, IRQ Enable: 0x0
Ch En Mode Tb-clk-rate Def CBD CBU CAD CAU PRD ZRO
0 1 Up 24000000 1 - - - Hgh Low -
- Hgh - - Low -
1 0 Up 24000000 1 - - - Hgh Low Low
- - - - - -
2 0 Up 24000000 0 - - - - - -
- - - - - -
3 0 Up 24000000 0 - - - - - -
- - - - - -
epwm config 节点操作:
# echo "0 0 0 24000000 0 0 0 0 1 0 2" > /sys/devices/platform/soc/18200000.epwm/config
[aic@] # cat /sys/devices/platform/soc/18200000.epwm/status
Ch Mode Tb-clk-rate Def CBD CBU CAD CAU PRD ZRO
0 Up 24000000 0 - - - Low - Hgh
- Hgh - - - Low
1 Up 24000000 1 - - - Hgh - Low
- Hgh - - - Low
2 Up 24000000 1 - - - Hgh - Low
- Hgh - - - Low
3 Up 0 0 - - - - - -
- - - - - -
4 Up 0 0 - - - - - -
- - - - - -
5 Up 0 0 - - - - - -
- - - - - -
config
的参数格式定义如下(按从左到右的输入顺序):
参数名称 |
取值范围 |
含义 |
---|---|---|
channel No. |
[0, 3] |
通道号 |
action No. |
[0, 1] |
0和1分别代表action0、action1 |
mode |
[0, 2] |
0, up-count; 1, down-count; 2, up-down-count |
tb-clk-rate |
[0, 24000000] |
时基计数器的工作时钟 |
default level |
[0, 1] |
初始电平 |
CBD |
[0, 3] |
0, none; 1, low; 2, high; 3, inverse |
CBU |
||
CAD |
||
CAU |
||
PRD |
||
ZRO |
同一PWM,2个action输出不同占空比配置。
配置不同占空比需要依赖两个action在不同时间发生变化,首先使用 config
节点,配置PWMx,action0在CAU、ZRO动作,action1在CBU、ZRO动作。然后分别控制 output0
和 output1
。
其中 output0
修改的是CMPA寄存器,此处对应action0,output1
修改的是CMPB寄存器,此处对应action1
pwm output 配置:
[aic@] # echo "3 1000000 800000" > /sys/devices/platform/soc/1924000.pwm/output0
[aic@] # echo "3 1000000 200000" > /sys/devices/platform/soc/1924000.pwm/output1
epwm output 配置:
[aic@] # echo "0 1000000 800000" > /sys/devices/platform/soc/18200000.epwm/output0
[aic@] # echo "0 1000000 200000" > /sys/devices/platform/soc/18200000.epwm/output1
指定数目脉冲输出。
pwm output 配置:
[aic@] # echo "3 0 1000000 800000 8" > /sys/devices/platform/soc/1924000.pwm/pulse
epwm output 配置:
[aic@] # echo "0 0 1000000 500000 8" > /sys/devices/platform/soc/18200000.epwm/pulse
脉冲输出的方向与action配置有关,同时指定脉冲数目输出依赖中断,中断模式需要与action配置相对应。
其中irq_mode范围为0-3,依次为:
0: TBCTR=CMPA且计数器正在递增时触发事件
1: TBCTR=CMPA且计数器正在递减时触发事件
2: TBCTR=CMPB且计数器正在递增时触发事件
3: TBCTR=CMPB且计数器正在递减时触发事件