1:arm-linlux-gnueabihf-gcc可以从linaro下载
新版本的linux采用dtb和内核的方式管理驱动,要使能比如spi,pwm之内的驱动,需要修改dtb和内核
ti有一个分配管脚的工具,TI PINMUX,根据你的想要使能的功能,进行设置,然后导出devicetree.txt。
以PWM为例
Devicetree.txt
/* This file was auto-generated by TI PinMux on 2017/6/9 at上午10:18:57. */
/* This file should only be used as a reference. Some pins/peripherals, */
/* depending on your use case, may need additionalconfiguration. */
myehrpwm1_pins_default: myehrpwm1_pins_default {
pinctrl-single,pins= <
0x24 (PIN_OUTPUT | MUX_MODE4 ) /* (T10) gpmc_ad9.ehrpwm2B */
>;
};
/* Optional sleep pin settings. Must manually enter values in thebelow skeleton. */
myehrpwm1_pins_sleep: myehrpwm1_pins_sleep {
pinctrl-single,pins= <
0x24 ( )/* (T10) gpmc_ad9.ehrpwm2B */
>;
};
在将dtb文件转为dts文件,在dts文件中添加红色部分(devicetree中的内容拷贝进去就是了)。
pinmux@800{
compatible= "pinctrl-single";
reg= <0x800 0x238>;
#address-cells= <0x1>;
#size-cells= <0x0>;
pinctrl-single,register-width= <0x20>;
pinctrl-single,function-mask= <0x7f>;
pinctrl-names= "default";
pinctrl-0= <0x24>;
user_leds_default{
pinctrl-single,pins= <0x54 0x7 0x58 0x17 0x5c 0x7 0x60 0x17>;
linux,phandle= <0x50>;
phandle= <0x50>;
};
user_leds_sleep{
pinctrl-single,pins= <0x54 0x27 0x58 0x27 0x5c 0x27 0x60 0x27>;
linux,phandle= <0x51>;
phandle= <0x51>;
};
pinmux_i2c0_pins{
pinctrl-single,pins= <0x188 0x30 0x18c 0x30>;
linux,phandle= <0x32>;
phandle= <0x32>;
};
pinmux_i2c2_pins{
pinctrl-single,pins= <0x178 0x33 0x17c 0x33>;
linux,phandle= <0x36>;
phandle= <0x36>;
};
pinmux_uart0_pins{
pinctrl-single,pins= <0x170 0x30 0x174 0x0>;
linux,phandle= <0x31>;
phandle= <0x31>;
};
pinmux_clkout2_pin{
pinctrl-single,pins= <0x1b4 0x3>;
linux,phandle= <0x24>;
phandle= <0x24>;
};
cpsw_default{
pinctrl-single,pins= <0x110 0x30 0x114 0x0 0x118 0x30 0x11c 0x0 0x120 0x0 0x124 0x0 0x128 0x00x12c 0x30 0x130 0x30 0x134 0x30 0x138 0x30 0x13c 0x30 0x140 0x30>;
linux,phandle= <0x47>;
phandle= <0x47>;
};
cpsw_sleep{
pinctrl-single,pins= <0x110 0x27 0x114 0x27 0x118 0x27 0x11c 0x27 0x120 0x27 0x124 0x27 0x1280x27 0x12c 0x27 0x130 0x27 0x134 0x27 0x138 0x27 0x13c 0x27 0x140 0x27>;
linux,phandle= <0x48>;
phandle= <0x48>;
};
davinci_mdio_default{
pinctrl-single,pins= <0x148 0x30 0x14c 0x10>;
linux,phandle= <0x49>;
phandle= <0x49>;
};
davinci_mdio_sleep{
pinctrl-single,pins= <0x148 0x27 0x14c 0x27>;
linux,phandle= <0x4a>;
phandle= <0x4a>;
};
pinmux_mmc1_pins{
pinctrl-single,pins= <0x160 0x2f>;
linux,phandle= <0x38>;
phandle= <0x38>;
};
pinmux_emmc_pins{
pinctrl-single,pins= <0x80 0x32 0x84 0x32 0x0 0x31 0x4 0x31 0x8 0x31 0xc 0x31 0x10 0x31 0x140x31 0x18 0x31 0x1c 0x31>;
linux,phandle= <0x3b>;
phandle= <0x3b>;
};
nxp_hdmi_bonelt_pins{
pinctrl-single,pins= <0x1b0 0x3 0xa0 0x8 0xa4 0x8 0xa8 0x8 0xac 0x8 0xb0 0x8 0xb4 0x8 0xb8 0x80xbc 0x8 0xc0 0x8 0xc4 0x8 0xc8 0x8 0xcc 0x8 0xd0 0x8 0xd4 0x8 0xd8 0x8 0xdc0x8 0xe0 0x0 0xe4 0x0 0xe8 0x0 0xec 0x0>;
linux,phandle= <0x33>;
phandle= <0x33>;
};
nxp_hdmi_bonelt_off_pins{
pinctrl-single,pins= <0x1b0 0x3>;
linux,phandle= <0x34>;
phandle= <0x34>;
};
mcasp0_pins{
pinctrl-single,pins= <0x1ac 0x30 0x19c 0x2 0x194 0x10 0x190 0x0 0x6c 0x7>;
linux,phandle= <0x4e>;
phandle = <0x4e>;
};
mcspi1_pins{
pinctrl-single,pins= <0x190 0x33 0x194 0x33 0x198 0x13 0x19c 0x13>;
linux,phandle= <0x58>;
phandle= <0x58>;
};
myehrpwm1_pins_default:myehrpwm1_pins_default {
pinctrl-single,pins= <0x24 ( PIN_OUTPUT | MUX_MODE4 )>;
};
};
以pwm为例,让EHRPWM2B输出pwm波形。需要修改EHRPWM2的节点,参看am335x的文档,其EHRPWM2的地址是48304000。
在dtb中找到对应的节点,按照如下修改
epwmss@48304000 {
compatible= "ti,am33xx-pwmss";
reg= <0x48304000 0x10>;
ti,hwmods= "epwmss2";
#address-cells= <0x1>;
#size-cells= <0x1>;
status ="okay";
ranges= <0x48304100 0x48304100 0x80 0x48304180 0x48304180 0x80 0x483042000x48304200 0x80>;
pinctrl-names= "default";
pinctrl-0= <&myehrpwm1_pins_default>;
ecap@48304100{
compatible= "ti,am3352-ecap", "ti,am33xx-ecap";
#pwm-cells= <0x3>;
reg= <0x48304100 0x80>;
clocks= <0x29>;
clock-names= "fck";
interrupts= <0x3d>;
interrupt-names= "ecap2";
status= "disabled";
};
pwm@48304200{
compatible= "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
#pwm-cells= <0x3>;
reg= <0x48304200 0x80>;
clocks= <0x44 0x29>;
clock-names= "tbclk", "fck";
status = "okay";
};
};
共修改两部分
1.使能节点
epwmss@48304000,pwm@48304200的参数state=“okay”,使能节点,使能EPRPWM2的驱动。做完这一步就可以在beaglebone里的/sys/class/pwm/pwmchip0就有了,就可以设置pwm的参数了,但是pwm信号是没有输出的,因为管脚还没设置好。
2. 使能管脚
pinctrl-names ="default";
pinctrl-0 =<&myehrpwm1_pins_default>;//myehrpwm1_pins_default就是上一步中我们设置的管脚。
这一步,在使能节点驱动的同时,就把pwm的管脚使能了。
到这里dts就修改完成了,将dts用dtc工具转换为dtb文件。
在内核中修改配置
makeARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
以pwm为例
Device Drivers --->
<*> Pulse WidthModulation(PWM) Support --->
<*> eHRPWM PWM support
DeviceDrivers --->
<*> Pulse WidthModulation(PWM) Support --->
<*> eCAP PWM support
重新编译就好了。
之后将编译好的内核和dtb文件拷贝到开发板根文件目录下的boot文件夹里。开发板重新上电就可以了。
在开发板上执行如下操作就可以查看pwm是否正常运行。
target$ echo 1 >/sys/class/pwm/pwmchip0/export 多出一个文件夹pwm1,对应EHRPWM2B,如果写入0,则会多出PWM0,对应EHRPWM2A。
target$ echo 1000000000 > /sys/class/pwm/pwmchip0/pwm1/period设置周期1s
target$ echo val >/sys/class/pwm/pwmchip0/pwm1/duty_cycle设置占空比
target$ echo 1 > /sys/class/pwm/pwmchip0/pwm1/enable使能pwm。
pwm波形就出现了。
在开发板中打印如下
cat/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
可以查看管脚当前的设置状态,确认自己的dtb文件管脚设置有没有改对。
1. dtc -I dtb -O dts am335x-boneblack.dtb >am335x-boneblack.dts
2. dtc -I dts -O dtb am335x-boneblack.dts >am335x-boneblack.dtb