CAN on the A20-OLinuXino-MICRO with the normal Linux kernel [SOLVED]

Started by johannes.pfister, October 25, 2023, 12:02:52 AM

Previous topic - Next topic

johannes.pfister

Can you help me using CAN on the A20-OLinuXino-MICRO-e4Gs16M with the normal Linux kernel?

TL;DR: I tried to add the CAN interface like described here. There is a can0 interface, it can be configured with the ip command but it doesn't receive anything nor does it send anything (checked with a oscilloscope). What must be done so the it can communicate with CAN?

--------------------------

I currently have many A20-OLinuXino-MICRO-e4Gs16M boards that use a recommended OLinuXino image from here where CAN works. But i would like to use buildroot in the future instead.

I tried to use the buildroot defconfig olimex_a20_olinuxino_micro_defconfig it works somewhat, but CAN doesn't work. iproute2 and other tools for CAN where added but can0 didn't show up with ipconfig -a nor ip a s . So i tried to steps described here:

- A linux-sunxi branch does not exist in the Linux kernel. So i used the 6.1.9 version with the sunix defconfig (but disabled CONFIG_MODULES) and the sun7i-a20-olinuxino-micro.dts .

- The arch/arm/boot/dts/sun7i-a20.dtsi file can be modified to add the can0_pins_a: can0@0 section. The line numbers don't work and have to be different but this is probably not a problem? The can0: can@01c2bc00 section already exist, with the same values (but sometimes with names instead of values).

- The arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts can be edited as described.

Doing this modifications to the dts and dtsi files made can0 appear in ifconfig. Enabling it via this commands:

ip link set can0 down
ip link set can0 type can bitrate 125000 triple-sampling on loopback off
ip link set can0 up

makes it possible to use can0 with candump and cansend. But no packets from other CAN nodes are received and no data is send from the A20 (confirmed with a oscilloscope measuring CAN_TX and CAN_RX).

How to send CAN frames so that they are actually send to the bus and how to receive CAN frames from the bus?

LubOlimex

I believe it should work with the default unmodified Olimage image if you enable it from the overlays. Did you try the overlays man? Type olinuxino-overlay - here is the option in overlays:

https://imgur.com/a/JDgTDZz
Technical support and documentation manager at Olimex

johannes.pfister

Thanks for your answer. But i don't really understand it.


Quote from: LubOlimex on October 25, 2023, 08:26:17 AMType olinuxino-overlay

Where exactly should that be typed?
On the host where i compile the Linux kernel? Or on the Olimex SBC? I didn't find any such program/command.

I didn't find the string nor file 'sun7i-a20-can-pa' or 'olinuxino-overlay' in buildroot nor in this git project, except the 'olinuxino-overlay' in the mentioned git project. But as string and not as file or command, so no idea how to run it.



LubOlimex

On the Olimex board in the command line as root, the board should be running the latest official Olimage. Refer to this document:

https://github.com/OLIMEX/OLINUXINO/blob/master/DOCUMENTS/OLIMAGE/Olimage-guide.pdf

About the source of olinuxino-overlay check here:

https://github.com/OLIMEX/olinuxino-overlays/tree/master/sun7i-a20
Technical support and documentation manager at Olimex

johannes.pfister

Quote from: LubOlimex on October 25, 2023, 02:59:36 PMlatest official Olimage

QuoteI currently have many A20-OLinuXino-MICRO-e4Gs16M boards that use a recommended OLinuXino image from here where CAN works. But i would like to use buildroot in the future instead.

While CAN works on the OLinuXino image, i would like to use something a bit more fine tuned for some of our machines. For that i need a kernel which i can reconfigure and recompile and i would like to avoid the full blown Debian based system.

For that i use buildroot, which has a olimex_a20_olinuxino_micro_defconfig . The board works in general, but CAN doesn't work there.

So how to configure the Linux source in order to make CAN work?

I tried the steps you described here: https://www.olimex.com/wiki/A20-CAN#For_Mainline_kernel but they don't work (can0 shows up, but the hardware doesn't work).

What do i miss? How can i make can work?

LubOlimex

Ignore the wiki article for now since it doesn't apply to Olimage.

If A20-CAN works with Olimage, just look at Olimage sources at our GitHub and see what've done for the CAN and try to copy it to your image. Mainly focus on the last two links I've shared where there are more details about the build process and locations of Olimage sources.
Technical support and documentation manager at Olimex

johannes.pfister

Quote from: LubOlimex on October 26, 2023, 08:48:19 AMIgnore the wiki article for now since it doesn't apply to Olimage.

Do you say the wikiarticle is wrong?
I don't want to use Olimage for this application, since it is too large and has a full blown Debian system.

