Jump to content

Tips on configuring double spi (through two chipselects) on Orange Pi Zero 2.


Recommended Posts

The configuration itself is probably quite similar.

However H5 and H616 are different SoCs where H5 is well matured but H616 still fairly recent and therefore it is lacking feature and development itself for ARM devices is generally quite slow in comparison to x86 for example.

Link to comment
Share on other sites

On 6/28/2022 at 1:34 PM, Werner said:

The configuration itself is probably quite similar.

However H5 and H616 are different SoCs where H5 is well matured but H616 still fairly recent and therefore it is lacking feature and development itself for ARM devices is generally quite slow in comparison to x86 for example.

can it work? if I copy dtbo files from debian system of this board, to this armbian

Link to comment
Share on other sites

/dts-v1/;
/plugin/;

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

	fragment@0 {
		target-path = "/aliases";
		__overlay__ {
			spi0 = "/soc/spi@5010000";
			spi1 = "/soc/spi@5011000";
		};
	};

	fragment@1 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			spidev@0 {
				compatible = "spidev";
				status = "disabled";
				reg = <0>;
				spi-max-frequency = <1000000>;
			};
		};
	};

	fragment@2 {
		target = <&spi1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			spidev@0 {
				compatible = "spidev";
				status = "disabled";
				reg = <0>;
				spi-max-frequency = <1000000>;
			};
		};
	};
};

 

Link to comment
Share on other sites

Very interesting!

 

Any idea how to make this work?

 

I have naively created a file /boot/overlay-user/spi.dts with the following contents (as i only need one spi interface):

 

/dts-v1/;
/plugin/;

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

        fragment@0 {
                target-path = "/aliases";
                __overlay__ {
                        spi0 = "/soc/spi@5010000";
                };
        };

        fragment@1 {
                target = <&spi0>;
                __overlay__ {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        spidev@0 {
                                compatible = "spidev";
                                status = "disabled";
                                reg = <0>;
                                spi-max-frequency = <1000000>;
                        };
                };
        };

};

 

Afterwards, I have enabled the overlay using `armbian-add-overlay spi`, but unfortunately, even after a reboot I don't have an spi device in /dev.

 

I'm running a fresh copy of Armbian 22.05 with all upgrades (including upgrade of armbian-{config,firmware,zsh} to 22.08.0).

 

# uname -a
Linux xxx 5.15.48-sunxi64 #22.05.3 SMP Wed Jun 22 07:33:24 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

 

# dmesg | grep spi
[    1.242938] sun6i-spi 5010000.spi: Failed to request TX DMA channel
[    1.242959] sun6i-spi 5010000.spi: Failed to request RX DMA channel
[    1.243556] spi-nor spi0.0: supply vdd not found, using dummy regulator
[    1.257585] spi-nor spi0.0: mx25l1606e (2048 Kbytes)
# cat /boot/armbianEnv.txt
verbosity=1
bootlogo=false
console=serial
disp_mode=1920x1080p60
rootdev=UUID=f3d154d3-f330-4f4c-8700-e85ffc6a9066
rootfstype=ext4
user_overlays=spi
usbstoragequirks=0x2537:0x1066:u,0x2537:0x1068:u

 

In desperate search for a solution, I have also replaced "disabled" with "enabled" in the dts file and installed armbian-firmware-full, without any success.

 

Any help would be appreciated!

Link to comment
Share on other sites

You'll have to look into specifics of HW created as fixup script in boot.

 

Edit: not time earlier and not priority - some notes and fixup example from orangepi h616 to study.

 

Quote

# overlays fixup script

# implements (or rather substitutes) overlay arguments functionality

# using u-boot scripting, environment variables and "fdt" command

 

# setexpr test_var ${tmp_bank} - A

# works only for hex numbers (A-F)

 

setenv decompose_pin 'setexpr tmp_bank sub "P(C|G|H|I)\\d+" "\\1";

setexpr tmp_pin sub "P\\S(\\d+)" "\\1";

test "${tmp_bank}" = "C" && setenv tmp_bank 2;

test "${tmp_bank}" = "G" && setenv tmp_bank 6'

test "${tmp_bank}" = "H" && setenv tmp_bank 7;

test "${tmp_bank}" = "I" && setenv tmp_bank 8;

 

if test -n "${param_spinor_spi_bus}"; then
    test "${param_spinor_spi_bus}" = "0" && setenv tmp_spi_path "spi@5010000"
    test "${param_spinor_spi_bus}" = "1" && setenv tmp_spi_path "spi@5011000"
    fdt set /soc/${tmp_spi_path} status "okay"
    fdt set /soc/${tmp_spi_path}/spiflash@0 status "okay"
    if test -n "${param_spinor_max_freq}"; then
        fdt set /soc/${tmp_spi_path}/spiflash@0 spi-max-frequency "<${param_spinor_max_freq}>"
    fi
    if test "${param_spinor_spi_cs}" = "1"; then
        fdt set /soc/${tmp_spi_path}/spiflash@0 reg "<1>"
    fi
    env delete tmp_spi_path
fi

 

if test -n "${param_spidev_spi_bus}"; then

test "${param_spidev_spi_bus}" = "0" && setenv tmp_spi_path "spi@5010000"

test "${param_spidev_spi_bus}" = "1" && setenv tmp_spi_path "spi@5011000"

fdt set /soc/${tmp_spi_path} status "okay"

fdt set /soc/${tmp_spi_path}/spidev status "okay"

if test -n "${param_spidev_max_freq}"; then

fdt set /soc/${tmp_spi_path}/spidev spi-max-frequency "<${param_spidev_max_freq}>"

fi

if test "${param_spidev_spi_cs}" = "1"; then

fdt set /soc/${tmp_spi_path}/spidev reg "<1>"

fi

env delete tmp_spi_path

fi

 

Pin in dtsi to check:

spi@0: 

 

pinctrl-names = "default";

pinctrl-0 = <&spi0_pins>;

 

spi@1:

 

pinctrl-names = "default";

pinctrl-0 = <&spi1_pins>, <&spi1_cs_pin>;

 

spi1_cs_pin: spi1-cs-pin {

pins = "PH9";

function = "spi1";

};

 

spidev change in dts relating to patchwork [2/3] spi: spidev: Add Rohm DH2228FV DAC compatible string:

 

spidev@1 {

compatible = "rohm,dh2228fv";

status = "disabled";

reg = <0>;

reg = <1>;

spi-max-frequency = <1000000>;

};

 

This what have noted so-far but not attempted anything further.

 

EDIT 2: Other possible requirements:

 

Headers for compiling dtbo

dtc -@ -I dts -O dtb -o

 

alistair@orangepizero2:~$ zcat /proc/config.gz   | grep -E 'CONFIG_OF_OVERLAY|CONFIG_OF_CONFIGFS'
CONFIG_OF_OVERLAY=y
CONFIG_OF_CONFIGFS=y

 

Edit /boot/armbianEnv.txt adding:

overlay_prefix=
overlays=
param_spidev_spi_bus=

param_spidev_spi_cs=
param_spidev_max_freq=

 

Check Forums e.g: https://github.com/armbian/sunxi-DT-overlays/blob/master/sun50i-a64/README.sun50i-a64-overlays

and posts from @martinayotte: 

https://docs.armbian.com/User-Guide_Allwinner_overlays/

 

Personally will have a go at H616 overlays in the next week or so, these stand as notes to my point of departure.

 

Good luck and let us know your progress!

Link to comment
Share on other sites

OK, so I got SPI working on Armbian 22.05.3 Jammy (edge).

 

In the end, the above DTS files weren't of much use (to me). Here's what I did:

 

1. I installed the Debian bullseye stock image (provided by Xunlong), which has SPI support.

 

2. I located the spi-spidev dtob files and the fixup script for sun50i-h616 in the boot folder and just copied them from the stock image over to a (newly installed) Armbian 22.05.3 Jammy (edge) image. Don't worry that the dtbo files are byte compiled and therefore not human readable. They can still be decompiled and so they are open source (although I don't know if they are legally licensed with an Open Source license, but what I mean is that the source can be viewed by anyone). You can decompile the dtbo with the following command:

dtc -I dtb -O dts -o devicetree.dts devicetree.dtb 

 

3. I activated SPI in armbianEnv.txt. Be warned that I had to use SPI bus 1. I haven't yet fully understood whether or not there is such a thing like SPI bus 0 on the Orange Pi Zero 2, as - on one hand - the documentation says that there is only one SPI on the 26 pins header, but, on the other hand, the original dtbo and fixup script require you to specify param_spi_bus in the orangepiEnv.txt file and no error is thrown when you select bus 0.

 

I'll post the decompiled dtbo and the fixup scripts here, although the fixup script wasn't surprising at all.

 

