Enable 1-wire in kernel 4.9 on BananaPi


cvxx
 Share

6 6

Recommended Posts

Hi,

I have just upgraded my BananaPi from Lemaker's Lubuntu 3.4 kernel to the latest Armbian with kernel 4.9 and I can't enable 1-wire to read ds18b20. I suspect the enabling procedure has changed?

 

What I did was:

1. bin2fex /boot/script.bin > script.fex

2. vi script.fex

Appended this section exactly as it was on my previous Lemaker kernel 3.4:

[w1_para]
gpio = 4

3. fex2bin script.fex > /boot/script.bin

4. reboot

5. echo 600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq

6. modprobe w1_gpio

7. modprobe w1_therm

8. ls /sys/bus/w1/devices/

empty answer

 

In the "known issues" currently it is written that "Different GPIO numbering compared to the legacy kernel". How different is that? Do I need to use different "[w1_para] gpio = 4" value in script.bin with the new kernel?

 

Thank you

Link to post
Share on other sites

Armbian is a community driven open source project. Do you like to contribute your code?

Mainline kernel doesn't use FEX at all, it is using DeviceTree DTB.

You first need to decompile DTB into DTS and you need to add some thing like that in you DTS in PIO section :

                        w1_pins: w1_pins {
                                allwinner,pins = "PD14";
                                allwinner,function = "gpio_in"; // in (initially)
                                allwinner,pull = <0>; // off
                        };

Then, at the root level :

                        w1: onewire@0 {
                                compatible = "w1-gpio";
                                pinctrl-names = "default";
                                pinctrl-0 = <&w1_pins>;
                                gpios = <&pio 3 14 0>; // PD14
                                status = "okay";
                        };

 

Link to post
Share on other sites

22 hours ago, zador.blood.stained said:

Recent nightly or manually built image, or alternatively updates for armbianEnv and boot script will be required.

So "Welcome to ARMBIAN 5.25 stable Debian GNU/Linux 8 (jessie) 4.9.12-sunxi" will not match the requirements for this easy way? I've downloaded the image a couple of days ago.

If not, could you give some more details on what has to be changed?

 

Thank you

René

Link to post
Share on other sites

If you can switch to newest image because you simply added tons of applications, and tweaked tons of configs, what you can do is still download newest image, plug into a SDCard reader over one of the USB, then move the old /boot into /boot-OLD and copy the one from the new image from /mnt/boot into /boot. Probably, you will also need to install newest u-boot by doing :

dd if=/usr/lib/linux-u-boot-dev-orangepipc_5.27_armhf/u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

The, reboot and see newest kernel, but still able to use you old applications

Link to post
Share on other sites

Hello all,

 

sorry for dropping in here.

 

I am trying to access a DS18B20 temperature sensor on my Banana Pi, which is runnin on the mainline kernel:

Linux bpi 4.10.12-sunxi #7 SMP Wed Apr 26 02:44:12 CEST 2017 armv7l GNU/Linux

However, I cannot get the sensor working. What I've tried so far is:

 

  1. Edit the /boot/script.bin file via sunxi-tools, as described multiple times on the net. Adding lines such as
    [w1_para]
    gpio = 4

    has no effect at all. (As mentioned above, this method is not used anymore - thanks for the hint! :) )

  2. Editing the /boot/armbianEnv.txt is not working either:

    1. Adding
      overlays=w1-gpio

      has no effect at all.

    2. Adding

      overlays=sun7i-a20-w1-gpio

      (while sun7i-a20-w1-gpio[.dtbo] is the filename of the DTB-tree in /boot/dtb/overlays/) causes some entries show up in /sys/bus/w1/devices/. They seem to be random, since the IDs are changing after a minute or so, and cannot be accessed.

Further, the kernel modules w1_gpio and w1_term are loaded during boot, which seems to have no effect, either.

 

Using the 2.2 method, lines like these

