CAN BUS support orange pi zero


Recommended Posts

Donate and support the project!

On 9/22/2019 at 3:53 PM, martinayotte said:

Try it without the "clocks" subpath :

Thank for replying. 

That was exactly the adjustment I made that successfully loaded the overlay.
This modification ensures that can0 is created with some duplicate error.

pi@orangepi3:~$ dmesg | grep spi||mcp
[    2.332200] sun6i-spi 5011000.spi: chipselect 0 already in use
[    2.332207] spi_master spi1: spi_device register error /soc/spi@5011000/spidev@0
[    2.332216] spi_master spi1: Failed to create SPI device for /soc/spi@5011000/spidev@0
[    6.059773] mcp251x spi1.0 can0: MCP2515 successfully initialized.
[  263.483858] mcp251x spi1.0: failed to acquire irq 0

The last log line is created with the command below: 

pi@orangepi3:~$ sudo ip link set can0 up type can bitrate 250000

replies with error message  

RTNETLINK answers: Invalid argument

My armbianEnv.txt

verbosity=1
console=both
overlay_prefix=sun50i-h6
rootdev=UUID=31a66c72-3b09-4222-a0f2-0f02de01b719
rootfstype=ext4
overlays=spi-spidev1
user_overlays=spi-mcp2515
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

My overlay:

/dts-v1/;
/plugin/;

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

        fragment@0 {
                target-path  = "/";
                __overlay__ {
                        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 = "PD21";
                                function = "irq";
                                bias-pull-up;
                        };
                };
        };

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

Update: For Opi3 read:

 

Edited by BertHav
pointer to solution added
Link to post
Share on other sites

Orange pi zero H2 + MCP2515

Connections:

MCP2515 Opi Zero H2
INT PA2
SCK PA14
SI PA15
SO PA16
CS PA13
GND GND
VCC 3.3v and for TJA1050 5v

OPi pinouts:

Spoiler

1483990620622-orange-pi-zero-description

My overlay:

Spoiler

 


/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 = "PA2";
                                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 2 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */
                                clocks = <&can0_osc_fixed>;
                                status = "okay";
                        };
                };
        };
};

dmesg:

Spoiler

[    9.660689] mcp251x spi1.0: Cannot initialize MCP2515. Wrong wiring?
[    9.661233] mcp251x spi1.0: Probe failed, err=19

 

Please, help. What's wrong?

Edited by ism
Opi Pinouts
Link to post
Share on other sites

Hi to all. 

I have Orange Pi PC+ and trying to use MCP2515. It worked well before, but some colleagues use my Orange and now I have "cannot find device can0" error

Board and bootenv:

Spoiler

78814    BOARD=orangepipcplus
 78815    BOARD_NAME="Orange Pi PC +"
 78816    BOARDFAMILY=sun8i
 78817    VERSION=5.73
 78818    LINUXFAMILY=sunxi
 78819    BRANCH=next
 78820    ARCH=arm
 78821    IMAGE_TYPE=stable
 78822    BOARD_TYPE=conf
 78823    INITRD_ARCH=arm
 78824    KERNEL_IMAGE_TYPE=zImage

 

78826    ### boot environment:
 78827    
 78828    verbosity=0
 78829    logo=/boot/boot.bmp
 78830    console=custom
 78831    stdout=both
 78832    disp_mode=1920x1080p60
 78833    overlay_prefix=sun8i-h3
 78834    rootdev=UUID=b674c5a6-e4bc-49c7-a23c-9ae6c54f55e0
 78835    rootfstype=ext4
 78836    overlays=spi0-mcp2515 spi-spidev
 78837    rootfstype=ext4
 78838    extraargs=vt.global_cursor_default=0 quiet splash plymouth.ignore-serial-consoles
 78839    usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

 

I found that there is no sun8i-h3-spi0-mcp2515.dtbo file in overlay folders. I tried to compile this file  from https://github.com/armbian/sunxi-DT-overlays but I am receiving this error

 

sudo 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 81:  2323 Aborted                 dtc -@ -q -I dts -O dtb -o ${temp_dir}/${fname}.dtbo $1
Error compiling the overlay

 

Sadly I am noob in this, what does it mean?

Link to post
Share on other sites

The H20 orange pi boards have on 40 pins GPIO PIN 18 CAN_RX signal. Why do you play with SPI to CAN adapter instead of use built in internal CAN peripheral.  Only can transmitter is needed.

Why do you involve SPI to convert it later to CAN?

 

By the way usually CAN pins are named as CAN_L and CAN_H why did they  called it as CAN_RX? If this was typo were is CAN_TX pin?

Link to post
Share on other sites

Can anyone explain strange driver behavior, actual CAN module connection:

MCP2515 Opi Zero H2
INT PA7
SCK PA14
SI PA15
SO PA16
CS PA13
GND GND
5V 5V

 

Either I write in overlay pins = "PA2"; or pins = "PA7"; mcp2515 is successfully initialized

dasio@orangepizero:~$ dmesg | grep mcp
[   11.495643] mcp251x spi0.0 can0: MCP2515 successfully initialized.

But in case of pins = "PA7"; command  "sudo ip link set up can0 type can bitrate 500000" leads system to hang

When in overlay pins = "PA2"; (that does not correspond to physical connection) CAN bus became functional

 

 

Скрытый текст


/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 = "PA2";
				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";
			};
		};
	};
};

 

 

Link to post
Share on other sites
17.01.2021 в 19:09, Vadzim Yatskevich сказал:

Can anyone explain strange driver behavior, actual CAN module connection:

MCP2515 Opi Zero H2
INT PA7
SCK PA14
SI PA15
SO PA16
CS PA13
GND GND
5V 5V

 

Either I write in overlay pins = "PA2"; or pins = "PA7"; mcp2515 is successfully initialized



dasio@orangepizero:~$ dmesg | grep mcp
[   11.495643] mcp251x spi0.0 can0: MCP2515 successfully initialized.

But in case of pins = "PA7"; command  "sudo ip link set up can0 type can bitrate 500000" leads system to hang

When in overlay pins = "PA2"; (that does not correspond to physical connection) CAN bus became functional

 

 

  Показать содержимое




/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 = "PA2";
				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";
			};
		};
	};
};

 

 

So finally I found a dirty solution to have CAN bus on Orange pi Zero and Orange pi Zero plus 2. Downgrade to kernel version Linux 5.4.x (Linux 5.4.58-sunxi in my case) makes interrupt pins behavior completely adequate. Possible to use PA7 (for Orange pi Zero) and PA2 (Orange pi Zero plus 2).

Link to post
Share on other sites

 

Just instead of  

interrupts = <0 7 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */ 
put the correct value  
interrupts = <0 7 IRQ_TYPE_LEVEL_LOW>;    

And everything will work for you including Linux 5.11

 

Just a Linux 5.5 driver, uses sleep functions in the MCP2515, and the IRQ_TYPE_EDGE_FALLING interrupt cannot be handled.

 

 

 

 

Link to post
Share on other sites
20 часов назад, Aleksey сказал:

 

Just instead of  

interrupts = <0 7 2>; /* PA7 IRQ_TYPE_EDGE_FALLING */ 
put the correct value  
interrupts = <0 7 IRQ_TYPE_LEVEL_LOW>;    

And everything will work for you including Linux 5.11

 

Just a Linux 5.5 driver, uses sleep functions in the MCP2515, and the IRQ_TYPE_EDGE_FALLING interrupt cannot be handled.

 

 

 

 

Getting compilation error with "interrupts = <0 2 IRQ_TYPE_LEVEL_LOW>;" 

But  when using  " interrupts = <0 2 8>; /* PA2 IRQ_TYPE_LEVEL_LOW */ " (is that what Aleksey meant?) compilation is successfull and  CAN interface is fully functional on Linux 5.10.16-sunxi

 

Link to post
Share on other sites

It’s strange that your definition didn’t fit , 

this value is defined https://elixir.bootlin.com/linux/latest/source/include/dt-bindings/interrupt-controller/irq.h#L18

 

Цитата

/*

* This header provides constants for most IRQ bindings.
* * Most IRQ bindings include a flags cell as part of the IRQ specifier.
* In most cases, the format of the flags cell uses the standard values
* defined in this header.
*/
#ifndef _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H
#define _DT_BINDINGS_INTERRUPT_CONTROLLER_IRQ_H
#define IRQ_TYPE_NONE 0
#define IRQ_TYPE_EDGE_RISING 1
#define IRQ_TYPE_EDGE_FALLING 2
#define IRQ_TYPE_EDGE_BOTH (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)
#define IRQ_TYPE_LEVEL_HIGH 4
#define IRQ_TYPE_LEVEL_LOW 8
#endif

 and here  https://elixir.bootlin.com/linux/latest/source/include/linux/irq.h#L82

But you can do that))

 

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...