This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] TDA4VEN-Q1: How to enable, troubleshoot, and debug MCAN, CAN-FD interface not working in Linux

Part Number: TDA4VEN-Q1

Tool/software:

The CAN interface is not working under Linux. How can I troubleshoot this?

  • Troubleshooting Guide

    As an example, TDA4VEN is used, but this guide should be somewhat applicable to all TDA4x and AM6x devices using Linux. There will be differences with available interfaces, pins, and names, but overall flow is same for all device.

    Step 1 - CAN driver is not coming up during boot

    Check to see if MCAN driver is initialized during boot. This can be done by running the following command:

    • dmesg | grep can

    If CAN driver is being probed to be initialized, then the following logs that say "m_can device registered" will be printed:

    root@j722s-evm:/opt/edgeai-gst-apps# dmesg | grep can
    [    0.412218] HugeTLB: 0 KiB vmemmap can be freed for a 1.00 GiB page
    [    0.425552] HugeTLB: 0 KiB vmemmap can be freed for a 32.0 MiB page
    [    0.438891] HugeTLB: 0 KiB vmemmap can be freed for a 2.00 MiB page
    [    0.452224] HugeTLB: 0 KiB vmemmap can be freed for a 64.0 KiB page
    [    1.736111] cpu cpu0: OPP table can't be empty
    [    9.172670] m_can_platform 4e18000.can: m_can device registered (irq=543, version=32)
    [    9.201131] m_can_platform 20701000.can: m_can device registered (irq=544, version=32)
    [    9.298068] m_can_platform 4e08000.can: m_can device registered (irq=545, version=32)
    [   10.199408] m_can_platform 20701000.can main_mcan0: renamed from can1
    [   10.263624] m_can_platform 4e18000.can mcu_mcan1: renamed from can0
    [   10.345368] m_can_platform 4e08000.can mcu_mcan0: renamed from can2
    root@j722s-evm:/opt/edgeai-gst-apps# 

    * note, above logs are from TDA4VEN TI board using the edgeai 10.1 prebuilt image.

    Problem 1:

    If "m_can device registered" logs are not printing out, this indicates that the CAN driver is not probed, or it is probed but there is an error.

    Solution 1:

    1. If no CAN related logs are received, then most likely the devicetree does not have the CAN nodes defined.

    2. If CAN driver is probed, but there is an error, then most likely that it is an pinmux issue. Please check the pinmux in devicetree one more time.

    Step 2 - Did CAN driver come up in boot?

    Run the following command to see if MCAN kernel driver is initialized:

    • ifconfig -a

    If driver is initialized correctly, then the following logs should be outputted:

    root@j722s-evm:/opt/edgeai-gst-apps# ifconfig -a
    eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether 58:a1:5f:c1:d1:09  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 82  bytes 6916 (6.7 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 82  bytes 6916 (6.7 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    main_mcan0: flags=128<NOARP>  mtu 16
            unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
            device interrupt 32
    
    mcu_mcan0: flags=128<NOARP>  mtu 16
            unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
            device interrupt 33
    
    mcu_mcan1: flags=128<NOARP>  mtu 16
            unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
            device interrupt 31
    
    root@j722s-evm:/opt/edgeai-gst-apps#
    

    Problem 1:

    "ifconfig -a" does not show the CAN interfaces

    Solution 1:

    Please go back to "Step 1".

    Step 3 - Testing CAN in CAN-FD internal loopback mode

    Initialize and test a MCAN interface in CAN-FD loopback mode.

    # Put the controller in internal loopback mode
    root@j722s-evm:/opt/edgeai-gst-apps# ip link set main_mcan0 type can bitrate 1000000 dbitrate 5000000 fd on loopback on
    root@j722s-evm:/opt/edgeai-gst-apps# ip link set main_mcan0 up
    
    # Check the details for main_mcan0 node, this should show LOOPBACK
    root@j722s-evm:/opt/edgeai-gst-apps# ip -details link show main_mcan0
    4: main_mcan0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
        link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
        can <LOOPBACK,FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
              bitrate 1000000 sample-point 0.750
              tq 12 prop-seg 29 phase-seg1 30 phase-seg2 20 sjw 10 brp 1
              m_can: tseg1 2..256 tseg2 2..128 sjw 1..128 brp 1..512 brp_inc 1
              dbitrate 5000000 dsample-point 0.750
              dtq 12 dprop-seg 5 dphase-seg1 6 dphase-seg2 4 dsjw 2 dbrp 1
              m_can: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..32 dbrp_inc 1
              clock 80000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536 parentbus platform parentdev 20701000.can
    
    # Run candump in background
    root@j722s-evm:/opt/edgeai-gst-apps# candump main_mcan0 &
    [1] 1610
    root@j722s-evm:/opt/edgeai-gst-apps# [ 2620.760472] can: controller area network core
    [ 2620.764928] NET: Registered PF_CAN protocol family
    [ 2620.780625] can: raw protocol
    
    # Send message on main_mcan0, this should be echoed back on the console as candump is running in background
    root@j722s-evm:/opt/edgeai-gst-apps# cansend main_mcan0 113##2AAAAAAAA
      main_mcan0  113  [04]  AA AA AA AA
      main_mcan0  113  [04]  AA AA AA AA
    root@j722s-evm:/opt/edgeai-gst-apps#

    Problem 1:

    Wrong CAN-frame format!

    root@j722s-evm:/opt/edgeai-gst-apps# cansend main_mcan0 113##2AAAAAAAAA
    
    Wrong CAN-frame format!
    
    cansend - send CAN-frames via CAN_RAW sockets.
    
    Usage: cansend <device> <can_frame>.
    
    <can_frame>:
     <can_id>#{data}          for Classical CAN 2.0 data frames
     <can_id>#R{len}          for Classical CAN 2.0 data frames
     <can_id>#{data}_{dlc}    for Classical CAN 2.0 data frames
     <can_id>#R{len}_{dlc}    for Classical CAN 2.0 data frames
     <can_id>##<flags>{data}  for CAN FD frames
    
    <can_id>:
     3 (SFF) or 8 (EFF) hex chars
    {data}:
     0..8 (0..64 CAN FD) ASCII hex-values (optionally separated by '.')
    {len}:
     an optional 0..8 value as RTR frames can contain a valid dlc field
    _{dlc}:
     an optional 9..F data length code value when payload length is 8
    <flags>:
     a single ASCII Hex value (0 .. F) which defines canfd_frame.flags
    
    Examples:
      5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / 123##1 / 213##311223344 /
      1F334455#1122334455667788_B / 123#R / 00000123#R3 / 333#R8_E
    
    root@j722s-evm:/opt/edgeai-gst-apps#

    Solution 1:

    CAN-FD supports a flexible message payload, but when using the Linux CAN utility tools, the messages should be sent in multiples of 8 bits or 2 hex characters.

    Problem 2:

    The "ip link set" command does not work

    Solution 2:

    Most likely the CAN driver is not initialized. Please go to "Step 1" in the troubleshooting guide. Otherwise, it may be different name for the interface (for example, instead of main_mcan0, might be can0).

    Problem 3:

    No data is being received or sent

    Solution 3:

    Please make sure the "candump" command is running in the background. This may be checked using "ps aux | grep can" to get below logs that candump is running.

    root@j722s-evm:/opt/edgeai-gst-apps# ps aux | grep can
    root         565  0.0  0.0   2888  1408 ?        Ss   18:44   0:00 /usr/sbin/tee-supplicant
    root        1675  0.0  0.0   2076   896 ttyS2    S    20:12   0:00 candump main_mcan0
    root        1677  0.0  0.0   3496  1280 ttyS2    S+   20:12   0:00 grep can
    root@j722s-evm:/opt/edgeai-gst-apps#
    

    Step 4 - Testing CAN in CAN-FD mode with other devices

    On receiver, set up CAN-FD and candump like below:

    # Initialize CAN-FD 
    root@j722s-evm:/opt/edgeai-gst-apps# ip link set main_mcan0 type can bitrate 1000000 dbitrate 5000000 fd on 
    root@j722s-evm:/opt/edgeai-gst-apps# ip link set main_mcan0 up
    
    # Check the details for main_mcan0 node
    root@j722s-evm:/opt/edgeai-gst-apps# ip -details link show main_mcan0
    4: main_mcan0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
        link/can  promiscuity 0 allmulti 0 minmtu 0 maxmtu 0
        can <LOOPBACK,FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
              bitrate 1000000 sample-point 0.750
              tq 12 prop-seg 29 phase-seg1 30 phase-seg2 20 sjw 10 brp 1
              m_can: tseg1 2..256 tseg2 2..128 sjw 1..128 brp 1..512 brp_inc 1
              dbitrate 5000000 dsample-point 0.750
              dtq 12 dprop-seg 5 dphase-seg1 6 dphase-seg2 4 dsjw 2 dbrp 1
              m_can: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..32 dbrp_inc 1
              clock 80000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535 gro_max_size 65536 gso_ipv4_max_size 65536 gro_ipv4_max_size 65536 parentbus platform parentdev 20701000.can
    
    # Run candump 
    root@j722s-evm:/opt/edgeai-gst-apps# candump main_mcan0
    [1] 1610
    root@j722s-evm:/opt/edgeai-gst-apps# [ 2620.760472] can: controller area network core
    [ 2620.764928] NET: Registered PF_CAN protocol family
    [ 2620.780625] can: raw protocol
    

    For sender, do similar set up, but use cansend for last command

    Problem 1:

    The "ip link set" command does not work

    Solution 1:

    Most likely the CAN driver is not initialized. Please go to "Step 1" in the troubleshooting guide. Otherwise, it may be different name for the interface (for example, instead of main_mcan0, might be can0).

    Problem 2:

    "Protocol error in Arbitration fail" and or "Data phase error detected" is printed out

    Solution 2:

    • Please check "sample-point" is the same for all devices connected through CAN
    • Please check "dbitrate" is supported by all devices connected through CAN
    • Please check "bitrate" is supported by all devices connected through CAN

    Problem 3:

    Data is not going out.

    Solution 3:

    • Please check the pinmuxing again to see if correct pins are pinmuxed
    • Please check the hardware wiring for CAN_H, CAN_L, and GND are correct
    • Please check to see if receiver is ready to receive

    Step 5 - Still have issues with MCAN?

    Please post a new E2E forum post and share details of the issue at hand, along with the full output from "dmesg".

    Regards,

    Takuma