[   62.195492] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.
[  125.795516] w1_master_driver w1_bus_master1: Family 0 for 00.400000000000.46 is not registered.
[  176.555608] w1_master_driver w1_bus_master1: Family 0 for 00.c00000000000.ca is not registered.
[  252.995466] w1_master_driver w1_bus_master1: Family 0 for 00.200000000000.23 is not registered.
[  316.595477] w1_master_driver w1_bus_master1: Family 0 for 00.a00000000000.af is not registered.
[  354.516052] w1_master_driver w1_bus_master1: Family 0 for 00.600000000000.65 is not registered.
[  394.995595] w1_master_driver w1_bus_master1: Family 0 for 00.e00000000000.e9 is not registered.
[  457.995555] w1_master_driver w1_bus_master1: Family 0 for 00.100000000000.9d is not registered.
[  497.115573] w1_master_driver w1_bus_master1: Family 0 for 00.900000000000.11 is not registered.
[  572.355679] w1_master_driver w1_bus_master1: Family 0 for 00.500000000000.db is not registered.

are showing up in dmesg.

 

The system is not upgraded from an older version but freshly installed (two days ago, switching from Bananian). DS18B20 is correctly plugged in with a 4k7 resistor, checked this multiple times.

 

Any help is greatly appreciated (forgive me if I made a trivial mistake).

 

Best regards,

Norbert Kahl

Link to post
Share on other sites

1 hour ago, nkahl said:

Adding


overlays=w1-gpio

has no effect at all.

 

This means that you don't have fresh enough base system - so boot script and armbianEnv.txt are old enough to cause issues.

As stated in the documentation, overlays don't work on stable (or upgraded stable) images yet.

 

1 hour ago, nkahl said:

Using the 2.2 method, lines like these


[   62.195492] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.
[  125.795516] w1_master_driver w1_bus_master1: Family 0 for 00.400000000000.46 is not registered.
[  176.555608] w1_master_driver w1_bus_master1: Family 0 for 00.c00000000000.ca is not registered.
[  252.995466] w1_master_driver w1_bus_master1: Family 0 for 00.200000000000.23 is not registered.
[  316.595477] w1_master_driver w1_bus_master1: Family 0 for 00.a00000000000.af is not registered.
[  354.516052] w1_master_driver w1_bus_master1: Family 0 for 00.600000000000.65 is not registered.
[  394.995595] w1_master_driver w1_bus_master1: Family 0 for 00.e00000000000.e9 is not registered.
[  457.995555] w1_master_driver w1_bus_master1: Family 0 for 00.100000000000.9d is not registered.
[  497.115573] w1_master_driver w1_bus_master1: Family 0 for 00.900000000000.11 is not registered.
[  572.355679] w1_master_driver w1_bus_master1: Family 0 for 00.500000000000.db is not registered.

are showing up in dmesg.

This means that overlay was activated with different pin for W1 bus.

 

Again, the proper way for enabling W1 on mainline is editing and reompiling the DT or upgrading boot script, armbianEnv and kernel manually and then following the documentation for enabling overlays..

Link to post
Share on other sites

Hello,

 

thanks for your reply and the information.

 

What puzzles me is that there seems to be a w1-gpio overlay in /boot/dtb/overlays/ which looks - decompiled :) - quite good. However, it uses the "PI15" pin which does not exist on Banana Pi.

 

I try to change the used pin, since I don't know where to copy the code blocks mentioned by martinayotte on Apr. 16th.

 

Any results will be reported here.

 

Best regards,

Norbert Kahl

Link to post
Share on other sites

Nope, this doesn't work. I am now trying to do this:

On 4/16/2017 at 2:43 PM, martinayotte said:

You first need to decompile DTB into DTS and you need to add some thing like that in you DTS in PIO section :


                        w1_pins: w1_pins {
                                allwinner,pins = "PD14";
                                allwinner,function = "gpio_in"; // in (initially)
                                allwinner,pull = <0>; // off
                        };

Then, at the root level :


                        w1: onewire@0 {
                                compatible = "w1-gpio";
                                pinctrl-names = "default";
                                pinctrl-0 = <&w1_pins>;
                                gpios = <&pio 3 14 0>; // PD14
                                status = "okay";
                        };

 

Although it does not became clear to me where exactly the code snippets must be copied to.

Link to post
Share on other sites

My decompiled DTS file now looks like this:

/dts-v1/;

