Enabling internal CAN interface on Colibri iMX8

Hello,

I’ve successfully wrote a C# code, using “can0” device ( mcp251x spi0.0 can0: MCP2515) of the colibri evaluation board.
Now we have to use iMX8QXP without a board and I’ve tried to switch to the internal CAN Contoller.

II’ve removed jumpers JP4 and JP5 and connected SODIMM_63 to CAN_RX (X38,2) and SODIMM_55 to CAN_TX (X38, 1).
But it seems to use still an external controller: there is no signals on X2. The socket will be initialized with “can0” parameters, ip link show shows can 0 state UP.
That I schould change also in order to get internal CAN Bus working?

Best Regards,
Dmitry

Greetings @programmier-hirsch,

Additionally you need to enable the specific CAN interface in the device-tree by default. By default these are not enabled in the device-tree. In addition you may need to also disable some interfaces because of pin conflicts.

You should be able to do this via overlay. Please see here for more info: Device Tree Overlays on Torizon | Toradex Developer Center

Best Regards,
Jeremias

Thank you @jeremias.tx

does it mean, I have to install TorizonCore Builder and somehow change in Device Tree

		/* Colibri optional CAN on PS2 */
		pinctrl_flexcan2: flexcan1grp {
			fsl,pins = <
				IMX8QXP_FLEXCAN1_TX_ADMA_FLEXCAN1_TX		0x21		/* SODIMM  55 */
				IMX8QXP_FLEXCAN1_RX_ADMA_FLEXCAN1_RX		0x21		/* SODIMM  63 */
			>;
		};
	
to	
		/* Colibri optional CAN on PS2 */
		pinctrl_flexcan2: flexcan1grp {
			fsl,pins = <
				IMX8QXP_FLEXCAN1_TX_ADMA_FLEXCAN1_TX		0x37		/* SODIMM  55 */
				IMX8QXP_FLEXCAN1_RX_ADMA_FLEXCAN1_RX		0x3F		/* SODIMM  63 */
			>;
		};

?

Will be added “can2” to the system or flexcan2?

Best regards,
Dmitry

Yes you’ll need to create an overlay with TorizonCore Builder that sets the status fro the CAN interface you want from “disabled” to “okay”. Then upon applying this overlay the system should generate the new CAN interface for usage.

Best Regards,
Jeremias

Thanx @jeremias.tx,

but where I can find a step by step manual HOW to do it?
I have installed torizon core builder according Article n WSL2, but I’ve got an error messages in both dto status and dto checkout commands.

Traceback (most recent call last):
  File "/builder/torizoncore-builder", line 204, in <module>
    mainargs.func(mainargs)
  File "/builder/tcbuilder/cli/dto.py", line 223, in do_dto_status
    (dtb_path, is_dtb_exact) = dt.get_current_dtb_path(args.storage_directory)
  File "/builder/tcbuilder/backend/dt.py", line 90, in get_current_dtb_path
    dtb_basename = get_current_dtb_basename(storage_dir)
  File "/builder/tcbuilder/backend/dt.py", line 60, in get_current_dtb_basename
    dtb_basename = query_variable_in_config_file("fdtfile", get_current_uenv_txt_path(storage_dir))
  File "/builder/tcbuilder/backend/dt.py", line 24, in get_current_uenv_txt_path
    assert os.path.exists(path), "panic: missing uEnv.txt in base image!"
AssertionError: panic: missing uEnv.txt in base image!

techniker@Feldberg:~/tcbworkdir$ torizoncore-builder dto list
error: missing device tree overlays directory 'device-trees/overlays' -- see dt checkout
techniker@Feldberg:~/tcbworkdir$ torizoncore-builder dt checkout
An unexpected Exception occured. Please provide the following stack trace to
the Toradex TorizonCore support team:


Traceback (most recent call last):
  File "/builder/torizoncore-builder", line 204, in <module>
    mainargs.func(mainargs)
  File "/builder/tcbuilder/cli/dt.py", line 43, in do_dt_checkout
    checkout_git_repo(storage_dir, None, None)
  File "/builder/tcbuilder/backend/common.py", line 331, in checkout_git_repo
    git_branch = get_branch_from_metadata(storage_dir)
  File "/builder/tcbuilder/backend/common.py", line 316, in get_branch_from_metadata
    src_sysroot = ostree.load_sysroot(src_sysroot_dir)
  File "/builder/tcbuilder/backend/ostree.py", line 44, in load_sysroot
    sysroot.load()
gi.repository.GLib.GError: g-io-error-quark: loading sysroot: opendir(/storage/sysroot): No such file or directory (1)

techniker@Feldberg:~/tcbworkdir$

Now I know it written in Python, but I can’t finished my project. Should I call somebody in Toradex and ask the questions in order to get support?

Best regard,
Dmitry

Please see the article on how to use device tree overlays with Torizon here: Device Tree Overlays on Torizon | Toradex Developer Center

