CAN FD example for iMX8 Max Plus Verdin

Hi, Is there any running example of CAN1 or CAN2 for Toradex iMX8 Plus verdin.

Below sample is not working

inside container can’t run below command

ip link set can0 type can bitrate 500000

Seems ip is not known by container
Screenshot from 2024-10-11 13-38-15

Had to manually install iproute2 and can-utils inside container
After that cant get can0

I can get can0 outside of the container in torizon OS

inside /dev verdin-can1 is not found as well

Have to run in privileged mode

# docker run --rm -it --privileged --name=can-test --net=host --cap-add="NET_ADMIN"  6db5fb72e18b sh

below is not working

when I am dumping nothing is coming
Screenshot from 2024-10-11 15-59-34

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


For the Verdin iMX8M Plus, both CAN1 and CAN2 interfaces are available and enabled by default as Verdin Reserved interfaces. The i.MX 8M Plus SoC features two Flexible Controller Area Network (FlexCAN) interfaces, which are compatible with other Verdin modules. Depending on the SoC version, the CAN interface supports the CAN Flexible Data Rate (CAN FD).

While the context does not provide a specific running example for CAN1 or CAN2 on the Verdin iMX8M Plus, you can utilize the pre-installed CAN utilities on the Reference Minimal Image and the Reference Multimedia Image to test and configure the CAN interfaces. The can-utils fork, which is included in the Toradex reference image, can be used for this purpose. You can refer to the can-utils README for more detailed instructions on using these utilities.

If you need further guidance on setting up and testing the CAN interfaces, you might want to check the Toradex documentation or community forums for any shared examples or additional resources.

Please, also check if these links can help you solve your problem:

https://community.toradex.com/tag/can

Using CAN bus on Verdin imx8 plus board.

Greetings @khaled.hassan,

Had to manually install iproute2 and can-utils inside container

This was shown in the example Dockerfile.

when I am dumping nothing is coming

Did you physically connect the TX and RX signals on the CAN interfaces you are trying to test?

Best Regards,
Jeremias

Hi Jeremias,
From Dockerfile it does not work had to manually install.
I fixed above issue by adding dependencies in torizonPackages.json file
Screenshot from 2024-10-14 10-11-43
However, I did not connect physically.

Is there any sample application to follow? I need to set following thins

  1. Baudrate during arbitration
  2. Flexible baud rate for CANFD
  3. Address of receiver
  4. Address of sending node
  5. Along with other configuration parameter of CAN module

A smaple application would be really helpful.

Moreover, where to put below arguments if wants to run docker container from VSCode?

I tried from tcb-env-setup by chaning
alias torizoncore-builder=‘docker run -it --rm --net=host --cap-add=“NET_ADMIN”’“$volumes”‘-v “$(pwd)”:/workdir -v ‘“$storage”’:/storage -v /var/run/docker.sock:/var/run/docker.sock’“$network”‘$(tcb_dynamic_params) ‘“$*”’ torizon/torizoncore-builder:’“$chosen_tag”

But seems above is not working.

Processing: image.png…

However, I can see differential voltage in scope sending CAN data from other board (Infineon). But Toradex is not receiving anything. Should I takeout any jumper?

@jeremias.tx when you said “Did you physically connect the TX and RX signals on the CAN interfaces you are trying to test?” what do you mean by this. There is no TX and RX right. It is high and low for CAN.

From Dockerfile it does not work had to manually install.

Are you sure? Maybe you’re installing it in the wrong Dockerfile, or wrong section of the Dockerfile. Otherwise it would not make sense that you can install it manually but not in the Dockerfile.

Is there any sample application to follow? I need to set following thins

We don’t provide a specific CAN application. That said, I’m sure there’s many examples that can be found online. The can-utils repository might be a good source for code references: GitHub - linux-can/can-utils: Linux-CAN / SocketCAN user space applications

Moreover, where to put below arguments if wants to run docker container from VSCode?

If you are using our VSCode extension, then everything related to how a container is started is defined in the docker-compose.yml file. You can consult the reference for this file to determine how to translate docker run arguments to docker-compose.yml syntax: Compose file reference | Docker Docs

I tried from tcb-env-setup by chaning

I’m confused this has nothing to do with torizoncore-builder.

when you said “Did you physically connect the TX and RX signals on the CAN interfaces you are trying to test?” what do you mean by this. There is no TX and RX right. It is high and low for CAN.

I’m talking about the CAN controller on the module itself which has a TX/RX. It looks like you’re talking about the CAN transciever which is on the carrier board and the CAN controller connects to.

Either way, you’re trying to cansend and candump something, correct? So if you you send something on CAN, how are you expecting to receive it? You would need some kind of connection or loopback otherwise how can you candump the message you sent with cansend.

Best Regards,
Jeremias

Hi Jeremias,

I am trying to do cansend and candump. This is correct.

I connected with another infineon board to high and low pins. Moreover put pin 20/22 ->TX/RX on scope. Nothing was changing?

How to check loopback? Should I short Tx and Tx. X3, Pin 20 and 22 in A column in verdin board?

Should I need to take out any jumper?

I connected with another infineon board to high and low pins. Moreover put pin 20/22 ->TX/RX on scope. Nothing was changing?

So you connected a device on the end of the CAN transceiver? What’s the setup exactly?

You send a message on CAN bus from the Toradex device to the infineon board. Then what are you expecting to receive on candump from this infineon board?

How to check loopback? Should I short Tx and Tx. X3, Pin 20 and 22 in A column in verdin board?

Originally I thought you were trying to send data from the Verdin board and receive the same data on the same Verdin board. Which is why I mentioned a loopback connection. But now it sounds like you instead have this infineon board connection which I’m not sure how that fits into this.

Best Regards,
Jeremias

Yes a device is on the end of the CAN transceiver. CAN Hi and CAN Lo of Toradex board are connected with CAN Hi and CAN Lo of Infineon board respectively. Please let me know if this setup is incorrect.

I am receiving message from Infineon to Toradex board (Can see through scope) but candump is not showing anything. I do expect candump should show it in Toradex.

Hi @jeremias.tx
I will be helpful if I get answers of my questions rather than questions.
However, Would you please answer my following questions.

  1. Do I need to take out any jumper of the verdin board for CAN messages transmission?
  2. How to check loopback? Do I need to connect TX and RX of Toradex board?
  3. I expect when other device will send messages I shall see those in candump. Is it that correct expectation?
  4. Python implementation is not available now. Can you give me the link of python implementation mentioned here
    below link is not working
    Documentation version not found - Read the Docs (python-can.readthedocs.io)

If you have questions please ask after answering above questions.

NB: Baudrate 250k is set in both boards for trasmission and receiving.

Best Regards
Md Khaled Ibn Hassan

Hi @jeremias.tx today seems I am getting CAN Hi and CAN Lo signal. Did not do anything new.
But I shall like to get candump from other board. candump is not working.

Hi Just to update seems candump can0 is working working while connected infineon board in other end. But unfortunately yet not successful to do communication in between boards.

Hello @khaled.hassan,

This is how I did basic CAN interface testing when I only had to validate, that my device tree works. I hope it helps you with your issue. I do not have any other CAN nodes and I do not currently posses oscilloscope, so it is just a very basic testing.

First I created a docker image using How to Use CAN on Torizon OS, Make sure to run following command to enable ARM emulation before building can-torizon-sample:

$ docker run --rm -it --privileged torizon/binfmt

Then move the docker archive to Verdin module and start it. Once you are in docker environment, my testing started to differ.

Physically connecting RX and TX signals on the same CAN interface (shorting) will not work, because the CAN node cannot acknowledge itself. You would need to connect two different CAN interfaces (which is actually possible on Verdin, but I have not used it).

For first testing I used SW loop-back. I ran candump in background creating canout.txt, while sending data with cansend. Messages appeared in canout.txt, but I am not sure why it always appeared twice.

Commands:

# ip link set can0 type can bitrate 250000 loopback on
# ip link set can0 up
# candump can0 > canout.txt &
# cansend can0 300#AA.BB.CC.11
# cansend can0 300#AA.BB.CC.22
# cansend can0 300#AA.BB.CC.33
# ip link set can0 down
# cat canout.txt

