• ip: either "dev" is duplicate, or "type" is garbage


    Driver installation

     $ make linux-menuconfig
    
    Networking support  --->
        <M>   CAN bus subsystem support ---> 
            --- CAN bus subsystem support
            <M>   Raw CAN Protocol (raw access with CAN-ID filtering)
            <M>   Broadcast Manager CAN Protocol (with content filtering)
                  CAN Device Drivers  --->
                      <M> Virtual Local CAN Interface (vcan)
                      <M> Platform CAN drivers with Netlink support
                      [*]   CAN bit-timing calculation   
                      <M> Microchip 251x series SPI CAN Controller
    
     $ make linux
     $ make
    
    • Reflash kernel and rootfs

    Usage

    • Load all the needed drivers:
    # modprobe can
    # modprobe can-dev
    # modprobe can-raw
    
    APF27 & APF51APF6
    # modprobe mcp251x          
    
    # modprobe flexcan         
    
    • Set the bitrate before all operations

    Example: Set the bitrate of the can0 interface to 125kbps:

    # ip link set can0 up type can bitrate 125000
    
    Note Note: An error occurs when you try to set the bitrate with an old Linux kernel.


    • If the following error occurs when you do the last instruction :
    ip: either "dev" is duplicate, or "type" is garbage
    

    check that this command:

    # which ip
    

    return this message:

    /sbin/ip
    

    and not this one :

    /bin/ip
    

    If the binary is installed in /bin instead of /sbin, the executable file is a link to busybox and the command to set the bitrate doesn't work on busybox, so try the following instructions:

    $ make busybox-clean
    $ make busybox-dirclean
    $ make menuconfig
    
    Package Selection for the target  --->
        Networking applications  --->
            [*] iproute2
    
    $ make 
    

    Then, reflash your rootfs.

    Quick test

    • Once the driver is installed and the bitrate is set, the CAN interface has to be started like a standard net interface:
     # ifconfig can0 up
    
    • and can be stopped like that:
     # ifconfig can0 down
    
    • The socketCAN version can be retrieved this way:
     # cat /proc/net/can/version
    
    • The socketCAN statistics can be retrieved this way:
     # cat /proc/net/can/stats
    

    Userspace tools

    Several tools are provided by socketCAN:

    • candump: dump traffic on a CAN network

    The following command shows the received message from the CAN bus

    candump can0
    
    • cansend: simple command line tool to send CAN-frames via CAN_RAW sockets

    exemple : The following command sends 3 bytes on the bus (0x1E, 0x10, 0x10) with the identifier 500.

    cansend can0 500#1E.10.10
    

    You can send a remote request message

    cansend can0 500#R
    

    The information with the identifier 500 will be available on the bus when the device receive the remote request message

    • cangen: CAN frames generator for testing purpose
    • canplayer: send CAN frames from a file to a CAN interface

    These tools can be compiled and installed on the target by means of the Buildroot menuconfig:

    $ make menuconfig
    
    Package Selection for the target  --->
        Networking  --->
            [*]   Socket CAN
    
    $ make
    

    then, reflash your rootfs.

  • 相关阅读:
    数据结构与算法20170804
    设计模式之抽象工厂模式20170803
    设计模式之建造者模式20170802
    设计模式之工厂方法模式20170801
    设计模式之中介者模式20170731
    设计模式之门面模式20170728
    设计模式之适配器模式20170727
    设计模式之装饰模式20170726
    AndroidStudio 开发JNI
    NDK开发: 打印C代码的调试信息Log
  • 原文地址:https://www.cnblogs.com/zym0805/p/4505462.html
Copyright © 2020-2023  润新知