Quote from: LubOlimex on October 26, 2023, 08:48:19 AMjust look at Olimage sources at our GitHub and see what've done for the CAN and try to copy it to your image

Tried that, but i don't really understand how this works.

Quote from: LubOlimex on October 26, 2023, 08:48:19 AMMainly focus on the last two links I've shared where there are more details about the build process and locations of Olimage sources.

One of them is a PDF with instruction how to use Olimage, rather than compiling, so not sure how that would help. The other one has dts files that add, as far as i understand, the same as in the wikiarticle (and more, for stuff not related to CAN).

The only thing i fund there, of which i understand should be relevant, are the links in the PDF, such as to here: https://github.com/OLIMEX/olimage/blob/master/build.sh but i don't understand enough of it to use it.

But then again, i don't really understand enough about this topic.

LubOlimex

QuoteDo you say the wikiarticle is wrong?

No. I say it applies the the previous iterration of Linux images. The information at the wiki doesn't apply to Olimage and it is not what we've done in Olimage.

QuoteOne of them is a PDF with instruction how to use Olimage, rather than compiling, so not sure how that would help.

Well, at the end of that PDF there is a chapter called building Olimage, there is chapter with links and resources, and so on...

QuoteThe other one has dts files that add, as far as i understand, the same as in the wikiarticle (and more, for stuff not related to CAN).

QuoteBut then again, i don't really understand enough about this topic.

That is too bad. In your case it might be better idea to just Olimage Linux as basis and apply the changes you want to it. That is why we made it in first place, so people that don't know stuff can have most of the hardware working out-of-the-box.

Alternatively, consider hiring embedded Linux professional that can transfer the CAN dts and related packages and settings from Olimage and recompile your image.
Technical support and documentation manager at Olimex

johannes.pfister

#8
Ok, now it works. It turns out:

-  the can0_pins_a: can0@0 sections should not be added to the arch/arm/boot/dts/sun7i-a20.dtsi file. Instead, use the can_ph_pins: can-ph-pins section that is already there. No idea why the can_ph_pins: can-ph-pins as described in the wikiarticle (here:  https://www.olimex.com/wiki/A20-CAN#For_Mainline_kernel) didn't work.

- The only thing that have to be changed in the dts files is adding this at the end of
arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts:

&can0
  {
      pinctrl-names = "default";
      pinctrl-0 = <&can_ph_pins>;
      status = "okay";
  };

Note that it uses can_ph_pins and not can0_pins_a as mentioned in the wiki.

Other notes: I use the Kernel version 6.1.9. I disabled dynamic module loading in the kernel (CONFIG_MODULES). Other than that, sun7i-a20-olinuxino-micro.dts (maybe sun7i-a20-olinuxino-micro-emmc.dts also works) has to be used. Everything else comes from the sunix_defconfig.


johannes.pfister

#9
It would help when you would mentioned the kernel versions that work with your wikiarticle in your wikiarticle. Or even better, add a new section for newer kernel version to use can_ph_pins instead of adding can0_pins_a: can0@0


Since we payed a few 1000 € for your boards already, i was expecting a bit better support, especially since the solutions turned out to be so simple.
Anyway.

LubOlimex

Thanks for the update glad you got it solved. CAN pins can be located on either PH or PA depending on the exact Olimex board and where the A20-CAN is connected.

Sorry if my replies sound unprofessional, but put yourself in our shoes. Our software support is limited, we can't support customizing thousands of customers for myriads of hardware and software configurations. It doesn't matter if you purchased Olmex boards for 100 or 100000 Euro situation would be the same. Even trying to help or respond for this type of software issues is more compared to what other companies dealing with embedded Linux boards would do. If it is a simple issue that we can spot or we have experience with - sure we can help. Even when it is not that simple we can point you in some direction, but situations that go like please make hardware A work with hardware B on my board running custom software C, is simply not possible. We don't have the capacity to do it. Especially when that exact config is running fine in Olimage which can be studied, copied, and used as basis.
Technical support and documentation manager at Olimex

johannes.pfister

My point was: You have a wikiarticle, and from your own software (olimage) you know you have to use a different way for newer kernels than described in this article. Why don't you update your wikiarticle to either include how it can be used (adding the 5 lines to arch/arm/boot/dts/sun7i-a20-olinuxino-micro.dts as mentioned in my comment), or at least mentioned that it will not work with newer kernels? Before your customers waste a lot of hours then ask you and only then you are telling them to look somewhere else.

QuoteCAN pins can be located on either PH or PA depending on the exact Olimex board and where the A20-CAN is connected.

In this case, it was always PH20 and PH21, or PH (not sure what PH and PA stands for).


JohnS