Odd CAN MCP2515 behavior

Post Reply
magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Odd CAN MCP2515 behavior

Post by magicsmoke »

Hi.

I'm implementing CAN bus with my N2+

I've installed the MCP2515 as the guide states. Whenever I start the CAN controller, it starts to spam the BUS with data.

I've attached a couple of images of CAN_H diff CAN_L.

Image
Image

My linux version is Odroid's Ubuntu
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.2 LTS"
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"

root@odroid:~# cat /proc/version
Linux version 4.9.241-114 (root@builder_n2) (gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-6ubuntu2) ) #1 SMP PREEMPT Tue Apr 20 13:25:36 UTC 2021



If anyone could shed some light on what could be going wrong, i'm all ears.

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

I've managed to get the bus not to crash when setting the bus to listen-only mode.

It's listening fine, but once it tries to send something it just floods the BUS.

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

Did you follow this wiki page?
https://wiki.odroid.com/common/applicat ... io/can-bus

Did you see tons of garbage data from candump command after sending something?

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Hi there.

After a bunch of debugging it was a stupid hardware issue on my part on why the diff pair looked bad.

The problem is definitely something regarding software side on the n2+.

I believe it is something to do with the 8Mhz oscillator on the module.

Could you advise how I could change the parameter.

Attached is images of the scope decoding the CANbus correctly.

Also is attached candump where the ID is wrong and there is apparently no data..

Image

Image

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

The CAN adapter board what we used for testing also has a 8Mhz X-Tal oscillator.
Which parameters do you want to change?

BTW, because we have no experience of using CAN bus in the real world, our support must be very limited.
We just performed a loop-back test and simple direct connection test between two ODROID-N2 boards as described in the WiKi page.

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Ah,

That probably explains it then.. yeah it seems to be a common problem if the frequency is not the same..

Looking at the other thread of the CAN issues, the user there mentioned changing the spi-max-frequency to the oscillator frequency.

I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..

btw this isn't an odroid specific issue it seems, looks like rpi also has the same issue with mismatched frequencies.

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

Can you measure the stock default clock frequency of the SPI-CLK pin?

You don't need to compile kernel to adjust the SPI clock frequency probably.
We could increase it up to 100Mhz(72Mhz) on C4 and N2 boards from user land application software on the fly.
viewtopic.php?p=309474#p309474

User avatar
tobetter
Posts: 8193
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 475 times
Been thanked: 1281 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by tobetter »

magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Ill be able to check the frequency later.

Currently only able to try software fixes. I see I could update the can0.dtbo using DTC.

I'm trying to build the file but keep getting a syntax error.

Code: Select all

root@odroid:/# dtc -I dts -O dtb -o can0.dtbo can0.dts
Error: can0.dts:13.23-24 syntax error
FATAL ERROR: Unable to parse input tree

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>

/ {
	fragment@0 {
		target = <&spicc0>;

		__overlay__ {
			status = "okay";

			can0: can@0 {
				compatible = "microchip,mcp2515";
				gpio-irq = <&gpio GPIOX_3 GPIO_ACTIVE_LOW>;
				reg = <1>;
				spi-max-frequency = <8000000>;
				status = "okay";
			};
		};
	};
};
There might be some options to get it working if I can play around with this.

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

tobetter wrote:
Fri Jul 23, 2021 3:33 pm
magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

I attempted this already, had issues with getting toolchain installed, even though I followed the wiki instructions.

User avatar
tobetter
Posts: 8193
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 475 times
Been thanked: 1281 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by tobetter »

magicsmoke wrote:
Fri Jul 23, 2021 4:01 pm
tobetter wrote:
Fri Jul 23, 2021 3:33 pm
magicsmoke wrote:
Fri Jul 23, 2021 3:21 pm
I've not got too much experience with building new kernels and linux operating systems, so i'll try and see if that gets it to work..
FYI, if you need to change the spi-max-frequency, you do not need to build whole linux source tree of Hardkernel's stock 4.9 kernel. Only need to build the device tree overlay file which must can0.dtb if you have not changed anything yet.

At the top directory of the Linux kernel source tree run thiese commands replace /media/boot/dtbs/odroidn2/can0.dtbo with arch/arm64/boot/dts/amlogic/overlays/odroidn2/can0.dtbo.

Code: Select all

make odroidg12_defconfig
make dtbs
Please find the link to change the spi-max-frequency in the device tree overlay.
https://github.com/hardkernel/linux/blo ... n0.dts#L18

I attempted this already, had issues with getting toolchain installed, even though I followed the wiki instructions.
Can you share the error what you faced?

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

Hello Odroid,

After chatting with the developers of can-utils on github, it seems the driver on your kernel is broken.

Please see this comment https://github.com/linux-can/can-utils/ ... -886227639

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

It seems not to easy to find which part of the driver was broken.

@tobetter,
One quick question.
Is the meson-spicc and mcp251x drivers existing(working?) on your Ubuntu 21.04 + Kernel 5.11 or 5.13 image?

User avatar
tobetter
Posts: 8193
Joined: Mon Feb 25, 2013 10:55 am
languages_spoken: Korean, English
ODROIDs: Many
Location: Paju, South Korea
Has thanked: 475 times
Been thanked: 1281 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by tobetter »

odroid wrote:
Mon Jul 26, 2021 10:12 am
It seems not to easy to find which part of the driver was broken.