Before running most commands in TorizonCore Builder you need to unpack a Torizon image as described by: TorizonCore Builder Tool - Customizing TorizonCore Images | Toradex Developer Center

Otherwise the tool doesn’t know what image base you are working on. That is what is causing the errors.

Then the overlay you need to apply should look something like this:

/dts-v1/;
/plugin/;

/ {
	compatible = "toradex,apalis-imx8x";
};

&flexcan2 {
	status = "okay";
};

This should enable the CAN interface on SODIMM pins 55/63.

Best Regards,
Jeremias

Tnank you, @jeremias.tx,

I’ve tried to follow your idea, but I think I did something wrong :frowning:

I’ve used command

  1. torizoncore-builder images download --remote-host 192.168.1.153 --remote-username torizon --remote-password xxx
  2. torizoncore-builder dt checkout

I’ve created file colibri-imx8x_can2_overlay.dts

 /dts-v1/;
 /plugin/;
 
 / {
     compatible = "toradex,colibri-imx8x";
 };
 
 &flexcan2 {
     status = "okay";
 };

and used

  1. torizoncore-builder dto apply device-trees/overlays/colibri-imx8x_can2_overlay.dts
  2. torizoncore-builder union dt_changes
  3. torizoncore-builder deploy --remote-host 192.168.1.153 --remote-username torizon --remote-password xxx --reboot

But ip link show command still displays only can0
How I can validate results of my changes?

Best regards,
Dmitry

The overlay worked on my setup and created a new can interface. Looking at your process the only thing I see that could be wrong is that in the final deploy command you didn’t specify your union branch dt_changes.

But I can guarantee at least from my own testing that your overlay is correct.

Best Regards,
Jeremias

@jeremias.tx ,

Yes, it’ possible, it was strange for me, what the command
cd /sysroot/boot/ostree/torizon-*/dtb/

moved to the directory:
colibri-imx8x-06789119:/sysroot/boot/ostree/torizon-c685d42cd306e142b153527dd4673a063d67dc0f96f29e81edc7d36d8a1d68ee/dtb$

May be it’s a checksum of the new branch?

The TorizonCore Builder tool should create a new deployment on the system with your changes. This is what gets deployed to the device via the deploy command.

Are you still having issues enabling the CAN on your setup?

Best Regards,
Jeremias

Tnanx @jeremias.tx,

Now I have can1 in the system!
Tomorrow I’m in office, will remove jumpers and test it.

The next step is to build an image for deploying into another devices.

And one question more: if I install this imx8x on Violaboard (without CAN controller) - does appier an on-processor flexcan as CAN1 or CAN0? Do I have a different setup for systems on Viola and Colibri Evaluation Board?

Best Regards,
Dmitry

That’s great to hear you got it up and running. With regards to to how the CAN interfaces will be numbered. On a carrier with no CAN controller the on-processor flexcan will be initialized as CAN0. In short the kernel will initialize CAN interfaces in order as they exist.

If you need a consistent name for a particular CAN interface you can try creating a udev rule as described here: CAN (Linux) | Toradex Developer Center

Best Regards,
Jeremias

@jeremias.tx ,

  1. So I have to create a file with rules for all Can devices I need?
    If I add only one device in this file, I’ll get only one can in the system?

    udevadm info -a -p $(udevadm info -q path -p /sys/class/net/can1)

returns:
looking at parent device ‘//devices/platform/bus@5a000000/5a8e0000.can’:
KERNELS==“5a8e0000.can”
SUBSYSTEMS==“platform”
DRIVERS==“flexcan”
ATTRS{suppliers}==“regulator.1”
ATTRS{driver_override}==“(null)”
ATTRS{consumers}==“”

So the rule with only one row
KERNELS==“5a8e0000.can”, ACTION==“add”, NAME=“CAN2”
garanties only one CAN2 device?

  1. Is this ID (5a8e0000.can) uniqe for all colibri-imx8X or different for different devices/OS versions?

  2. Could you guide me how (if it’s possible) to deploy all this hardware changes on many devices? We have only a propotype at the miment and we have to adopt it for using with Viola-board with additional CAN-Transmitter, but in the future we hope to sell more systems.

Best Regards,
Dmitry

All a udev rule does is overwrite the default behavior of the kernel. The rule only applies for devices you specify. Meaning if you have 2 CAN devices and only write a rule for one, then the other CAN device will just follow the default behavior of the kernel.

This “5a8e0000.can” is the ID of a that specific CAN bus. This should be the same for each SoC. Meaning all i.MX8QXP based devices have their flexcan2 interface identified by “5a8e0000.can”. This is defined in the device tree by NXP themselves.

Could you guide me how (if it’s possible) to deploy all this hardware changes on many devices?

Are you asking how to create a software image you can flash to other devices?

For this you can use TorizonCore Builder: Capturing Changes in the Configuration of a Board on Torizon OS | Toradex Developer Center

As described in the link above you can capture device tree and configuration changes then produce a package that can be flashed with Toradex Easy Installer.

Best Regards,
Jeremias