Jump to content

CAN BUS support orange pi zero


amauri

Recommended Posts

Quote

It will display as nightly but it still will not have required changes. And I checked the configuration, nightly images are not enabled for your board (Orange Pi Plus 2). Sorry.


And where to get the kernel that is used in the night assemblies?

Link to comment
Share on other sites

If there is no nightly image for your board, you need to build one. You need a whole image, not just kernel update as already stated:

1 hour ago, zador.blood.stained said:

Stable image switched to beta repository will not have required changes, so nightly or user built image is required.

, otherwise it wont work and we are wasting time.  Is this now clear?

Link to comment
Share on other sites

Need help!

I'm trying to connect the mcp2515 module to the Orange Pi Zero 2+ H3, but I can not. Dmesg wrote:
[8.572220] mcp251x spi0.0: Can not initialize MCP2515. Wrong wiring?
[8.572248] mcp251x spi0.0: Probe failed, err = 19

 

The OS is assembled from a night assembly with CAN-BUS support:
Root @ orangepizeroplus2: ~ # uname -a
Linux orangepizeroplus2 4.11.9-sun8i # 17 SMP Sat Jul 29 00:21:32 CEST 2017 armv7l armv7l armv7l GNU / Linux

I connect modules without problems:
Modprobe can
Modprobe can-dev
Modprobe mcp251x

I use this overlay (PA7 is replaced with PA13 according to the pinout: this and this):

https://github.com/armbian/sunxi-DT-overlays/blob/master/examples/spi-mcp251x.dts

What else do I need to do to make the mcp2515 module work?

Link to comment
Share on other sites

2 minutes ago, zador.blood.stained said:

Please show your edited overlay.

/dts-v1/;
/plugin/;

/ {
	compatible = "allwinner,sun4i-a10", "allwinner,sun7i-a20", "allwinner,sun50i-a64", "allwinner,sun50i-h5";

	fragment@0 {
		target-path = "/clocks";
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <1>;
			can0_osc_fixed: can0_osc_fixed {
				compatible = "fixed-clock";
				#clock-cells = <0>;
				clock-frequency  = <8000000>;
			};
		};
	};

	fragment@1 {
		target = <&pio>;
		__overlay__ {
			can0_pin_irq: can0_pin_irq {
				pins = "PA13";
				function = "irq";
				bias-pull-up;
			};
		};
	};

	fragment@2 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";
			mcp2515 {
				reg = <0>;
				compatible = "microchip,mcp2515";
				pinctrl-names = "default";
				pinctrl-0 = <&can0_pin_irq>;
				spi-max-frequency = <10000000>;
				interrupt-parent = <&pio>;
				interrupts = <0 13 2>; /* PA13 IRQ_TYPE_EDGE_FALLING */
				clocks = <&can0_osc_fixed>;
				status = "okay";
			};
		};
	};
};

 

Link to comment
Share on other sites

8 minutes ago, zador.blood.stained said:

