2 2
Rolf Bakker

NanoPi Neo 2 - set input pull-up via Device Tree

Recommended Posts

I had a hard time to figure out how to set the input pull-up on GPIO 1 of the NanoPi neo2. In the end it appeared to be extremely simple, but in order to help other beginners I like to share how I accomplished it.

1) I created a dts file with the input pull-up definition for GPIO 1
2) I compiled the dts with the "armbian-add-overlay" tool
3) rebooted the NanoPi Neo2 

That's it.

The dts file can be placed anywhere on the Nanopi Neo2 eg. /home/pi/sun50i-h5-nanopi-neo2-pullup.dts
 

nano /home/pi/sun50i-h5-nanopi-neo2-pullup.dts


The content of sun50i-h5-nanopi-neo2-pullup.dts looks like this:

 

/dts-v1/;                                                                       
/plugin/;                                                                       
                                                                                
/ {                                                                             
        compatible = "allwinner,sun50i-h5";                                     
                                                                                
          fragment@0 {                                                          
            target = <&pio>;                                                    
            __overlay__ {                                                       
              input_0: input_0 {                                                
                pins = "PA1";                                                   
                function = "gpio_in";                                           
                bias-pull-up;                                                   
              };                                                                
            };                                                                  
          };                                                                    
                                                                                
};   


note that PIN "PA1" = GPIO 1 (BCM) 

now save the file (press ctrl-x, press y, press enter)

 

start the "armbian-add-overlay" tool
 

sudo armbian-add-overlay /home/pi/sun50i-h5-nanopi-neo2-pullup.dts

when the tool finishes, you will have to reboot to apply the changes.

That's it, I hope you save some time with this monkey proof explanation.


PS:
it is easy to convert BCM to PIN, e.g. GPIO 200 (BCM) = PIN "PG8" 
The letters A - G have the following values A=0, B=1, C=2 ... G=6
The value of the letter must be multiplied by 32, so G = 6x32 = 192
The value behind the letter is added to the value of the letter, in this case for PG8: 192 + 8 = 200
So BCM GPIO 200 is the same pin as PG8.
To derive the PIN from BCM you just do it the other way around.

e.g.
GPIO 6 (BCM) = PIN "PA6"
GPIO 201 (BCM) = PIN "PG9"

Share this post


Link to post
Share on other sites

First of all thank you for this post; it helped a lot.

 

But, I've just went through a similar journey and wonder if this is a complete solution. Your 'fragment@0' does what it intends but in my experience it was only half of the solution. My gleanings through various sources indicates that to actually accomplish something a second piece of the puzzle (for arguments sake 'fragment@1') is needed and it must reference the name (or alias?) of 'fragment@0'. I guess the reference could come from some other dts file but, normally, from, at least, another overlay file, or within the same overlay file.

 

The point I'm trying to make is that 'fragment@0' on its own did little. I found that setting 'bias-pull-up' will not result in seeing '1' on a gpio pin without another device-tree node referencing that pin. As far as I can see something like https://forum.armbian.com/topic/6723-gpio-keys-mainline-linux/ with 'fragment@1' referencing 'fragment@0' (through the line 'pinctrl-0 = <&gpio_keys>;' in that instance) only then would apply the 'bias-pull-up'.

 

I'm not advocating for how this appears to me at the moment. I'd rather use a gpio on its own if possible (perhaps there's a 'compatible = XXX' that I haven't found yet).

 

Share this post


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