/dts-v1/;

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

	fragment@0 {
		target-path = "/aliases";

		__overlay__ {
			spi0 = "/soc/spi@5010000";
			spi1 = "/soc/spi@5011000";
		};
	};

	fragment@1 {
		target = <0xffffffff>;

		__overlay__ {
			#address-cells = <0x01>;
			#size-cells = <0x00>;

			spidev@0 {
				compatible = "rohm,dh2228fv";
				status = "disabled";
				reg = <0x00>;
				spi-max-frequency = <0xf4240>;
			};
		};
	};

	fragment@2 {
		target = <0xffffffff>;

		__overlay__ {
			#address-cells = <0x01>;
			#size-cells = <0x00>;

			spidev@0 {
				compatible = "rohm,dh2228fv";
				status = "disabled";
				reg = <0x00>;
				spi-max-frequency = <0xf4240>;
			};
		};
	};

	__fixups__ {
		spi0 = "/fragment@1:target:0";
		spi1 = "/fragment@2:target:0";
	};
};

 

(The fixup script has some gibberish bytecode at the beginning. I believe that's of no importance, but not sure...)

'V<\99\8Db\F0\9A\EF\00\00+\00\00\00\00\00\00\00\00fpq\A3\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00#\00\00\00\00# overlays fixup script
# implements (or rather substitutes) overlay arguments functionality
# using u-boot scripting, environment variables and "fdt" command

# setexpr test_var ${tmp_bank} - A
# works only for hex numbers (A-F)

setenv decompose_pin 'setexpr tmp_bank sub "P(C|G|H|I)\\d+" "\\1";
setexpr tmp_pin sub "P\\S(\\d+)" "\\1";
test "${tmp_bank}" = "C" && setenv tmp_bank 2;
test "${tmp_bank}" = "G" && setenv tmp_bank 6'
test "${tmp_bank}" = "H" && setenv tmp_bank 7;
test "${tmp_bank}" = "I" && setenv tmp_bank 8;

if test -n "${param_spinor_spi_bus}"; then
	test "${param_spinor_spi_bus}" = "0" && setenv tmp_spi_path "spi@5010000"
	test "${param_spinor_spi_bus}" = "1" && setenv tmp_spi_path "spi@5011000"
	fdt set /soc/${tmp_spi_path} status "okay"
	fdt set /soc/${tmp_spi_path}/spiflash@0 status "okay"
	if test -n "${param_spinor_max_freq}"; then
		fdt set /soc/${tmp_spi_path}/spiflash@0 spi-max-frequency "<${param_spinor_max_freq}>"
	fi
	if test "${param_spinor_spi_cs}" = "1"; then
		fdt set /soc/${tmp_spi_path}/spiflash@0 reg "<1>"
	fi
	env delete tmp_spi_path
fi

if test -n "${param_spidev_spi_bus}"; then
	test "${param_spidev_spi_bus}" = "0" && setenv tmp_spi_path "spi@5010000"
	test "${param_spidev_spi_bus}" = "1" && setenv tmp_spi_path "spi@5011000"
	fdt set /soc/${tmp_spi_path} status "okay"
	fdt set /soc/${tmp_spi_path}/spidev status "okay"
	if test -n "${param_spidev_max_freq}"; then
		fdt set /soc/${tmp_spi_path}/spidev spi-max-frequency "<${param_spidev_max_freq}>"
	fi
	if test "${param_spidev_spi_cs}" = "1"; then
		fdt set /soc/${tmp_spi_path}/spidev reg "<1>"
	fi
	env delete tmp_spi_path
fi

if test -n "${param_pps_pin}"; then
	setenv tmp_bank "${param_pps_pin}"
	setenv tmp_pin "${param_pps_pin}"
	run decompose_pin
	fdt set /soc/pinctrl@300b000/pps_pins pins "${param_pps_pin}"
	fdt get value tmp_phandle /soc/pinctrl@300b000 phandle
	fdt set /pps@0 gpios "<${tmp_phandle} ${tmp_bank} ${tmp_pin} 0>"
	env delete tmp_pin tmp_bank tmp_phandle
fi

if test "${param_pps_falling_edge}" = "1"; then
	fdt set /pps@0 assert-falling-edge
fi

for f in ${overlays}; do
	if test "${f}" = "pwm34"; then
		setenv bootargs_new ""
		for arg in ${bootargs}; do
			if test "${arg}" = "console=ttyS0,115200"; then
				echo "Warning: Disabling ttyS0 console due to enabled PWM3 and PWM4 overlay"
			else
				setenv bootargs_new "${bootargs_new} ${arg}"
			fi
		done
		setenv bootargs "${bootargs_new}"
	fi
done

if test -n "${param_w1_pin}"; then
	setenv tmp_bank "${param_w1_pin}"
	setenv tmp_pin "${param_w1_pin}"
	run decompose_pin
	fdt set /soc/pinctrl@300b000/w1_pins pins "${param_w1_pin}"
	fdt get value tmp_phandle /soc/pinctrl@300b000 phandle
	fdt set /onewire@0 gpios "<${tmp_phandle} ${tmp_bank} ${tmp_pin} 0>"
	env delete tmp_pin tmp_bank tmp_phandle
fi

if test "${param_w1_pin_int_pullup}" = "1"; then
	fdt set /soc/pinctrl@300b000/w1_pins bias-pull-up
fi

if test "${param_uart1_rtscts}" = "1"; then
	fdt get value tmp_phandle1 /soc/pinctrl@300b000/uart1-pins phandle
	fdt get value tmp_phandle2 /soc/pinctrl@300b000/uart1-rts-cts-pins phandle
	fdt set /soc/serial@5000400 pinctrl-names "default" "default"
	fdt set /soc/serial@5000400 pinctrl-0 "<${tmp_phandle1}>"
	fdt set /soc/serial@5000400 pinctrl-1 "<${tmp_phandle2}>"
	env delete tmp_phandle1 tmp_phandle2
fi

if test "${param_uart2_rtscts}" = "1"; then
	fdt get value tmp_phandle1 /soc/pinctrl@300b000/uart2-pins phandle
	fdt get value tmp_phandle2 /soc/pinctrl@300b000/uart2-rts-cts-pins phandle
	fdt set /soc/serial@5000800 pinctrl-names "default" "default"
	fdt set /soc/serial@5000800 pinctrl-0 "<${tmp_phandle1}>"
	fdt set /soc/serial@5000800 pinctrl-1 "<${tmp_phandle2}>"
	env delete tmp_phandle1 tmp_phandle2
fi

if test "${param_uart3_rtscts}" = "1"; then
	fdt get value tmp_phandle1 /soc/pinctrl@300b000/uart3-pins phandle
	fdt get value tmp_phandle2 /soc/pinctrl@300b000/uart3-rts-cts-pins phandle
	fdt set /soc/serial@5000c00 pinctrl-names "default" "default"
	fdt set /soc/serial@5000c00 pinctrl-0 "<${tmp_phandle1}>"
	fdt set /soc/serial@5000c00 pinctrl-1 "<${tmp_phandle2}>"
	env delete tmp_phandle1 tmp_phandle2
fi

 

And I use these parameters in armbianEnv.txt:

overlay_prefix=sun50i-h616
overlays=spi-spidev
param_spidev_spi_bus=1

 

Link to comment
Share on other sites

Thank you for sharing your efforts @zaibot.w, that a novel, if not innovative approach solving. Importantly what this "confirms" is that the existing overlays can be ported, the binaries you used are 'part' compiled with the files I mentioned above.

 

The 3 folded approach (on-board/ dynamic/ build) which hope to get to sometime this week, should resolve by patching without much faffing around directly on the board, which can be challenging. 

 

As a whole for Zero2 its a matter of somebody having the time to test and incrementally submit PR's to the build system. Here there has been a huge effort with sunxi in the build system already! Thank you to those Individuals.

Link to comment
Share on other sites

OK. I don't really get what work is left to be done, but I'm totally new to the whole topic and I'm already happy that I got SPI working on my board.

 

Just out of curiosity:

You have the source code (fixup script and dts/dtbo files) that I've posted above, which could be directly (and without any further modification) included into an Armbian Image just like all the other overlays for other boards. What is there that still needs to be done and that has not been tested yet?

Link to comment
Share on other sites

Many of the legacy kernel 4.9.255 features have not made it into the 5.x.y, be that mainline or here, common topics, no wifi, display engine, overlays, boot problems etc, etc should be indication of the modern kernels being WIP

 

Fork the build system and have a look around and help if you can and have time.

 

Added Edit: Overlays would probably be last on the list and not everyone will agree they the best approach.

Link to comment
Share on other sites

hey, sorry but Armbian is new for me

I also have a OP02 with the latest bullseye (5.19) and want to use SPI (laster also i2c) within klipper 

I found a guide how to enable SPI on OP boards (https://neonaut.neocities.org/blog/2018/orange-pi-i2c-spi-setup.html) but my first issue is in armbian-config.

my "hardware-tab" is empty like in https://github.com/armbian/config/issues/33 

I even tried to add "overlay_prefix=sun50i-h616" to armbianEnv.txt since this line was missing and might cause issues. (the "sun50i-h616-....dtb" file was und the dth subfolder)

 

So since there seems to be a solution to get 2 SPI working, maybe someone could help me find an easy way to set up SPI for a noob :D

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