1 1
shigeki

BananaPi CanBus not working

Recommended Posts

Armbianmonitor:

Hi again.

 

After 2 years i want to try configure CanBus on BananaPi and still nothing.  I'm continuing my previous post

 

What i do:

1) Paths dtb with this instruction :

2) Load kernel modules:

# lsmod | grep can
can_raw                20480  1
can_bcm                24576  0
can                    20480  2 can_raw,can_bcm
sun4i_can              16384  0
can_dev                20480  1 sun4i_can

3) Spawn can0 interface

# ip link set can0 type can bitrate 500000 restart-ms 100 triple-sampling on loopback on
# ip link set up can0 

4) Play with candump / cansend

 

On loopback my messages show in candump, but on arduino receiver still nothing

 

My test env:

Two arduino uno with mcp2515 + tja1050 - one as sender other as receiver

BananaPi 4.19.62-sunxi and tja1051 transceiver

 

Bitrate on all boards set to 500k

 

Maybe this may be helpful:

# ip -det link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0
    can <LOOPBACK,TRIPLE-SAMPLING> state ERROR-WARNING (berr-counter tx 0 rx 129) restart-ms 100
	  bitrate 500000 sample-point 0.875
	  tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  sun4i_can: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 24000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
# dmesg | grep can
[    8.090861] sun4i_can 1c2bc00.can: device registered (base=(ptrval), irq=53)
[    8.120057] can: controller area network core (rev 20170425 abi 9)
[    8.128499] can: broadcast manager protocol (rev 20170425 t)
[    8.132629] can: raw protocol (rev 20170425)
[ 3502.151374] sun4i_can 1c2bc00.can can0: bus-off
[ 3502.255288] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3507.633774] sun4i_can 1c2bc00.can can0: bus-off
[ 3507.735553] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3509.316187] sun4i_can 1c2bc00.can can0: bus-off
[ 3509.419665] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3510.275698] sun4i_can 1c2bc00.can can0: bus-off
[ 3510.388158] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3518.457783] sun4i_can 1c2bc00.can can0: bus-off
[ 3518.560252] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3520.323530] sun4i_can 1c2bc00.can can0: bus-off
[ 3520.710972] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3522.219241] sun4i_can 1c2bc00.can can0: bus-off
[ 3522.320498] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3523.602391] sun4i_can 1c2bc00.can can0: bus-off
[ 3523.704584] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready

 

Share this post


Link to post
Share on other sites

So, i finally manege this to work.

 

Tested on newest kernel :

Linux bananapi 5.4.26-sunxi #20.02.5 SMP Thu Mar 19 22:23:40 CET 2020 armv7l GNU/Linux

First, you need to patch dtb :

# cd /boot/dtb-5.4.26-sunxi

# diff sun7i-a20-bananapi.dts sun7i-a20-bananapi.dts.bak
710c710,716
< 			can0_pins_a: can0@0 {
---
> 			can-pa-pins {
> 				pins = "PA16\0PA17";
> 				function = "can";
> 				phandle = < 0x63 >;
> 			};
>
> 			can-ph-pins {
713d718
< 				linux,phandle = < 0x64 >;
1446,1447c1451
< 			status = "okay";
< 			linux,phandle = < 0xb0 >;
---
> 			status = "disabled";
1449,1450d1452
< 			pinctrl-names = "default";
< 			pinctrl-0 = <&can0_pins_a>;
1862c1864,1865
< 		can0_pins_a = "/soc/pinctrl@1c20800/can0@0";
---
> 		can_pa_pins = "/soc/pinctrl@1c20800/can-pa-pins";
> 		can_ph_pins = "/soc/pinctrl@1c20800/can-ph-pins";

 

And in my test environment (two Arduino with mcp2515 CAN Module  receiver and sender ) and bananapi i had to set baud rate 125K on banana pi and 250K on Arduino sender/receiver.

Share this post


Link to post
Share on other sites
On 4/4/2020 at 7:38 PM, shigeki said:

So, i finally manege this to work.

 

Tested on newest kernel :


Linux bananapi 5.4.26-sunxi #20.02.5 SMP Thu Mar 19 22:23:40 CET 2020 armv7l GNU/Linux

First, you need to patch dtb :


# cd /boot/dtb-5.4.26-sunxi

# diff sun7i-a20-bananapi.dts sun7i-a20-bananapi.dts.bak
710c710,716
< 			can0_pins_a: can0@0 {
---
> 			can-pa-pins {
> 				pins = "PA16\0PA17";
> 				function = "can";
> 				phandle = < 0x63 >;
> 			};
>
> 			can-ph-pins {
713d718
< 				linux,phandle = < 0x64 >;
1446,1447c1451
< 			status = "okay";
< 			linux,phandle = < 0xb0 >;
---
> 			status = "disabled";
1449,1450d1452
< 			pinctrl-names = "default";
< 			pinctrl-0 = <&can0_pins_a>;
1862c1864,1865
< 		can0_pins_a = "/soc/pinctrl@1c20800/can0@0";
---
> 		can_pa_pins = "/soc/pinctrl@1c20800/can-pa-pins";
> 		can_ph_pins = "/soc/pinctrl@1c20800/can-ph-pins";

 

And in my test environment (two Arduino with mcp2515 CAN Module  receiver and sender ) and bananapi i had to set baud rate 125K on banana pi and 250K on Arduino sender/receiver.

Thank you! This is helpful.

Share this post


Link to post
Share on other sites

Hi Hans,
what is the difference compared to the previous entry from shigeki ?


 

 

 

Share this post


Link to post
Share on other sites

@wollik: Sorry for the delay. Shikegis changes pointed me in the right direction. I wanted to express that.

 

CAN is indeed working with the current stable Armbian version on BananaPi M1:

 

root@bananapi:~/dtb# cat /etc/armbian-release
# PLEASE DO NOT EDIT THIS FILE
BOARD=bananapi
BOARD_NAME="Banana Pi"
BOARDFAMILY=sun7i
BUILD_REPOSITORY_URL=https://github.com/armbian/build
BUILD_REPOSITORY_COMMIT=eb9dad92
DISTRIBUTION_CODENAME=buster
DISTRIBUTION_STATUS=supported
VERSION=20.05.2
LINUXFAMILY=sunxi
BRANCH=current
ARCH=arm
IMAGE_TYPE=stable
BOARD_TYPE=conf
INITRD_ARCH=arm
KERNEL_IMAGE_TYPE=Image

I have just changed the pins in the dtb overlay file, which looks like that now:

 

root@bananapi:~/dtb# cat sun7i-a20-can.dts 
/dts-v1/;

/ {
	compatible = "allwinner,sun7i-a20";

	fragment@0 {
		target = < 0xffffffff >;

		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = < 0xffffffff >;
			status = "okay";
		};
	};

	__fixups__ {
		can0 = "/fragment@0:target:0";
		can_ph_pins = "/fragment@0/__overlay__:pinctrl-0:0";
	};
};

I have added this overlay as user overlay with armbian-add-overlay sun7i-a20-can.dts and rebooted.

As my hardware requires a 500 kBit setting, I use this as setup:

modprobe can_raw
ip link set can0 type can bitrate 500000 triple-sampling on 
ifconfig can0 up

 

Btw. dynamic loading of the overlay at runtime works as well.

Share this post


Link to post
Share on other sites

Hi Hans,
how did you activate/bind the overlay ?

 

I get this eror:
 

sudo armbian-add-overlay sun7i-a20-can.dts
Error: dtc does not support compiling overlays

 

Regards
Wolfgang

Share this post


Link to post
Share on other sites
18 hours ago, wollik said:

Hi Hans,
how did you activate/bind the overlay ?

 

I get this eror:
 

sudo armbian-add-overlay sun7i-a20-can.dts
Error: dtc does not support compiling overlays

 

Regards
Wolfgang

 

The dtc on my Bananapi did not complain about overlays. This is the version installed on my side:

 

root@bananapi:~# dtc --version
Version: DTC 1.4.7

 

Just try by hand to find out, what is going on:

root@bananapi:~/dtb# dtc  -I dts -O dtb -o sun7i-a20-can.dtbo sun7i-a20-can.dts

 

 

Share this post


Link to post
Share on other sites

If you do not succeed compiling the overlay directly on the BananaPi M1, you may do it anywhere else, if you have a working dtc there. Any Linux box with a dtc installed will do.

Share this post


Link to post
Share on other sites

Hi Hans,
I running an old Armbian version on my M1 that shows this older dtc version:


pi@hnet-fhem-203:~$ dtc --version
Version: DTC 1.4.2

 

My other BPI's (R1's) are upgradet to the latest buster version, where the CAN is enabled.
At the moment I can't upgrade my M1 to the latest version. I have to migrate the apps first, so I want to get the CAN working on my M1 with the informations patches and workarounds I found on the internet.

 

When I try to run it manualy like you suggested in your last message, I got this syntax error:

 

pi@hnet-fhem-203:/boot/dtb$ dtc  -I dts -O dtb -o sun7i-a20-can.dtbo sun7i-a20-can.dts
Error: sun7i-a20-can.dts:2.1-2 syntax error
FATAL ERROR: Unable to parse input tree
pi@hnet-fhem-203:/boot/dtb$ ls -l *can*
-rw-r--r-- 1 root root 356 Jul 22 21:40 sun7i-a20-can.dts

 

Like I said, on my M1 are runing applications so I don't trust to bring the dts version 1.4.7 from my R1 to the M1 and try to run it , not knowing what sideeffects that will cause bacause of the different Armbian releases.

 

There is no man entyr for dts, please can you help ?

 


Regards
WolliK

 

Share this post


Link to post
Share on other sites
On 7/17/2020 at 11:24 AM, Hans Heukenkamp said:

@wollik: Sorry for the delay. Shikegis changes pointed me in the right direction. I wanted to express that.

 

CAN is indeed working with the current stable Armbian version on BananaPi M1:

 


root@bananapi:~/dtb# cat /etc/armbian-release
# PLEASE DO NOT EDIT THIS FILE
BOARD=bananapi
BOARD_NAME="Banana Pi"
BOARDFAMILY=sun7i
BUILD_REPOSITORY_URL=https://github.com/armbian/build
BUILD_REPOSITORY_COMMIT=eb9dad92
DISTRIBUTION_CODENAME=buster
DISTRIBUTION_STATUS=supported
VERSION=20.05.2
LINUXFAMILY=sunxi
BRANCH=current
ARCH=arm
IMAGE_TYPE=stable
BOARD_TYPE=conf
INITRD_ARCH=arm
KERNEL_IMAGE_TYPE=Image

I have just changed the pins in the dtb overlay file, which looks like that now:

 


root@bananapi:~/dtb# cat sun7i-a20-can.dts 
/dts-v1/;

/ {
	compatible = "allwinner,sun7i-a20";

	fragment@0 {
		target = < 0xffffffff >;

		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = < 0xffffffff >;
			status = "okay";
		};
	};

	__fixups__ {
		can0 = "/fragment@0:target:0";
		can_ph_pins = "/fragment@0/__overlay__:pinctrl-0:0";
	};
};

I have added this overlay as user overlay with armbian-add-overlay sun7i-a20-can.dts and rebooted.

As my hardware requires a 500 kBit setting, I use this as setup:


modprobe can_raw
ip link set can0 type can bitrate 500000 triple-sampling on 
ifconfig can0 up

 

Btw. dynamic loading of the overlay at runtime works as well.

Hello,

 

I am not able to reproduce this.

apt update and apt upgrade

cat /etc/armbian-release: VERSION=20.05.2

sudo armbian-add-overlay sun7i-a20-can.dts works:

  Compiling the overlay
  Copying the compiled overlay file to /boot/overlay-user/
  Reboot is required to apply the changes

Reboot, but no can0 interface with

sudo ifconfig -a

 

jjf@bpi2:~$ dmesg | grep can

 

Joachim

 

 

Share this post


Link to post
Share on other sites
(edited)
On 7/24/2020 at 10:22 AM, wollik said:

Hi Hans,
I running an old Armbian version on my M1 that shows this older dtc version:


pi@hnet-fhem-203:~$ dtc --version
Version: DTC 1.4.2

 

My other BPI's (R1's) are upgradet to the latest buster version, where the CAN is enabled.
At the moment I can't upgrade my M1 to the latest version. I have to migrate the apps first, so I want to get the CAN working on my M1 with the informations patches and workarounds I found on the internet.

 

When I try to run it manualy like you suggested in your last message, I got this syntax error:

 

pi@hnet-fhem-203:/boot/dtb$ dtc  -I dts -O dtb -o sun7i-a20-can.dtbo sun7i-a20-can.dts
Error: sun7i-a20-can.dts:2.1-2 syntax error
FATAL ERROR: Unable to parse input tree
pi@hnet-fhem-203:/boot/dtb$ ls -l *can*
-rw-r--r-- 1 root root 356 Jul 22 21:40 sun7i-a20-can.dts

 

Like I said, on my M1 are runing applications so I don't trust to bring the dts version 1.4.7 from my R1 to the M1 and try to run it , not knowing what sideeffects that will cause bacause of the different Armbian releases.

 

There is no man entyr for dts, please can you help ?

 


Regards
WolliK

 

 

It looks like you would need to modify the actual DTB of your Armbian version on the M1. I suspect the overlay code cited here will not work with your Armbian version. It is a hint that the DTC compiler refuses to accept the dts file. You may want to check the CAN overlay that comes with exactly the Armbian version you run on your M1. That is certainly the best way to start.

 

 

Edited by Hans Heukenkamp
typo

Share this post


Link to post
Share on other sites
On 7/25/2020 at 4:53 PM, JoachimJF said:

Hello,

 

I am not able to reproduce this.

apt update and apt upgrade

cat /etc/armbian-release: VERSION=20.05.2

sudo armbian-add-overlay sun7i-a20-can.dts works:

  Compiling the overlay
  Copying the compiled overlay file to /boot/overlay-user/
  Reboot is required to apply the changes

Reboot, but no can0 interface with

sudo ifconfig -a

 

jjf@bpi2:~$ dmesg | grep can

 

Joachim

 

 

 

Do you use a BananaPi M1? The prompt indicates otherwise.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
1 1