On Zero SPI bus 0 is wired to the SPI flash pads (even if the flash itself it's not soldered), and SPI bus 1 is wired to the pin headers, so it should be


target = <&spi1>;

instead

Corrected

 

root@orangepizeroplus2:~# dmesg|grep mcp25
[    8.346819] mcp251x spi1.0: Error applying setting, reverse things back
[    8.346839] mcp251x: probe of spi1.0 failed with error -22
root@orangepizeroplus2:~# dmesg|grep can
[    8.309157] can: controller area network core (rev 20120528 abi 9)
[    8.346796] sun8i-h3-pinctrl 1c20800.pinctrl: pin PA13 already requested by 1c69000.spi; cannot claim for spi1.0

 

Link to comment
Share on other sites

1 hour ago, martinayotte said:

Leave the PA13 as SPI_CS, and choose any other free GPIO for the IRQ, could be the original PA7.

My connection with the module:

4 VCC

6 GND

19 - GPIO 15 - MOSI
21 - GPIO 16 - MISO
23 - GPIO 14 - CLK
24 - GPIO 13 - CS0

It's right?

Is it necessary to connect a pin-INT on the module mcp2515, or without it to worked?

Link to comment
Share on other sites

Why don't you choose another GPIO for IRQ ? You don't have any left ?

According to Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt, the driver requires it :

 

 


* Microchip MCP251X stand-alone CAN controller device tree bindings

Required properties:
 - compatible: Should be one of the following:
   - "microchip,mcp2510" for MCP2510.
   - "microchip,mcp2515" for MCP2515.
 - reg: SPI chip select.
 - clocks: The clock feeding the CAN controller.
 - interrupt-parent: The parent interrupt controller.
 - interrupts: Should contain IRQ line for the CAN controller.

Optional properties:
 - vdd-supply: Regulator that powers the CAN controller.
 - xceiver-supply: Regulator that powers the CAN transceiver.

Example:
        can0: can@1 {
                compatible = "microchip,mcp2515";
                reg = <1>;
                clocks = <&clk24m>;
                interrupt-parent = <&gpio4>;
                interrupts = <13 0x2>;
                vdd-supply = <&reg5v0>;
                xceiver-supply = <&reg5v0>;
        };
 

 

 

EDIT : @zador.blood.stained bet me, time to do copy/paste last to long ... ;-)

Link to comment
Share on other sites

After all the fixes, errors ceased to appear and the interface can0 appeared! Thank you!

root@orangepizeroplus2:~# dmesg|grep mcp
[    8.873365] mcp251x spi1.0 can0: MCP2515 successfully initialized.
root@orangepizeroplus2:~# dmesg|grep can
[    8.803670] can: controller area network core (rev 20120528 abi 9)
[    8.873365] mcp251x spi1.0 can0: MCP2515 successfully initialized.

root@orangepizeroplus2:~# ifconfig -a
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

I connected the interrupt pin to PA7, orange is loaded normally, but when I execute the reboot command, orange does not load. When the interrupt terminal is connected, the orange can not normally reboot.

What can be done about this?

 

If I disable the interrupt pin, the orange is loaded and the can-modules also.
Next, I connect can0:
Ip link set can0 up type can bitrate 250000

 

I try to forward the message:
Cansend can0 100 # 43414e2054650000

 

I see this message on another device connected to another computer.

 

But the re-sending does not work and command "candump can0" does not show anything either. Perhaps this is due to the disconnected interrupt pin. But when the output is connected it is not possible to restart the orange. In what here there can be a problem?

Link to comment
Share on other sites

11 hours ago, martinayotte said:

I'm glad to see that it every thing worked out !

I have some of those MCP2515 modules on my desk since more than a month, but  never got chance/time try them out ...

 

If you find the time, try different pins for interrupts, for me it is not entirely clear why it was PA2, but when connected to other pins, orange could not reboot

Link to comment
Share on other sites

On 31/7/2017 at 3:39 PM, chuvak2007f said:

There was a new problem.
The system worked with a flash drive.
I transferred to internal memory. And orange stopped booting!
If I disconnect the interrupt pin, orange is loaded ...
In what there can be a problem, how it to win?

did you went on this?

is it all working?

 

thank you

Link to comment
Share on other sites

Thank you very much.
It works =)

YEEEEE

 

For all Orange pi h2&h3

Step:

1) Download nightly image!!!

2) Connect
PC0(GPIO Orange PI) MOSI - (MCP2515<->CAN) SI
PC1(GPIO Orange PI) MISO - (MCP2515<->CAN) SO
PC2(GPIO Orange PI) CLK   - (MCP2515<->CAN) SCK
PC3(GPIO Orange PI) CS     - (MCP2515<->CAN) CS
PA7(GPIO Orange PI)  INT    - (MCP2515<->CAN) INT
3) Download overlay (zipped): sun8i-h3-spi0-mcp2515.zip (read up)

4) connect for orange pi, and command: armbian-config

Chose: System->Hardware-> spi0-mcp2515 and spi-spidev.
5) reboot

6) next login and
modprobe can
modprobe can-dev

# set bitrate 125kbit