Content of canout.txt:

  can0  300   [4]  AA BB CC 11
  can0  300   [4]  AA BB CC 11
  can0  300   [4]  AA BB CC 22
  can0  300   [4]  AA BB CC 22
  can0  300   [4]  AA BB CC 33
  can0  300   [4]  AA BB CC 33

In the second test I actually measured voltage difference behind CAN transceiver, which translates TX to CAN High and CAN Low. It is important to understand, how transceiver works, nicely explained here.

When sending CAN command via cansend, the command is repeated in a loop until acknowledged. Due to this behavior, you can do a basic check even without another node. Command will never be acknowledged and will be repeated in an infinite loop. You can take advantage of this by measuring “average voltage” between CAN_H and CAN_L with a simple voltmeter.

There is a simple rule that the more bits have high value, the lower the voltage difference will be. Be aware that the voltage difference will not increase or decrease with ideal consistency, because CAN protocol data link layer contains other bits that you cannot set directly, for example CRC. But you can do at least basic checks. Just for illustration, here are some measurement which I did at my custom carrier board.

cansend can0 7FF#FF.FF.FF.FF -> 0.53V
cansend can0 0FF#FF.FF.FF.FF -> 0.61V
cansend can0 F0F#FF.FF.FF.FF -> 0.62V
cansend can0 F00#FF.FF.FF.FF -> 0.71V
cansend can0 0F0#FF.FF.FF.FF -> 0.72V
cansend can0 00F#FF.FF.FF.FF -> 0.76V
cansend can0 001#FF.FF.00.00 -> 1.15V
cansend can0 001#00.00.FF.FF -> 1.15V
cansend can0 7FF#00.00.00.00 -> 1.30V
cansend can0 002#00.00.00.00 -> 1.41V
cansend can0 001#00.00.00.00 -> 1.46V

To do this measurements yourself, make sure to disable SW loopback, and then make sure to change state to down and back up after each command.

# ip link set can0 type can bitrate 250000 loopback off
# ip link set can0 up
# cansend can0 7FF#FF.FF.FF.FF
# ip link set can0 down
# ip link set can0 up
# cansend can0 0FF#FF.FF.FF.FF
# ip link set can0 down
# ip link set can0 up
...

I hope this helps you or others testing CAN. It does not test the receiving side, but this will only be possible with a real second node.

Best Regards,
Jaroslav

@henrique.tx Thanks for the solution.
I found following references are very useful too
How to Use CAN on Torizon OS | Toradex Developer Center

Reading Vehicle OBD-II data through CAN within a containerized application in Embedded Linux - CNX Software (cnx-software.com)

Below command I used to solve CANFD issue as you said
using can-util from container please use
below commands

  1. ip link set can0 up type can bitrate 500000 dbitrate 2000000 fd on
  2. cansend can0 123##0112233445566778899AABBCCDDEEFF00

I shall be happy to help anyone regarding CAN issues. Please feel free to comment or reach me.

1 Like

Hi @khaled.hassan !

Thanks for commenting about your solution.

We will work on adding such commands about CAN FD to our documentation.

Best regards,

1 Like

@henrique.tx Just noticed today. Not only deadbeef if we put letter at the start say AABBCCDD then also it distorts in receiving end. We have to put a number (one digit/nimble) say 0~9 to make it correct. Would you please also look into that.
This is making CAN unreliable for Torizon.

Hi @khaled.hassan !

As commented via email, cansend needs a flag as the first nibble in the dataframe: CAN FD frames need a control field (8 bits) to be added to the frame: CAN FD: CAN in Automation (CiA)

But cansend only accepts 4 bits (0, 1, …, F) out of those 8 bits. It is not yet clear to me which of them. I guess it is the DLC, but I am not sure.

If you would like to invest some time investigating, this is the place where the parsing of the arguments happen on cansend : can-utils/lib.c at 6526683a10d8700ceea5148e5d2652fadaf3db6d · linux-can/can-utils · GitHub

It is (poorly) documented on cansed’s manpage: cansend(1) — can-utils — Debian testing — Debian Manpages

Best regards,