Jump to content

CAN BUS support orange pi zero


amauri

Recommended Posts

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Good afternoon,

I'm sorry to reopen this topic, but I have problems with the can bus in a nanopi neo core.

I manage to bring up the can0 interface, but using the cansend command, I only send 1 message, the following ones are not sent, I have to down-up the interface and again it lets me send one.

I think it may be that this board does not have the PA7, but I don't know which one I can declare in dts... any help?

thank you!

Link to comment
Share on other sites

hi everyone!

 

try to start MCP2515 on Nano Pi Neo Air, have next success:

 

Armbian 22.05.0-trunk Focal with Linux 5.15.33-sunxi

root@nanopiair:~# dmesg | grep spi
[    1.965166] sun6i-spi 1c68000.spi: chipselect 0 already in use
[    1.965202] spi_master spi0: spi_device register error /soc/spi@1c68000/spidev@0
[    1.965257] spi_master spi0: Failed to create SPI device for /soc/spi@1c68000/spidev@0
[    1.965550] sun8i-h3-pinctrl 1c20800.pinctrl: pin PA15 already requested by 1c28c00.serial; cannot claim for 1c69000.spi
[    1.965580] sun8i-h3-pinctrl 1c20800.pinctrl: pin-15 (1c69000.spi) status -22
[    1.965632] sun6i-spi 1c69000.spi: Error applying setting, reverse things back
[   13.173316] mcp251x spi0.0 can0: MCP2515 successfully initialized.

root@nanopiair:~# dmesg | grep mcp
[   13.173316] mcp251x spi0.0 can0: MCP2515 successfully initialized.

root@nanopiair:~# dmesg | fgrep -i can
[    1.965550] sun8i-h3-pinctrl 1c20800.pinctrl: pin PA15 already requested by 1c28c00.serial; cannot claim for 1c69000.spi
[   13.093230] CAN device driver interface
[   13.173316] mcp251x spi0.0 can0: MCP2515 successfully initialized.

root@nanopiair:~# sudo ip link set can0 up type can bitrate 500000
root@nanopiair:~# ifconfig
can0: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

but can data doesnt receive and send to other device.

 

this is my overlay

/dts-v1/;
/plugin/;

/ {
	compatible = "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  = <40000000>;
			};
		};
	};

	fragment@1 {
		target = <&pio>;
		__overlay__ {
			can0_pin_irq: can0_pin_irq {
				pins = "PA2";
				function = "irq";
				drive = <0x0>;
				pull = <0x1>;
				linux,phandle = <0x1>;
				phandle = <0x1>;
			};
		};
	};

	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 = <500000>;
				interrupt-parent = <&pio>;
				interrupts = <0 2 8>;
				clocks = <&can0_osc_fixed>;
				status = "okay";
			};
		};
	};
};

 

this is my boot config

 

verbosity=1
bootlogo=false
console=serial
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
overlays=i2c0 spi-spidev usbhost2 usbhost3 w1-gpio
param_spidev_spi_bus=1
param_spidev_spi_cs=1
param_spidev_max_freq=1000000
rootdev=UUID=b159adca-200e-4061-b610-b41e2ca7e38e
rootfstype=ext4
user_overlays=sun8i-h3-i2s0-master spi-mcp251x
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

try to test loopback:

sudo ip link set can0 type can loopback on
cansend can0 001#1122334455667788

 

but command

candump can0

 

doesnt anwer me, just hold it tty. only CTRL+C breacked it.

 

Please help me to dig and solve problem.


 

Link to comment
Share on other sites

Its work succeful on NanoPi neo Air

 

Armbian 22.05.0-trunk Focal with Linux 5.15.33-sunxi
 

 

armbianEnv.txt

verbosity=1
bootlogo=false
console=serial
disp_mode=1920x1080p60
overlay_prefix=sun8i-h3
overlays=i2c0 spi-spidev usbhost2 usbhost3 w1-gpio
param_spidev_spi_bus=1
param_spidev_spi_cs=1
param_spidev_max_freq=1000000
rootdev=UUID=b159adca-200e-4061-b610-b41e2ca7e38e
rootfstype=ext4
user_overlays=sun8i-h3-i2s0-master spi-mcp251x
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

interrupt set on PA2 in dts / dtbo file

 

 

2023-06-24_23-05-08.png

 

photo_2023-06-25_10-49-37.jpg

spi-mcp251x.dtbo spi-mcp251x.dts

Edited by nagaudio
Link to comment
Share on other sites

add some extra info for activating mcp2515 driver on AIR.

 

put next files  (from attach) to next directories:

/boot/dtb-5.15.33-sunxi/overlay/

sun8i-h3-uart3.dtbo

(with disabled uart2, because it use PA2 pin, which is necessary to use as INTERRUPT pin)

 

/overlay-user/

spi-mcp251x.dts,

spi-mcp251x.dtbo

(with configured correct pins)

 

/boot/dtb-5.15.33-sunxi/

sun8i-h3-nanopi-neo-air.dts,

sun8i-h3-nanopi-neo-air.dtbo

(customized setup SPI bus on Armbian 22.05.0-trunk Focal with Linux 5.15.33-sunxi)

mcp2115.zip

Link to comment
Share on other sites

Hi @nagaudio

 

im trying to do the same in a neo core.

what changes you do in 

sun8i-h3-nanopi-neo-air.dts,

sun8i-h3-nanopi-neo-air.dtbo?

 

i have to replicate in the 

sun8i-h3-nanopi-neo-core.dts,

sun8i-h3-nanopi-neo-core.dtbo

Thanks!!

Link to comment
Share on other sites

Hello. I've also had issues to run CAN bus on my Orange Pi One.
I have armbinan with 6.x kernel. And also had stuck on interface upping.
I've solved it by modifing dts file in interrupt section

Have changed <0 7 2> to <0 7 8> and now it works fine! Thanks to one good person who described the same issue and suggested to change interruption type.
I've looked at linux kernel header and  IRQ_TYPE_LEVEL_LOW points to 8.
Connected to my car and data started to run. Thanks!

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