平台:Zynq-7010
内核:Linux3.14.52
Xilinx官网CAN驱动相关:
http://www.wiki.xilinx.com/Linux+CAN+driver
1、内核中开启CAN总线:
1)进入内核源码顶层目录 cd /opt/hzzd/linux/linux-xlnx-xilinx-v2014.2.01/
2)make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig
3)选中"Networking support"->"CAN bus subsystem support"->"CAN device drivers"->"xilinx CAN",保存退出;
2、设备树中添加:
For Zynq CANPS Dts file:
zynq_can_0: can@e0008000 {
compatible = "xlnx,zynq-can-1.0";
clocks = <&clkc 19>, <&clkc 36>;
clock-names = "can_clk", "pclk";
reg = <0xe0008000 0x1000>;
interrupts = <0 28 4>;
interrupt-parent = <&intc>;
tx-fifo-depth = <0x40>;
rx-fifo-depth = <0x40>;
};
For Axi CAN Dts file:
axi_can_0: axi-can@40000000 {
compatible = "xlnx,axi-can-1.00.a";
clocks = <&clkc 0>, <&clkc 1>;
clock-names = "can_clk","s_axi_aclk" ;
reg = <0x40000000 0x10000>;
interrupt-parent = <&intc>;
interrupts = <0 59 1>;
tx-fifo-depth = <0x40>;
rx-fifo-depth = <0x40>;
};
3、上述Xilinx官网下载测试lib包,注意需将libsocketcan.so.2.2.0拷贝到目标板的/lib文件夹下,并建立快捷方式:ln -s libsocketcan.so.2.2.0 libsocketcan.so.2;
4、编写CAN的socket收发测试程序canApp;
5、以下步骤均指在目标板操作:
root@hzzd:/mnt/zynq_canutils# ./canconfig can0 bitrate 200000
XILINX_CAN e0008000.can can0: bitrate error 0.0%
can0 bitrate: 199999, sample-point: 0.750
root@hzzd:/mnt/zynq_canutils# ./canconfig can0 start
xiao's open
can0 state: ERROR-ACTIVE
root@hzzd:/mnt/zynq_canutils# cd ..
root@hzzd:/mnt# ./canApp
1
2
can frame sent 0