@tobetter,
One quick question.
Is the meson-spicc and mcp251x drivers existing(working?) on your Ubuntu 21.04 + Kernel 5.11 or 5.13 image?
MCP251x driver is with Linux kernel 5.11 and 5.13 as a module and can0.dtbo is also there.

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

@tobetter, Glad to hear that.

@magicsmoke, Please try tobetter's Ubuntu 21.04 + Kernel 5.13 image if you don't mind.
viewtopic.php?f=52&t=42300

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

odroid wrote:
Mon Jul 26, 2021 10:12 am
It seems not to easy to find which part of the driver was broken.
https://github.com/linux-can/can-utils/ ... -886494801

Here is an explanation of what is wrong with your driver.
odroid wrote:
Mon Jul 26, 2021 2:01 pm
@tobetter, Glad to
@magicsmoke, Please try tobetter's Ubuntu 21.04 + Kernel 5.13 image if you don't mind.
viewtopic.php?f=52&t=42300
I'll give that image a try.

cap00k
Posts: 117
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID
Has thanked: 0
Been thanked: 18 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by cap00k »

Hi, @magicsmoke

I tried modifying the CAN bus clock. Can you apply and test this?
It can be applied by unzip and copying the can0.dtbo file.

Code: Select all

unzip odroidn2_can_bus.zip
mv /media/boot/amlogic/overlays/odroidn2/can0.dtbo /media/boot/amlogic/overlays/odroidn2/can0-orig.dtbo
cp ./can0.dtbo /media/boot/amlogic/overlays/odroidn2/can0.dtbo
sync
reboot
After reboot, you can check as below.

Code: Select all

root@odroid:~# ip -det link show can0
3: can0: <NOARP,ECHO> mtu 16 qdisc fq_codel state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can <LOOPBACK> state STOPPED restart-ms 0 
	  bitrate 125000 sample-point 0.875 
	  tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 12000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
can0.dts file is as follows:

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/meson-g12a-gpio.h>
#include <dt-bindings/gpio/gpio.h>

/ {
	fragment@0 {
		target-path = "/";
		__overlay__ {
			can_clk: can-clk {
				compatible = "fixed-clock";
				clock-frequency = <24000000>;
				clock-output-names = "can_clk";
				#clock-cells = <0>;
			};
		};
	};

	fragment@1 {
		target = <&spicc0>;

		__overlay__ {
			status = "okay";

			can0: can@0 {
				compatible = "microchip,mcp2515";
				reg = <1>;
				clocks = <&can_clk>;
				gpio-irq = <&gpio GPIOX_3 GPIO_ACTIVE_LOW>;
				spi-max-frequency = <10000000>;
				status = "okay";
			};
		};
	};
};
Attachments
odroidn2_can_bus.zip
(990 Bytes) Downloaded 6 times
These users thanked the author cap00k for the post:
magicsmoke (Thu Jul 29, 2021 1:30 am)

magicsmoke
Posts: 9
Joined: Mon Jul 19, 2021 2:14 am
languages_spoken: english
ODROIDs: N2+
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Odd CAN MCP2515 behavior

Post by magicsmoke »

cap00k wrote:
Wed Jul 28, 2021 2:16 pm
I tried modifying the CAN bus clock. Can you apply and test this?
You genius.

I had actually tried something along the lines of your can0.dbs configuration.

Turns out, the new can0.dtbo needed also to go in /media/boot not /boot.... Didn't know that...

Works now!! on HardKernel's ubuntu build of 20.04, 4.9.241-114.

Code: Select all

root@odroid:~# ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0
    can <TRIPLE-SAMPLING> state ERROR-PASSIVE restart-ms 0
          bitrate 100000 sample-point 0.875
          tq 625 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
          mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
          clock 8000000 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

root@odroid:~# candump any
  can0  1F4   [2]  03 00
  can0  1F4   [2]  04 00
  can0  1F4   [2]  05 00
  can0  1F4   [2]  06 00
  can0  1F4   [2]  00 01
  can0  1F6   [5]  00 00 00 00 00
  can0  1F4   [2]  01 01
  can0  1F4   [2]  02 01
  can0  1F6   [5]  01 00 00 00 00
  can0  1F4   [2]  03 01
  can0  1F6   [5]  02 00 00 00 00
  can0  1F4   [2]  04 01
  can0  1F4   [2]  05 01
  can0  1F4   [2]  06 01
  can0  1F4   [2]  00 00
  can0  1F4   [2]  01 00
  can0  1F4   [2]  02 00
  can0  1F4   [2]  03 00
  can0  1F6   [5]  00 00 00 00 00
  can0  1F4   [2]  04 00
  can0  1F6   [5]  01 00 00 00 00
  can0  1F4   [2]  05 00
  can0  1F4   [2]  06 00
  can0  1F6   [5]  02 00 00 00 00
  can0  1F4   [2]  00 01
  can0  1F4   [2]  01 01


These users thanked the author magicsmoke for the post:
odroid (Thu Jul 29, 2021 9:21 am)

User avatar
odroid
Site Admin
Posts: 37793
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean
ODROIDs: ODROID
Has thanked: 1919 times
Been thanked: 1186 times
Contact:

Re: Odd CAN MCP2515 behavior

Post by odroid »

Thank you for the confirmation.
We will merge the patch and release a new Kernel update package soon.

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 7 guests