Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rock3/dev/can"

< Rock3‎ | dev
(Created page with "{{rock3_header}} {{Languages|rock3/dev/adb}} ROCK 3 > Development > Using Can ===Description=== ROCK 3 supports can fun...")
 
Line 8: Line 8:
  
 
ROCK 3 supports can function. Here we will test it on ROCK 3A.
 
ROCK 3 supports can function. Here we will test it on ROCK 3A.
Here we use Type-A to Type-A USB cable with one port connected to the Type-A socket of ROCK 3A,
+
Here we use two board to test this function.
and the other port connected to the Type-A socket of the PC.
+
 
+
 
===Hardware support===
 
===Hardware support===
  
 
Support hardware platform:
 
Support hardware platform:
 
* ROCK 3A  x2
 
* ROCK 3A  x2
 
+
* Dupont Line
  
 
=== Operations on ROCK 3A ===
 
=== Operations on ROCK 3A ===
 +
==== Install Test Tool ====
 +
$ sudo apt update
 +
$ sudo apt-get install can-utils iproute2
 +
 +
==== Check the information of Can ====
 +
Check can device
 +
$ ifconfig can0
 +
can0: flags=193<UP,RUNNING,NOARP>  mtu 72
 +
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
 +
        RX packets 144  bytes 1152 (1.1 KiB)
 +
        RX errors 175  dropped 0  overruns 0  frame 35
 +
        TX packets 0  bytes 0 (0.0 B)
 +
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 +
        device interrupt 62 
 +
 +
Check Can detailed information
 +
$ ip -details -statistic link show can0
 +
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group defa
 +
ult qlen 10
 +
    link/can  promiscuity 0 minmtu 0 maxmtu 0
 +
    can <FD> state ERROR-WARNING (berr-counter tx 0 rx 0) restart-ms 0
 +
          bitrate 1000000 sample-point 0.740
 +
          tq 20 prop-seg 18 phase-seg1 18 phase-seg2 13 sjw 1
 +
          rockchip_canfd: tseg1 1..128 tseg2 1..128 sjw 1..128 brp 1..256 brp-inc 2
 +
          dbitrate 1000000 dsample-point 0.720
 +
          dtq 40 dprop-seg 8 dphase-seg1 9 dphase-seg2 7 dsjw 1
 +
          rockchip_canfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp-inc 2
 +
          clock 100000000
 +
          re-started bus-errors arbit-lost error-warn error-pass bus-off
 +
          0          140        0          0          15        0        numtxqueues 1 n
 +
umrxqueues 1 gso_max_size 65536 gso_max_segs 65535
 +
    RX: bytes  packets  errors  dropped overrun mcast 
 +
    1152      144      175    0      35      0     
 +
    TX: bytes  packets  errors  dropped carrier collsns
 +
    0          0        0      0      0      0     
 +
 +
==== Test can function by loopback test ====
 +
Just need one board.
 +
$ sudo ip link set can0 down
 +
$ sudo ip link set can0 type can bitrate 1000000 dbitrate 1000000 loopback on fd on
 +
$ sudo ip link set can0 up
 +
$ sudo candump can0 &
 +
$ sudo cansend can0 123#11223344
 +
can0  123  [4]  11 22 33 44
 +
you can run more '''candump can0 &''' to get more answer.
 +
 +
==== Test can function between two Rock 3a ====
 +
===== '''how to connect two board:''' =====
 +
board A:CAN1_TX_M0 connect to board B:CAN1_TX_M0
 +
 +
board A:CAN1_RX_M0 connect to board B:CAN1_RX_M0
 +
===== '''board A to be receiver and board B to be sender''' =====
 +
This is the c program : [[Media:Can_test.zip]]
 +
Board A :
 +
$ gcc -Wall -g -O0 -o can_receive can_receive.c
 +
$ sudo ./can_receive
 +
this is a can receive demo
 +
can_id = 0x123
 +
can_dlc = 8
 +
data[0] = 1
 +
data[1] = 2
 +
data[2] = 3
 +
data[3] = 4
 +
data[4] = 5
 +
data[5] = 6
 +
data[6] = 7
 +
data[7] = 8
 +
 +
Board B :
 +
$ gcc -Wall -g -O0 -o can_send can_secd.c
 +
$ sudo ./can_send
 +
this is a can send demo
 +
can_id  = 0x123
 +
can_dlc = 8
 +
data[0] = 1
 +
data[1] = 2
 +
data[2] = 3
 +
data[3] = 4
 +
data[4] = 5
 +
data[5] = 6
 +
data[6] = 7
 +
data[7] = 8
 +
This is the communication between the two boards.

Revision as of 07:32, 7 September 2021

    ROCK 3 >  Development >  Using Can

Description

ROCK 3 supports can function. Here we will test it on ROCK 3A. Here we use two board to test this function.

Hardware support

Support hardware platform:

  • ROCK 3A x2
  • Dupont Line

Operations on ROCK 3A

Install Test Tool

$ sudo apt update
$ sudo apt-get install can-utils iproute2

Check the information of Can

Check can device

$ ifconfig can0
can0: flags=193<UP,RUNNING,NOARP>  mtu 72
       unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
       RX packets 144  bytes 1152 (1.1 KiB)
       RX errors 175  dropped 0  overruns 0  frame 35
       TX packets 0  bytes 0 (0.0 B)
       TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
       device interrupt 62  

Check Can detailed information

$ ip -details -statistic link show can0
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group defa
ult qlen 10
   link/can  promiscuity 0 minmtu 0 maxmtu 0 
   can <FD> state ERROR-WARNING (berr-counter tx 0 rx 0) restart-ms 0 
         bitrate 1000000 sample-point 0.740 
         tq 20 prop-seg 18 phase-seg1 18 phase-seg2 13 sjw 1
         rockchip_canfd: tseg1 1..128 tseg2 1..128 sjw 1..128 brp 1..256 brp-inc 2
         dbitrate 1000000 dsample-point 0.720 
         dtq 40 dprop-seg 8 dphase-seg1 9 dphase-seg2 7 dsjw 1
         rockchip_canfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp-inc 2
         clock 100000000
         re-started bus-errors arbit-lost error-warn error-pass bus-off
         0          140        0          0          15         0         numtxqueues 1 n
umrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
   RX: bytes  packets  errors  dropped overrun mcast   
   1152       144      175     0       35      0       
   TX: bytes  packets  errors  dropped carrier collsns 
   0          0        0       0       0       0       

Test can function by loopback test

Just need one board.

$ sudo ip link set can0 down
$ sudo ip link set can0 type can bitrate 1000000 dbitrate 1000000 loopback on fd on
$ sudo ip link set can0 up
$ sudo candump can0 &
$ sudo cansend can0 123#11223344
can0  123   [4]  11 22 33 44

you can run more candump can0 & to get more answer.

Test can function between two Rock 3a

how to connect two board:

board A:CAN1_TX_M0 connect to board B:CAN1_TX_M0

board A:CAN1_RX_M0 connect to board B:CAN1_RX_M0

board A to be receiver and board B to be sender

This is the c program : Media:Can_test.zip

Board A :
$ gcc -Wall -g -O0 -o can_receive can_receive.c
$ sudo ./can_receive
this is a can receive demo
can_id = 0x123
can_dlc = 8 
data[0] = 1
data[1] = 2
data[2] = 3
data[3] = 4
data[4] = 5
data[5] = 6
data[6] = 7
data[7] = 8

Board B :
$ gcc -Wall -g -O0 -o can_send can_secd.c
$ sudo ./can_send
this is a can send demo
can_id  = 0x123
can_dlc = 8
data[0] = 1
data[1] = 2
data[2] = 3
data[3] = 4
data[4] = 5
data[5] = 6
data[6] = 7
data[7] = 8

This is the communication between the two boards.