Skip to content

Instantly share code, notes, and snippets.

@takurx
Last active January 22, 2024 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takurx/9b324a2d47442c78b3474c87b34bae59 to your computer and use it in GitHub Desktop.
Save takurx/9b324a2d47442c78b3474c87b34bae59 to your computer and use it in GitHub Desktop.
[WIP] debugging CAN-BUS......

CAN Bus Debug Command

command list

  • connect Microchip CAN-BUS analyzer to USB
  • check device/network interface
ip link
  • set bitrate
sudo ip link set can0 type can bitrate 125000
  • start(up) can-bus interface
sudo ip link set can0 up
  • check tx/rx packet
ip -details -statistics link
  • stop(down) can-bus interface
sudo ip link set can0 down
  • install can-utils
sudo apt install can-utils
  • send dummy CAN signal
cangen can0
  • receive/sniffing CAN signal
candump can0
  • send CAN signal (CAN 2.0B, extended ID)
cansend can0 00001234#F0
  • can statistics
ip -details -statistics link show can0
  • can signal generate and repeat
cangen can0 -g 10 -e -I 00001419 -D 0384 -L 2
  • can bus load check
canbusload can0 -b -r -c

command log

  • connect Microchip CAN-BUS analyzer to USB
  • check device/network interface
chiya@ujimatsu:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether e8:6a:64:88:74:eb brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether 50:76:af:42:a5:81 brd ff:ff:ff:ff:ff:ff
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can 
  • set bitrate
chiya@ujimatsu:~$ sudo ip link set can0 type can bitrate 500000
  • start(up) can-bus interface
chiya@ujimatsu:~$ sudo ip link set can0 up
chiya@ujimatsu:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether e8:6a:64:88:74:eb brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether 50:76:af:42:a5:81 brd ff:ff:ff:ff:ff:ff
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can 
  • check tx/rx packet
chiya@ujimatsu:~$ ip -details -statistics link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 minmtu 0 maxmtu 0 addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    44603874   92371    0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    44603874   92371    0       0       0       0       
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether e8:6a:64:88:74:eb brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 68 maxmtu 9000 addrgenmode none numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0       
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether 50:76:af:42:a5:81 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 256 maxmtu 2304 addrgenmode none numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    2042119690 1999318  0       21764   0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    178819133  837052   0       0       0       0       
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 500000
	     [   20000,    33333,    50000,    80000,    83333,   100000, 
	        125000,   150000,   175000,   200000,   225000,   250000, 
	        275000,   300000,   500000,   625000,   800000,  1000000 ]
	  termination 0 [ 0, 120 ]
	  clock 0 
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0
  • stop(down) can-bus interface

  • install can-utils

  • send dummy CAN signal

  • receive/sniffing CAN signal

chiya@ujimatsu:~$ candump can0
  can0  789   [1]  D7
  can0  3B1   [8]  90 23 D0 4E 07 EE 8A 49
  can0  1F6   [6]  50 DF 90 14 8B 05
  can0  4B8   [8]  06 15 43 0B 50 A5 3C 4E
  can0  4F6   [4]  50 0E 6E 39
  can0  2DC   [8]  FF 49 A8 4D E4 D1 92 2A
  can0  313   [8]  A3 1A DC 56 77 0E 00 55
  can0  7B4   [6]  E2 28 81 08 3D 47
  • can statistics
chiya@ujimatsu:~$ ip -details -statistics link show can0
10: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0 
    can state ERROR-WARNING (berr-counter tx 0 rx 1) restart-ms 0 
	  bitrate 125000
	     [   20000,    33333,    50000,    80000,    83333,   100000, 
	        125000,   150000,   175000,   200000,   225000,   250000, 
	        275000,   300000,   500000,   625000,   800000,  1000000 ]
	  termination 0 [ 0, 120 ]
	  clock 0 
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    1081985    540995   0       0       0       0  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment