Daniel Posted February 21, 2016 Posted February 21, 2016 Hello, I want to use SocketCan on the Banana Pi / Allwinner A20 with the internal CAN interface. I have tested my hardware in the past using can4linux and also have some experience with Socketcan and other interfaces. Configuarion: Armbian root@bananapi:/# uname -r4.4.1-sunxi loaded the can driver with "modprobe sun4i_can" results in "lsmod": Module Size Used bysun4i_can 5810 0can_dev 8307 1 sun4i_can And dmesg states: [ 2632.582992] CAN device driver interface But I do not get the can0 device up: root@bananapi:~# ip link set can0 up type can bitrate 500000Cannot find device "can0" There seems to be no can device detected by the sun4i_can: root@bananapi:~# cat /proc/net/devInter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 4307 60 0 0 0 0 0 0 4307 60 0 0 0 0 0 0 eth0: 929191 13067 0 0 0 0 0 0 871467 4282 0 0 0 0 0 0 bond0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Did someone else try canbus and got it running? Thanks, Daniel
bertc3p0 Posted February 23, 2016 Posted February 23, 2016 (edited) Hi Daniel, I'm using CAN-Bus successfully on Bpi. You need some simple patches for the DT: ./armbian/userpatches/kernel/sunxi-next % cat 800-dt-sun7i-add-can.patch --- a/arch/arm/boot/dts/sun7i-a20.dtsi 2015-09-28 11:34:05.383525775 +0200 +++ b/arch/arm/boot/dts/sun7i-a20.dtsi 2015-09-28 11:58:11.720217304 +0200 @@ -890,6 +890,13 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; }; + can0_pins_a: can0@0 { + allwinner,pins = "PH20","PH21"; + allwinner,function = "can"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + }; + i2c0_pins_a: i2c0@0 { allwinner,pins = "PB0", "PB1"; allwinner,function = "i2c0"; @@ -1334,6 +1341,16 @@ #size-cells = <0>; }; + can0: can@01c2bc00 { + compatible = "allwinner,sun4i-a10-can"; + reg = <0x01c2bc00 0x400>; + interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&apb1_gates 4>; + status = "disabled"; + #address-cells = <1>; + #size-cells = <0>; + }; + i2c4: i2c@01c2c000 { compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; reg = <0x01c2c000 0x400>; ./armbian/userpatches/kernel/sunxi-next % cat bananapix-add_can.patch --- a/arch/arm/boot/dts/sun7i-a20-bananapi.dts 2016-02-16 13:04:24.322060998 +0100 +++ b/arch/arm/boot/dts/sun7i-a20-bananapi.dts 2016-02-16 13:48:38.457387549 +0100 @@ -106,6 +106,12 @@ status = "okay"; }; +&can0 { + pinctrl-names = "default"; + pinctrl-0 = <&can0_pins_a>; + status = "okay"; +}; + &codec { status = "okay"; }; Compile your armbian and everything runs fine ;-) Regards Gerd Edited February 26, 2016 by wildcat_paris added spoiler 1
Eric Posted March 6, 2016 Posted March 6, 2016 Daniel, did you ever manage to get can bus working? I tried with my banana pi, building my own armbian 5.05 (trusty) image with the patches provided above, but I have the same issue; "Cannot find device "can0"". I can however see the device in the device tree: /proc/device-tree/soc@01c00000/can@01c2bc00. For anyone else looking at this, I was able to find my issue; with the consolidation of the BananaPi and the BPI-Pro in the armbian build tools, you need to patch the bananapipro device tree, not just the plain bpi device tree. This patch is what I used to patch the device tree in the 4.4 kernel
Daniel Posted March 13, 2016 Author Posted March 13, 2016 Hello Eric, I tested my hardware using Can4Linux, which you can get easily running on the banana pi so I know, everything is working well. Just reading your replay and the one of Gerd i'm trying to compile the latest 4.4.x kernel. Gerd, your patches seem to include all needed information, but cannot be directly applied to the latest kernel any more. Only using the one patch from Eric is missing some information, but when I download all 3 patches from that site: "https://github.com/GBert/sunxi-can-driver",to userpatches/kernel/sunxi-next the kernel compiles. I hope to find some time within the next week to install the kernel and test can. I will post an update. Daniel
Daniel Posted March 15, 2016 Author Posted March 15, 2016 Hello, I just tested the compiled kernel and CAN is working. Thanks for all your hints. Daniel 1
vaibhavkambli1993 Posted November 23, 2016 Posted November 23, 2016 can anyone suggest should I start with can4linux or socketcan for can bus configuration in banana pro?
Franz Posted February 25, 2017 Posted February 25, 2017 Hello, I want to use socketcan with kernel 4.9.12. Is it still necessary to compile kernel with patches? Directories in https://github.com/GBert/sunxi-can-driverare marked as obsolete. And patches are even older. I tried to use fex, but was not successful. Command: /sbin/ifconfig -1 does not show a can device. Connecting a PEAK USB-CAN dongle displays CAN0.
bertc3p0 Posted February 26, 2017 Posted February 26, 2017 Hi Franz, Hello, I want to use socketcan with kernel 4.9.12. Is it still necessary to compile kernel with patches? Directories in https://github.com/GBert/sunxi-can-driverare marked as obsolete. And patches are even older. I tried to use fex, but was not successful. Command: /sbin/ifconfig -1 does not show a can device. Connecting a PEAK USB-CAN dongle displays CAN0. I've marked the Git as obsolete because the driver is in the kernel. You may need to change the device tree (DT). That's are the patches (80.-*) for: root@ubuntu ~/lib (git)-[master] # find ./ -name '80[12]*' ./patch/kernel/sunxi-next/801-dt-sun7i-add-can-bananapi.patch ./patch/kernel/sunxi-next/802-dt-sun7i-add-can-bananapro.patch ./patch/kernel/sunxi-dev/801-dt-sun7i-add-can-bananapi.patch ./patch/kernel/sunxi-dev/802-dt-sun7i-add-can-bananapro.patch root@ubuntu ~/lib (git)-[master] # cat ./patch/kernel/sunxi-next/802-dt-sun7i-add-can-bananapro.patch --- a/arch/arm/boot/dts/sun7i-a20-bananapro.dts 2016-01-11 00:01:32.000000000 +0100 +++ b/arch/arm/boot/dts/sun7i-a20-bananapro.dts 2016-02-03 20:12:28.285742989 +0100 @@ -104,6 +104,12 @@ status = "okay"; }; +&can0 { + pinctrl-names = "default"; + pinctrl-0 = <&can0_pins_a>; + status = "okay"; +}; + &ehci0 { status = "okay"; }; root@ubuntu ~/lib (git)-[master] # cat ./patch/kernel/sunxi-next/801-dt-sun7i-add-can-bananapi.patch --- a/arch/arm/boot/dts/sun7i-a20-bananapi.dts 2016-01-11 00:01:32.000000000 +0100 +++ b/arch/arm/boot/dts/sun7i-a20-bananapi.dts 2016-02-03 20:07:27.074726689 +0100 @@ -92,6 +92,12 @@ status = "okay"; }; +&can0 { + pinctrl-names = "default"; + pinctrl-0 = <&can0_pins_a>; + status = "okay"; +}; + &cpu0 { cpu-supply = <®_dcdc2>; operating-points = < FEX is for 3.x kernels and not applicable here. Try to load the kernel model 'modprobe sun4i_can'. There should a dmesg entry like: [ 10.063815] sun4i_can 1c2bc00.can: device registered (base=f1428c00, irq=48) Otherwise look at the DT (again). Regards Gerd
jgeisler Posted March 8, 2018 Posted March 8, 2018 Hi, I had the same problem still with ARMBIAN 5.38 stable Debian GNU/Linux 9 (stretch) 4.14.18-sunxi. But I didn't want to compile the kernel anew. So I did dtc -I dtb -O dts -o sun7i-a20-bananapi.dts sun7i-a20-bananapi.dtb with a copy of the dtb file from "/boot/dtb-4.14.18-sunxi" (maybe with sudo). Then edited the dts like this patch --- sun7i-a20-bananapi.dts 2018-03-05 18:42:30.608935387 +0000 +++ sun7i-a20-bananapi_can.dts 2018-03-05 18:28:21.085552756 +0000 @@ -1099,12 +1099,12 @@ linux,phandle = <0x2b>; phandle = <0x2b>; - can0@0 { + can0_pins_a: can0@0 { pins = "PH20", "PH21"; function = "can"; linux,phandle = <0x74>; phandle = <0x74>; - }; + }; clk_out_a@0 { pins = "PI12"; @@ -1847,10 +1847,12 @@ reg = <0x1c2bc00 0x400>; interrupts = <0x0 0x1a 0x4>; clocks = <0x43 0x4>; - status = "disabled"; linux,phandle = <0xb5>; phandle = <0xb5>; - }; + status = "okay"; + pinctrl-names = "default"; + pinctrl-0 = <&can0_pins_a>; + }; i2c@01c2c000 { compatible = "allwinner,sun7i-a20-i2c", "allwinner,sun4i-a10-i2c"; and recompiled with dtc -I dts -O dtb -o sun7i-a20-bananapi_can.dtb sun7i-a20-bananapi_can.dts copied it back to "/boot/dtb-4.14.18-sunxi", overwriting the original (and making a copy of the original of course). And voila: I have CAN bus working. But beware: the dtc on my bananapi had a lot of error messages and the changed dtb didn't boot. So I had to do the whole procedure on my main machine. Hope this helps anyone to a painless CAN bus activation. And thanks to the previous posters to get me on the right track.
Recommended Posts