/ {
	compatible = "allwinner,sun7i-a20";

	fragment@0 {
		target = <0xffffffff>;

		__overlay__ {

			w1_pins: w1_pins {
				allwinner,pins = "PH20"; // use PH20 pin for 1-Wire
				allwinner,function = "gpio_in";
				alwinner,pull = <0>;
				linux,phandle = <0x1>;
				phandle = <0x1>;
			};
		};
	};

	fragment@1 {
		target-path = [2f 00];

		__overlay__ {

			w1: onewire@0 {
				compatible = "w1-gpio";
				pinctrl-names = "default";
				pinctrl-0 = <&w1_pins>;
				gpios = <&pio 7 20 0>; // PH20 seems to be "7 20", "3" belongs to different GPIO header
				status = "okay";
			};
		};
	};

	__symbols__ {
		w1_pins = "/fragment@0/__overlay__/w1_pins";
	};

	__fixups__ {
		pio = "/fragment@0:target:0", "/fragment@1/__overlay__/onewire@0:gpios:0";
	};

	__local_fixups__ {

		fragment@1 {

			__overlay__ {

				onewire@0 {
					pinctrl-0 = <0x0>;
				};
			};
		};
	};
};

And it won't compile:

root@bpi:~/own_dtb# dtc -I dts -O dtb sun7i-a20-w1-gpio.dts > sun7i-a20-w1-gpio.dtbo
ERROR (phandle_references): Reference to non-existent node or label "pio"

ERROR: Input tree has errors, aborting (use -f to force output)

Could somebody who got this 1-wire sensor stuff working just post his/her dts file?

Link to post
Share on other sites

3 minutes ago, nkahl said:

Thanks for the hint. I did this already, but there is no "pio"-section. Must I add it manually?

If you have a pull-up resistor you don't even need the pio block. Just add onewire@0 block to the root node /

			onewire@0 {
				compatible = "w1-gpio";
				gpios = <&pio 7 20 0>; /* PH20 */
				status = "okay";
			};

Also find "pinctrl@01c20800" block and add pio label to it:

pio: pinctrl@01c20800

 

Link to post
Share on other sites

Hello all,

 

of the occasion now comes a tutorial for how to set up a DS18B20 temperature sensor on a Banana Pi:

  1. Connect the sensor and a 4k7 pull-up resistor as shown in the attached circuit diagram. Make sure the Banana Pi is switched off to avoid any damage.
  2. Boot the BPi and log in as "root".
  3. Create a new directory in the root's home and copy the Banana Pi device tree (DTB) to it:
    mkdir dtb
    cp /boot/dtb/sun7i-a20-bananapi.dtb .
    cd dtb/

    Change to the new directory with the cd command.

  4. Decompile the DTB:

    dtc -I dtb -O dts sun7i-a20-bananapi.dtb > sun7i-a20-bananapi.dts

     

  5. Open the DTS file (which contains plaintext and is thereof human-readable), for example, with nano.

  6. Insert the following code block at the end of the file before the last line (containing };) - see attached screenshot if necessary:

    			onewire@0 {
    				compatible = "w1-gpio";
    				gpios = <&pio 7 20 0>; /* PH20 */
    				status = "okay";
    			};

     

  7. Search for "pinctrl@01c20800" in the file and go to it.

  8. Put a "pio: " before "pinctrl@01c20800" (see screenshot).

  9. Save your changes and exit the DTS file.

  10. Run the following commands:

    mv sun7i-a20-bananapi.dtb sun7i-a20-bananapi.dtb.orig
    dtc -I dts -O dtb sun7i-a20-bananapi.dts > sun7i-a20-bananapi.dtb
    cp sun7i-a20-bananapi.dtb /boot/dtb/sun7i-a20-bananapi.dtb
    sync
    shutdown -r now

    This will move the original DTB file to "sun7i-a20-bananapi.dtb.orig" (in case you need it in the future), compile the DTS file to a new DTB and copy this into /boot. Then your Banana Pi is restarted.

  11. Afterwards, the temperature sensor will show up in /sys/bus/w1/devices with a random ID.

  12. The temperature can be read out via:

    cat /sys/bus/w1/devices/[DS18B20 ID]/w1_slave

    Replace [DS18B20 ID] with the ID you see in the directory, it is usually beginning with "28-". The command's output will contain something like

    t=20312

    which is the temperature in Celsius (°C), here, it is ~ 20,3 °C.

This tutorial assumes that the sensor is connected to the PH20 pin, if you use another, you will need to edit the code snippets above.

 

Kudos to zador.blood.stained for all the help! :)

 

Further readings:

Best regards,

Norbert Kahl

727D00F62EB3A97.png

7B838DA29B19550.png

E577AFCD5CD8889.png

Edited by nkahl
Fixed errors
Link to post
Share on other sites

Hi all!

 

I have Cubieboard, not Banana, but the problem is similar, so I read all the tips and try to do everything...

 

If I understand correctly, PI15 is configured for 1-wire by default, so I need not to modify dtb/dts files

According to documentation in https://linux-sunxi.org/1-Wire I check

cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pinmux-pins |grep PI15

and receive output

pin 271 (PI15): onewire@0 1c20800.pinctrl:271 function gpio_in group PI15

so I connected my sensor to PI15 with resistor 4k7, add sun4i-a10-w1-gpio in /boot/armbianEnv.txt and hope to see  smth in /sys/bus/w1/devices

 

w1_bus_master1 appears and several directories 00-хх000000000, but nothing like the correct sensor.

 

what else do I need to do or check?

 

 

Link to post
Share on other sites

Hi!

I solved the problem, but still don't understand the source of the error.

 

that's what I did:

 

1. connected the sensor to PI15 without any modifying dts/dtb, as i wrote in previous post. result - negative.

 

2. modified dts/dtb to define PI16 as w1_bus_master, according to nkahl's manual (great thanks to him!). I received two directories w1_bus_master1 and w1_bus_master2 and up to five directories like 00-хх000000000 but nothing like real sensor response

 

3. a lot of thought...

 

4. hooked up saleae logic analyzer to PI16 to see how bus master seaches slaves - nothing activity! on one side, I've seen messages in dmesg where bus_master is searching slaves, on other side - no any signal on pin

 

5. a lot of thought... again

 

6. exported PG0 as gpio output, test with "echo 1 > ...   echo 0 > ..." - everything worked, did the same with PI16 - nothing worked. system executed my commands without any effect in real. I wrote value "1", then read it - really "1", but real state of the pin was LOW.

 

7. a little thought :)

 

8.  modified dts/dtb to define PG0 as w1_bus_master, connected sensor and..... BLISS!!!!!  I finally found out the temperature in the room :)

 

in fact i understood that must avoid using pins PIxx

 

I have two proposals about this abnormality 1) it is a little bug in armbian (or, may be, an unknown to me feature)  2) hardware error, however my cubieboard is absolutely new

 

I will be glad to hear any comments

 

 

Link to post
Share on other sites

On 5/2/2017 at 0:05 PM, nkahl said:

Hello all,

 

of the occasion now comes a tutorial for how to set up a DS18B20 temperature sensor on a Banana Pi:

 

 

I tried to follow your steps, but I still get these:

 

Quote

$ dmesg | grep w1
[   15.893944] w1_master_driver w1_bus_master1: w1_search: max_slave_count 64 reached, will continue next search.
[   67.319719] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.
[  130.944923] w1_master_driver w1_bus_master1: Family 0 for 00.400000000000.46 is not registered.
[  181.688801] w1_master_driver w1_bus_master1: Family 0 for 00.c00000000000.ca is not registered.
[  258.775418] w1_master_driver w1_bus_master1: Family 0 for 00.200000000000.23 is not registered.
[  323.731530] w1_master_driver w1_bus_master1: Family 0 for 00.a00000000000.af is not registered.
[  361.583136] w1_master_driver w1_bus_master1: Family 0 for 00.600000000000.65 is not registered.
[  402.156470] w1_master_driver w1_bus_master1: Family 0 for 00.e00000000000.e9 is not registered.
[  465.759980] w1_master_driver w1_bus_master1: Family 0 for 00.100000000000.9d is not registered.
[  504.842482] w1_master_driver w1_bus_master1: Family 0 for 00.900000000000.11 is not registered.
[  580.773234] w1_master_driver w1_bus_master1: Family 0 for 00.500000000000.db is not registered.
[  633.335167] w1_master_driver w1_bus_master1: Family 0 for 00.d00000000000.57 is not registered.
[  659.813141] w1_master_driver w1_bus_master1: Family 0 for 00.300000000000.be is not registered.
[  709.171637] w1_master_driver w1_bus_master1: Family 0 for 00.b00000000000.32 is not registered.
[  748.467639] w1_master_driver w1_bus_master1: Family 0 for 00.700000000000.f8 is not registered.
[  800.467509] w1_master_driver w1_bus_master1: Family 0 for 00.f00000000000.74 is not registered.
[  864.184568] w1_master_driver w1_bus_master1: Family 0 for 00.080000000000.c2 is not registered.
[  917.469077] w1_master_driver w1_bus_master1: Family 0 for 00.880000000000.4e is not registered.
[  956.569430] w1_master_driver w1_bus_master1: Family 0 for 00.480000000000.84 is not registered.
[ 1007.428226] w1_master_driver w1_bus_master1: Family 0 for 00.c80000000000.08 is not registered.
[ 1085.843027] w1_master_driver w1_bus_master1: Family 0 for 00.280000000000.e1 is not registered.
[ 1150.068100] w1_master_driver w1_bus_master1: Family 0 for 00.a80000000000.6d is not registered.

 

