Linux CAN驱动及测试总结

平台: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、设备树中添加:
    
 
   
  1. For Zynq CANPS Dts file:
  2. zynq_can_0: can@e0008000 {
  3. compatible = "xlnx,zynq-can-1.0";
  4. clocks = <&clkc 19>, <&clkc 36>;
  5. clock-names = "can_clk", "pclk";
  6. reg = <0xe0008000 0x1000>;
  7. interrupts = <0 28 4>;
  8. interrupt-parent = <&intc>;
  9. tx-fifo-depth = <0x40>;
  10. rx-fifo-depth = <0x40>;
  11. };
  12. For Axi CAN Dts file:
  13. axi_can_0: axi-can@40000000 {
  14. compatible = "xlnx,axi-can-1.00.a";
  15. clocks = <&clkc 0>, <&clkc 1>;
  16. clock-names = "can_clk","s_axi_aclk" ;
  17. reg = <0x40000000 0x10000>;
  18. interrupt-parent = <&intc>;
  19. interrupts = <0 59 1>;
  20. tx-fifo-depth = <0x40>;
  21. rx-fifo-depth = <0x40>;
  22. };

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

你可能感兴趣的:(Linux CAN驱动及测试总结)