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

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值