Should it work on Armbian 5.25 and kernel 4.9.7 Feb 2 01:52:06 CET 2017?

 

Link to post
Share on other sites

Update: issue solved. Me stupid: I started with adding a w1-gpio overlay in ArmbianEnv.txt and I forgot to remove that. After removing it works like a charm!! Excuse me ...

 

First thanks to everyone contributing to this forum and this specific topic!

 

I followed the tutorial of @nkahl above to use DS18B20 sensors for my BananaPi running ARMBIAN 5.31 with kernel 4.11.6-sunxi.

Unfortunately it doesn't work.

 

Is the following: 

root@bananapi:/sys/bus/w1/devices# dmesg | grep w1
[   12.679227] w1_master_driver w1_bus_master1: w1_search: max_slave_count 64 reached, will continue next search.
[   65.428475] w1_master_driver w1_bus_master1: Family 0 for 00.800000000000.8c is not registered.
[  129.013222] w1_master_driver w1_bus_master1: Family 0 for 00.400000000000.46 is not registered.

and

 

root@bananapi:/sys/bus/w1/devices# cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pinmux-pins |grep PH20
pin 244 (PH20): (MUX UNCLAIMED) (GPIO UNCLAIMED)

A 4k7 restore between 5V and data has been applied.

 

As a newbie I think pin PH20 hasn't been configured for Onewire,  despite the onwire@0 block in the code @nkahl provided.

Link to post
Share on other sites

Hi everybody.

Recenly I've moved to Armbian mainline from Bananian on my Banana pro. 'uname -r' is now saying "BPro 4.14.18-sunxi #24 SMP Fri Feb 9 16:24:32 CET 2018 armv7l GNU/Linux".

I tried to make ds18b20 work but had no luck.

First I've decompiled /boot/dtb/overlay/sun7i-a20-w1-gpio.dtbo, edited dts section to look like this:

        __overlay__ {

            w1_pins {
                pins = "PB6";
                function = "gpio_in";
                linux,phandle = <0x1>;
                phandle = <0x1>;
            };

I connected, data line of sensor to pin 38 and pulled it up by external resistor.

Then I compiled dts to dtbo, replaced original .dtbo file and added "overlays=w1-gpio" string to armbianEnv.txt. What I get after reboot:

root@BPro:~/dtb# cat /sys/kernel/debug/pinctrl/1c20800.pinctrl/pinmux-pins |grep onewire
pin 38 (PB6): onewire@0 (GPIO UNCLAIMED) function gpio_in group PB6
root@BPro:~/dtb# ls /sys/bus/w1/devices/
w1_bus_master1
root@BPro:~/dtb# dmesg |grep w1
 

So sensor doesn't work and what is strange for me, there is no even a word about w1 driver in dmesg. What can be the problem?

Link to post
Share on other sites

Had no luck with overlay, I tried to change .dtb file and got this:

dmesg |grep w1
[   10.673288] w1-gpio onewire@0: Failed to parse gpio property for data pin (-2)
[   10.673318] w1-gpio: probe of onewire@0 failed with error -2
 

So Please can anyone help me? Any thoughts or suggestions?

Link to post
Share on other sites

Guest
This topic is now closed to further replies.
 Share

6 6