Device Tree Overlays Torizon imx7 CAN bus, can0 not found

Good morning,
I am new with embedded linux and SoM world in general, I probably do not have enough background to understand properly what I am trying to do.

As an experiment, I would like to enable CAN bus on my module imx7 colibri mounted on iris v2.0, from “How to Use CAN on TorizonCore” I understand that this device does not have a CAN transceiver, so I am gonna add an external transcriver.

But the problem that I am facing is that I do not properly understand how Device tree overlay works with Torizon, it seems to be too over-complicated and poorly explained in details, the tutorials just give some little examples but they are not enough to really understand in deep what is going on with all the tools provided (in my opinion).

What I did so far is creating a device tree overlay as explained in “CAN (Linux)” .dts that contains:

/dts-v1/;
/plugin/;

/ {
	compatible = "toradex,colibri-imx7d",
		     "toradex,colibri-imx7s";
};

&flexcan1 {
	status = "okay";
};

&iomuxc {
	pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3 &pinctrl_gpio5>;
};

and upload it with my host machine using:

torizoncore-builder dto deploy --remote-host 192.168.1.33  --remote-username torizon --remote-password <password> --force --reboot device-trees/overlays/imx7_canbus.dts

This runs and performs without any error the compilation and deploy the “ostree” on the device, but then the device does not boot and after 3 failed boot it rollback to the older version and starts.

Next I tried the solution proposed by this kind user " How to enable flexcan1 and flexcan2 on colibri imx7?? - Toradex Community ", making an overlay with:

/dts-v1/;
/plugin/;

/ {
	compatible = "toradex,colibri-imx7d",
		     "toradex,colibri-imx7s";
};

&flexcan1 {
	status = "okay";
};

&iomuxc {
	pinctrl_gpio7: gpio7-grp { /* Alternatively CAN1 */
		fsl,pins = <
		
		>;
	};
	
	pinctrl_flexcan1: flexcan1-grp {
		fsl,pins = <
			MX7D_PAD_ENET1_RGMII_RD3__FLEXCAN1_TX	0x59 /* SODIMM 55 */
			MX7D_PAD_ENET1_RGMII_RD2__FLEXCAN1_RX	0x59 /* SODIMM 63 */
		>;
	};
};

But once I load this, the error is:

Downloading image from: https://artifacts.toradex.com/artifactory/torizoncore-oe-prod-frankfurt/dunfell-5.x.y/release/1/colibri-imx7-emmc/torizon-upstream/torizon-core-docker/oedeploy/torizon-core-docker-colibri-imx7-emmc-Tezi_5.1.0+build.1.tar

The download may take some time. Please wait...
Download Complete!

Unpacking Toradex Easy Installer image.
Copying Toradex Easy Installer image.
Unpacking TorizonCore Toradex Easy Installer image.
Importing OSTree revision 423f8b8c528c61d7846fdee6e9bfb9505246ac2843493a397391681b2b44666d from local repository...
0 metadata, 0 content objects imported; 0 bytes content written
Unpacked OSTree from Toradex Easy Installer image:
  Commit checksum: 423f8b8c528c61d7846fdee6e9bfb9505246ac2843493a397391681b2b44666d
  TorizonCore Version: 5.1.0+build.1
'device-trees' directory already exists
Error: device-trees/overlays/colibri-imx7_canbus.dts:25.4-5 syntax error
FATAL ERROR: Unable to parse input tree
error: cannot apply device-trees/overlays/colibri-imx7_canbus.dts.

What I am missing?
Where I can find some good explanation of what is going on without spending years reversing some code?

Greetings @zobeer,

I believe I know what’s going on here. So let’s look at the first overlay as I believe that one is close to working. When working with device tree overlays it’s important to be mindful of the source device tree that you’re overlaying on top of.

For reference the source file I’m looking at is here: http://git.toradex.com/cgit/linux-toradex.git/tree/arch/arm/boot/dts/imx7-colibri.dtsi?h=toradex_5.4.y

You set flexcan1 to “okay” which is fine. However you then redefine pinctrl-0 in iomuxc to free up the pins for CAN so that there’s no conflict. Compared to the source tree I noticed a discrepancy here. The default definition of pinctrl-0 is:

 pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3 &pinctrl_gpio4
		     &pinctrl_gpio7>;

In your overlay you redefined it to:

pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3 &pinctrl_gpio5>;

In the device tree we see the pins for CAN1 are used by pinctrl_gpio7 so it’s good that you removed it to free those pins. However you also added pinctrl_gpio5, which doesn’t seem to exist anywhere. Probably the overlay you referenced in our article is outdated or refers to a different branch of the kernel. This might be why you’re having booting issues after applying this overlay

Alright so try changing your pinctrl-0 to this:

pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3>;

This should free up the pins for both CAN1 and CAN2. Furthermore if you continue to have issues can you share the exact output of the “failed boot”, perhaps there’s something useful there.

Best Regards,
Jeremias

Great, it solved the booting problem and I can see the interface can0, unfortunately, I’m sick in home and can not test it with the transceiver.

I was using as reference imx7-colibri.dtsi a file contained in your repository suggested in one of the tutorials: " https://github.com/toradex/device-trees/blob/toradex_5.4-2.1.x-imx/dts-arm32/imx7-colibri.dtsi ", but looks like it is deprecated, shall I open an issue/pull request on github or you can do it?
I will use the repository you suggested for further modification of my device tree overlays.

Kind regards
Zobeer

Ok I think I see where the confusion happened. So on Torizon for the i.MX7 we use the mainline based branch toradex_5.4.y. I believe you were looking at the branch toradex_5.4-2.1.x-imx branch which we do use on our non-Torizon BSP. This kernel is based on a downstream kernel from NXP, which has it’s differences.

I’d recommend consulting the matrix here: https://developer.toradex.com/knowledge-base/embedded-linux-release-matrix

Just to always make sure you’re working with and referencing the correct branch of our kernel.

Best Regards,
Jeremias

Thanks for the very well documented solution, @jeremias.tx.

We hope you get better anytime soon, @zobeer, then we’ll be waiting for your feedback on this topic.