ip link set can0 type can bitrate 125000 triple-sampling on
ifconfig can0 up

7) Testing

apt-get install can-utils

cangen can0 -I 5 -L 8 -D 11223344AABBCCDD

 

Screenshot_20180401_065849.png

Link to comment
Share on other sites

Hi all, i tryedto enable the overlay to the PiZero Plus H5 image but as soon as i try to install i have an error message:

 

 

root@orangepizeroplus:/boot/dtb/allwinner/overlay# armbian-add-overlay ./spi-mcp251x.dts
Compiling the overlay
dtc: livetree.c:521: get_node_by_phandle: Assertion `(phandle != 0) && (phandle != -1)' failed.
/usr/sbin/armbian-add-overlay: line 76:  2078 Aborted                 dtc -@ -q -I dts -O dtb -o ${temp_dir}/${fname}.dtbo $1
Error compiling the overlay

This is the overlay

/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun4i-a10", "allwinner,sun7i-a20", "allwinner,sun8i-h3", "allwinner,sun50i-a64", "allwinner,sun50i-h5";

        fragment@0 {
                target-path = "/clocks";
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <1>;
                        can0_osc_fixed: can0_osc_fixed {
                                compatible = "fixed-clock";
                                #clock-cells = <0>;
                                clock-frequency  = <8000000>;
                        };
                };
        };

        fragment@1 {
                target = <&pio>;
                __overlay__ {
                        can0_pin_irq: can0_pin_irq {
                                pins = "PA7";
                                function = "irq";
                                bias-pull-up;
                        };
                };
        };

        fragment@2 {
                target = <&spi1>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        mcp2515 {
                                reg = <0>;
                                compatible = "microchip,mcp2515";
                                pinctrl-names = "default";
                                pinctrl-0 = <&can0_pin_irq>;
                                spi-max-frequency = <10000000>;
                                interrupt-parent = <&pio>;
                                interrupts = <0 7 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */
                                clocks = <&can0_osc_fixed>;
                                status = "okay";
                        };
                };
        };
};

I'm a bit new to armbian an help will be wellocome.

Link to comment
Share on other sites

I tried install spi-mcp251x.dts on my opi-pc.

 

$ uname -a
Linux orangepipc 4.19.20-sunxi #5.75 SMP Sat Feb 9 19:02:47 CET 2019 armv7l GNU/Linux

 

$ ls spi-mcp251x.dts
spi-mcp251x.dts

 

I added set -x to /usr/sbin/armbian-add-overlay

 

$ sudo armbian-add-overlay ./spi-mcp251x.dts
+ [[ ! -n ./spi-mcp251x.dts ]]
+ [[ 0 -ne 0 ]]
+ [[ ! -f ./spi-mcp251x.dts ]]
+ [[ ./spi-mcp251x.dts == *.dts ]]
++ basename ./spi-mcp251x.dts .dts
+ fname=spi-mcp251x
+ [[ ! -f /etc/armbian-release ]]
+ [[ ! -f /boot/armbianEnv.txt ]]
+ . /etc/armbian-release
++ BOARD=orangepipc
++ BOARD_NAME='Orange Pi PC'
++ BOARDFAMILY=sun8i
++ VERSION=5.75
++ LINUXFAMILY=sunxi
++ BRANCH=next
++ ARCH=arm
++ IMAGE_TYPE=stable
++ BOARD_TYPE=conf
++ INITRD_ARCH=arm
++ KERNEL_IMAGE_TYPE=zImage
+ [[ sunxi != sunxi ]]
+ [[ next != next ]]
++ uname -r
+ [[ -d /lib/modules/4.19.20-sunxi/build/scripts/dtc ]]
++ uname -r
+ [[ ! -x /lib/modules/4.19.20-sunxi/build/scripts/dtc/dtc ]]
+ echo 'Error: kernel headers are not installed properly'
Error: kernel headers are not installed properly
+ echo 'Can'\''t find dtc that supports compiling overlays'
Can't find dtc that supports compiling overlays
++ uname -r
+ echo 'Please install the headers package for kernel 4.19.20-sunxi'
Please install the headers package for kernel 4.19.20-sunxi
+ exit -1

 

$ ls /lib/modules/4.19.20-sunxi/build/scripts/dtc/
checks.c     dtc-parser.y  fdtput.c          livetree.c    treesource.c
data.c       dt_to_config  flattree.c        Makefile      update-dtc-source.sh
dtc.c        dtx_diff      fstree.c          Makefile.dtc  util.c
dtc.h        fdtdump.c     include-prefixes  srcpos.c      util.h
dtc-lexer.l  fdtget.c      libfdt            srcpos.h      version_gen.h


Can I have some advice?

 

EDIT:

remove kernel header from system

update dtc

resolved.

$ dtc -v
Version: DTC 1.4.2
$ wget https://git.kernel.org/pub/scm/utils/dtc/dtc.git/snapshot/dtc-1.4.7.tar.gz
$ tar xvfz dtc-1.4.7.tar.gz
$ cd dtc-1.4.7/
$ make
$ sudo cp ./dtc /usr/bin/
$ dtc -v
Version: DTC 1.4.7
$ sudo armbian-add-overlay ./spi-mcp251x.dts
Compiling the overlay
Copying the compiled overlay file to /boot/overlay-user/
Reboot is required to apply the changes

 

Link to comment
Share on other sites

Hi All,

 

I'm having some trouble getting this to work on the orangepilite2.  

 

uname -a

Linux orangepilite2 5.3.0-rc6-sunxi64 #5.95.190904 SMP Wed Sep 4 00:52:50 CEST 2019 aarch64 GNU/Linux

 

This is my DTS file (copied from the most recent DTS file from this thread). I've modified the clock frequency to: 16000000 because i have an 16Mhz crystal. I've also changed the interrupt pin to PD21 and in the interrupt line i've modified: interrupts = <0 117 2>;

 

After this i've ran the command: armbian-add-overlay which succeeds and i've double checked the armbianEnv which contains the compiled overlay. After reboot i attempted to modprobe the driver: modprobe mcp251x which doesn't give me any error and only returns: 

 

dmesg

[   91.647006] CAN device driver interface

 

No can0 device is created. I've also tried to enable the spi overlays without any success. 

 

Could someone please point me in the right direction?

/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun50i-h6";

        fragment@0 {
                target-path = "/clocks";
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <1>;
                        can0_osc_fixed: can0_osc_fixed {
                                compatible = "fixed-clock";
                                #clock-cells = <0>;
                                clock-frequency  = <16000000>;
                        };
                };
        };

        fragment@1 {
                target = <&pio>;
                __overlay__ {
                        can0_pin_irq: can0_pin_irq {
                                pins = "PD21";
                                function = "irq";
                                bias-pull-up;
                        };
                };
        };

        fragment@2 {
                target = <&spi0>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        status = "okay";
                        mcp2515 {
                                reg = <0>;
                                compatible = "microchip,mcp2515";
                                pinctrl-names = "default";
                                pinctrl-0 = <&can0_pin_irq>;
                                spi-max-frequency = <10000000>;
                                interrupt-parent = <&pio>;
                                interrupts = <0 117 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */
                                clocks = <&can0_osc_fixed>;
                                status = "okay";
                        };
                };
        };
};


 

 

Link to comment
Share on other sites

Hi Laurens,

My research focuses on connecting an MCP251x to an Orange Pi 3. I now have the /dev/sp1.0. This appeared after selecting in armbian-config -> system -> hardware -> spi-spidev1. But thats for spi1. The pi lite 2 has spi0 exposed, so select spi-spidev.

Currently I am working on the overlay for mcp251x. Next week I´will expect to have an mcp2515 available to test the overlay.

According to the documentation https://github.com/armbian/sunxi-DT-overlays in your overlay the following line is not correct:

Quote

interrupts = <0 117 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */

To me it sounds that PD21 must look like:

interrupts = <3 21 2>; /* PD21 IRQ_TYPE_EDGE_FALLING */

 

Link to comment
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...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines