One of the new feature of the i.MX8 family is to support CAN FD. Fortunately the MEK board has a TJA1043 supporting CAN FD.
The following document show you how to do simple CAN (FD) test under Linux.
First of all let configure the CAN0 to be at 500kps in CAN, and 4Mbps in CAN FD:
ip link set can0 up type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
Let's do the same for CAN1:
ip link set can1 up type can bitrate 500000 sample-point 0.75 dbitrate 4000000 dsample-point 0.8 fd on
Now you can do a bridge between CAN0 and CAN1 on the board. The easiest way is to put simple wires (pin 2 to pin 2 a,d pin 7 to pin 7), normally you have to twist your wires, but as it is on your desk, you can get rid of it):
You can check the configurations of your FlexCAN:
root@imx8qxpmek:~# ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
can <FD> state ERROR-WARNING (berr-counter tx 0 rx 0) restart-ms 0
bitrate 500000 sample-point 0.750
tq 25 prop-seg 29 phase-seg1 30 phase-seg2 20 sjw 1
flexcan: tseg1 2..64 tseg2 1..32 sjw 1..32 brp 1..1024 brp-inc 1
dbitrate 4000000 dsample-point 0.800
dtq 25 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1
flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
clock 40000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
root@imx8qxpmek:~# ip -details link show can1
4: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 500000 sample-point 0.750
tq 25 prop-seg 29 phase-seg1 30 phase-seg2 20 sjw 1
flexcan: tseg1 2..64 tseg2 1..32 sjw 1..32 brp 1..1024 brp-inc 1
dbitrate 4000000 dsample-point 0.800
dtq 25 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1
flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
clock 40000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
root@imx8qxpmek:~#
Now a simple test can be to send random CAN FD messages, for that use "cangen" to send random CAN FD messages (read "cangen" documentation: https://manpages.debian.org/stretch-backports/can-utils/cangen.1.en.html
root@imx8qxpmek:~# cangen can0 -v -b -g 20
can1 3E6 [00]
can1 735 [20] F9 ED 40 53 AC CF 48 34 F9 ED 40 53 AC CF 48 34 F9 ED 40 53
can1 513 [20] 92 D2 E7 32 48 E6 EA 39 92 D2 E7 32 48 E6 EA 39 92 D2 E7 32
can1 03B [12] 6D 34 2F 11 52 8A 52 50 6D 34 2F 11
can1 47D [24] 72 08 88 0D E0 04 F7 09 72 08 88 0D E0 04 F7 09 72 08 88 0D E0 04 F7 09
can1 245 [00]
can1 6F6 [48] B9 82 A1 49 4E ED BA 06 B9 82 A1 49 4E ED BA 06 B9 82 A1 49 4E ED BA 06 B9 82 A1 49 4E ED BA 06 B9 82 A1 49 4E ED BA 06 B9 82 A1 49 4E ED BA 06
can1 1F4 [16] 03 5B 7C 00 DA E5 FA 03 03 5B 7C 00 DA E5 FA 03
can1 38A [48] 71 CE A3 1A C0 8A 4F 20 71 CE A3 1A C0 8A 4F 20 71 CE A3 1A C0 8A 4F 20 71 CE A3 1A C0 8A 4F 20 71 CE A3 1A C0 8A 4F 20 71 CE A3 1A C0 8A 4F 20
can1 4C9 [20] 6C 5A 98 54 DD D1 CB 09 6C 5A 98 54 DD D1 CB 09 6C 5A 98 54
can1 536 [48] 25 B8 B6 43 71 CD 54 71 25 B8 B6 43 71 CD 54 71 25 B8 B6 43 71 CD 54 71 25 B8 B6 43 71 CD 54 71 25 B8 B6 43 71 CD 54 71 25 B8 B6 43 71 CD 54 71
can1 308 [02] C3 57
can1 33E [05] 65 8C 7B 21 83
can1 3F5 [05] EA E0 07 63 EB
can1 633 [03] 39 10 18
can1 25D [32] 01 4E 65 41 E8 4D 94 6F 01 4E 65 41 E8 4D 94 6F 01 4E 65 41 E8 4D 94 6F 01 4E 65 41 E8 4D 94 6F
can1 2FB [03] A8 D8 E3
can1 0DE [04] A1 11 3F 32
can1 012 [06] 85 23 B2 07 1A 03
can1 658 [08] A0 8A 2D 67 97 79 A1 64
can1 37D [05] 1A 57 E8 4F 72
can1 70A [04] 5E 6A B8 0F
can1 3A8 [07] 65 C5 48 76 05 B6 11
can1 5D4 [07] ED 03 A6 07 CF D8 DC
can1 7DA [05] 94 18 50 09 B8
can1 7A9 [05] CC 5E 02 74 BC
can1 3FC [01] D6
can1 599 [06] EB 23 02 61 16 D9
can1 47C [06] 88 20 F2 62 86 3B
can1 30A [06] C4 98 57 61 B2 4E
can1 57E [16] B8 04 86 5B 52 EB DF 45 B8 04 86 5B 52 EB DF 45
can1 191 [05] 22 C4 BC 26 6B
can1 53B [06] 23 AA AA 00 E4 F4
can1 6EB [64] A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D A0 64 BE 5E E7 FA 20 1D
You can check with a scope your CAN FD frame (here CAN High):
And you can see the first part of the frame sent @500kps and the second part @4Mbps.
If you unplug one wire, the messages will no longer be sent as no acknowlege will occurs.
You can also send message without flexible datarate. In our case, we'll send long frame at 500kps (no more 4Mbps transfer for end of the frame):
imx8qxpmek:~# cangen can0 -v -f -g 20
can0 6FE##0.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E.6B.C6.BA.1A.82.2D.29.7E
can0 3E2##0.D4.9E.3D
can0 1DE##0.D0.D8.33.50.7E.39
can0 7CE##0.FA.68.25.74.86.E7.E1.4A.FA.68.25.74.86.E7.E1.4A.FA.68.25.74
can0 7C3##0.58.E6.F2.1E.BD.7D.F8.7F
can0 32A##0.0D.06.98.0D.08.81.5C.4E.0D.06.98.0D.08.81.5C.4E.0D.06.98.0D.08.81.5C.4E.0D.06.98.0D.08.81.5C.4E.0D.06.98.0D.08.81.5C.4E.0D.06.98.0D.08.81.5C.4E
can0 48B##0.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47.76.48.B4.34.59.81.B9.47
can0 3FC##0.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00.6E.70.F7.36.FB.82.B9.00
can0 4BE##0.7D.B0.E2.7E.A0.F0.DF.24.7D.B0.E2.7E
can0 60C##0.0E
can0 257##0.69.11.0C.4B.25.CA.16.65.69.11.0C.4B.25.CA.16.65.69.11.0C.4B.25.CA.16.65.69.11.0C.4B.25.CA.16.65.69.11.0C.4B.25.CA.16.65.69.11.0C.4B.25.CA.16.65
can0 0BA##0.AB.B1.F8
can0 0FC##0.3A.7E.FB.34
can0 452##0.2F.4D.04.26.DE.80.EA
can0 2C7##0.37.02.A4.4D.C3
can0 0B4##0.BE.39.AD.3B.73
can0 17E##0.13.66.44.6A.8A.8F.CE.7A.13.66.44.6A.8A.8F.CE.7A.13.66.44.6A
You can also force the CAN to only send CAN 2.0b frames (not FD, you'll have 8-byte data max frames):
imx8qxpmek:~# cangen can0 -v -g 20
can0 7FF#8F.04.3F.31.EB
can0 135#92.7C.46.5C.95.4E.6C.48
can0 0F8#E3.E4.7E.4D.92.2A.1D.69
can0 68F#C6.B7.BA.35.78.06
can0 4EC#D8.D9.86.19.40.BE.64.05
can0 09F#EE.E1.70.7D.13.C9.18.53
can0 7CE#BB.CD.FE.50.3E.B6.A4.4A
can0 3C7#04
can0 1F6#B2.E4.4B.42
can0 080#C1.81.65.41
can0 14C#0B.B4.7E.5D
can0 15A#53
can0 1CF#86.D4.ED.11.6E.BA.20.14
can0 257#82.83.39.67
can0 2C1#64.20.DF.0D.89.0E.14.55
can0 45E#50.72.44.76.55.4E.96.0F
can0 6FC#80.81
can0 046#F6
can0 1E5#6D
can0 0D2#
can0 7EB#0F.3D.29.78.42.72.60.61
can0 480#68
can0 1CE#CB.05.12.74.2D.0E.F2.14
can0 634#82.5C.88.24.31.75.AF.03
can0 71D#AE.4C
can0 144#F5.A8.17.70
can0 2A5#69.BE
can0 222#18.C6.AA.4A.0D.5A.EC.48
can0 5FA#4F.CC.4C.2A.7B.BA.31
can0 3B9#BD.B1.2F.3C.87.D5.D1
can0 583#B4.E3.C3.4E.B8.D3.22.43
Hi,vincent
thanks for the guide, it is very helpful.
I'm using CAN bus at the MX8QXP MEK board. It is OK when connect CAN0 with CAN1 directly.but when I connect CAN0 to a CANalyzer , problems come:
CAN0 can receive the standard frame sent from CANalyzer, however CANalyzer only can receive the RTR frame sent from CAN0 ,and the Data Frame sent from CAN0 is received wrong.
I wonder how it happens. For the CANalyzer can not receive the FD frame, is it possible to when CAN0 send a frame with FD frame but receive both standard and FD frames?
Thanks in advance.
Hi,
I don't have a Vector probe.
Which model do you have? Are you sure it support CAN FD?
BR
Vincent
Hi,
I have tried with a scope and I don't see RTR error:
I have errors but it is certainly due to the measure (long wires, oscilloscope frequency, etc...).
So please check you Vector tool supports CAN FD.
BR
V.
Hello Vincent,
I wonder if the TJA used in CAN on i.MX8 MEK board works by default or some pin must be configured to command it ?
I use CAN0 connector and I use it by M4 ( autosar)
Can I’ve the schematic between both board ? I mean which pin used of imx8 to control TJA ( Rx, Tx, Stb…)
Best Regards,
Chafiq Sakouat
Hi, I try to follow this guide to test CAN on an i.MX8QM MEK board, see https://community.nxp.com/message/1255675
I tried the the offical validation images for L4.14.98_2.0.0 and L4.19.35_1.1.0. But the CAN devices just don't show up in linux. They are even disabled in the device tree.
Hi,
Strange, I can still find it for i.MX8QXP:
fsl-imx8dx.dtsi\freescale\dts\boot\arm64\arch - linux-imx - i.MX Linux kernel
...but not for i.MX8QM.
In 4.9.88_2.0.0_ga i.MX8QM's FlexCAN is there for i.MX8QM:
fsl-imx8qm.dtsi\freescale\dts\boot\arm64\arch - linux-imx - i.MX Linux kernel
I am checking why.
BR
Vincent
Hi Vincent,
thanks for the anser. In the other thread Igor mentions that it is disabled by fsl-imx8qm-mek-rpmsg.dtsi .
Does this mean that on the A cores with newer images I do not have access to the CAN interfaces anymore by default because CAN is routed to the M4 cores?
Regards
Georg
Hi vincent.aubineau,
so I downloaded imx-image-full-imx8qmmek.sdcard from Linux 4.19.35_1.1.0 and changed the fdt_file in the bootloader with
setenv fdt_file "fsl-imx8qm-mek.dtb"
saveenv
I also checked that the device node is enabled in u-boot:
=> run loadfdt
98315 bytes read in 14 ms (6.7 MiB/s)
=> fdt addr ${fdt_addr}
=> fdt list /can@5a8d0000
can@5a8d0000 {
compatible = "fsl,imx8qm-flexcan", "fsl,imx6q-flexcan";
reg = <0x00000000 0x5a8d0000 0x00000000 0x00010000>;
interrupts = <0x00000000 0x000000eb 0x00000004>;
interrupt-parent = <0x000000bf>;
clocks = <0x00000003 0x00000086 0x00000003 0x00000088>;
clock-names = "ipg", "per";
assigned-clocks = <0x00000003 0x00000088>;
assigned-clock-rates = <0x02625a00>;
power-domains = <0x000000c0>;
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <0x000000c1>;
xceiver-supply = <0x000000c2>;
};
But after booting to linux the nodes are still disabled:
root@imx8qmmek:~# cat /sys/firmware/devicetree/base/can\@5a8d0000/status
disabledroot@imx8qmmek:~# cat /sys/firmware/devicetree/base/can\@5a8e0000/status
disabledroot@imx8qmmek:~# cat /sys/firmware/devicetree/base/can\@5a8f0000/status
disabledroot@imx8qmmek:~#
There are suspicious entry during booting:
Disable can@5a8d0000, resource id 105 not owned
Disable can@5a8e0000, resource id 106 not owned
Disable can@5a8f0000, resource id 107 not owned
See this pastebin for the full logs.
What does "resource not owned" mean? Another forum post from last December suggests that I need to recompile SCFW:
https://community.nxp.com/thread/507460
Do I really need to adapt the system controller firmware to get the base board with CAN working on the A cores?
Regards
Georg
hi vincent.aubineau,
Thank you for sharing this document it really helped to test CAN.
I was thinking as canutils talk to can driver and dump messages cant I do the same dumping & sending it to Vehicle HAL up to the android application?
I basically want to receive CAN frames in VHAL.
Is there a way Vehicle HAL can receive CAN commands and send it up to the application layer?
Is this possible,Android(kernel net can driver)->VHAL->car service->application?
Also, any idea on running this vehicle emulator tools present here
<sources>/packages/services/Car/tools/emulator or
<sources>/hardware/interfaces/automotive/vehicle/2.0/default/tests?
Regards,
Sriraksha