Posts tagged nanopi
[Electronics] Nanopi A64 and the GPIO
NanoPi_A64-1.jpg

Recently I “found” some Nanopi A64 (micro computer made by FriendlyARM similar to Raspberry Pi) that were unused. After some research, I found the official wiki and decided to try them out! My first step was to install an OS, I tried the two OS proposed by FriendlyARM which are Ubuntu-Core and Ubuntu-Mate (Mate has an UI).

And success, they boot and those OSs seems working pretty find! So naively I thought: “Cool I’ve two little electronic circuits that I can use as Raspberry Pi and I got them for free!”. At this point, I want to try to access the GPIO and try to install the common GPIO library for Raspberry PI since on the wiki I found “GPIO pin-header compatible with Raspberry Pi “ . Long story short didn’t work at all. After some research on internet, FriendlyARM doesn’t provide any GPIO support for the Nanopi A64 and I never found anybody working with the GPIO on this board…

At this point, I thought that GPIO on this board couldn’t be accessible. After some research, I found a thread on Armbian forum called Build libgpiod the "New GPIO Interface for User Space" . I gave a look and it’s talking about Nanopi and a library called libgpiod . So time to give it at try! Let’s install this lib on our Ubuntu-Core or Ubuntu-Mate! Again, didn’t work either…

This reference about libgpiod and Nanopi was on Armbian forum so now my guess is to have an Armbian that work for Nanopi A64! Guess what, it’s not officially supported.. but after some research I found that on the same forum: [Experiment] armbian on NanoPi A64 . Apparently, some people succeded to install Armbian on Nanopi A64 and there is a description of the few tricks to do it!

So it was time to clone the Armbian Git and try to compile an Armbian for my Nanopi A64! And guess what, it worked! For the people that want to do it too, I’ll resume the manipulation that I made according to the “guidol” (all credits to him for this part!) modification to do it:

After cloning the Armbian build git, create an new configuration for the nanopia64 in ./build/config/boards/nanopia64.conf

# A64 quad core 512MB-2GB SoC GBE
BOARD_NAME="NanoPiA64"
BOARDFAMILY="sun50iw1"
BOOTCONFIG_DEFAULT="sun50iw1p1_config"
BOOTCONFIG="nanopi_a64_defconfig"
#
MODULES="sunxi_codec sunxi_i2s sunxi_sndcodec 8723bs"
MODULES_NEXT=""
#
KERNEL_TARGET="default,next,dev"
CLI_TARGET="bionic,stretch:next"
DESKTOP_TARGET="xenial:default"
#
CLI_BETA_TARGET=""
DESKTOP_BETA_TARGET=""

Then compile Armbian with ./compile.sh EXPERT="yes" and select Nanopi A64 for the platform. In my case I also selected DEV for linux kernel. My result is then: Arbian_5.78_Nanopia64_Debian_stretch_dev_5.0.7.img (guidol was Armbian_5.71_Nanopia64_Debian_stretch_dev_4.20.0 )

This image boot well on the Nanopi A64 but USB is not enabeld. guidol also provide a fix for that by modifying the device tree:

Copy the /boot/dtb/allwiner/sun50i-a64-nanopia64.dtb and do those operation:

DTC-decompile .dtb to .dts
dtc -I dtb -O dts ./sun50i-a64-nanopi-a64.dtb -o sun50i-a64-nanopi-a64.dts

Modify the dts as so:

NanoPi A64 (standard)
=====================

                usb@1c19000 {
                        compatible = "allwinner,sun8i-a33-musb";
                        reg = <0x1c19000 0x400>;
                        clocks = <0x2 0x29>;
                        resets = <0x2 0x12>;
                        interrupts = <0x0 0x47 0x4>;
                        interrupt-names = "mc";
                        phys = <0x21 0x0>;
                        phy-names = "usb";
                        extcon = <0x21 0x0>;
                        status = "disabled";
                        phandle = <0x54>;
                };

 

NanoPi A64 (activated / changed)
================================

                usb@1c19000 {
                        compatible = "allwinner,sun8i-a33-musb";
                        reg = <0x1c19000 0x400>;
                        clocks = <0x2 0x29>;
                        resets = <0x2 0x12>;
                        interrupts = <0x0 0x47 0x4>;
                        interrupt-names = "mc";
                        phys = <0x21 0x0>;
                        phy-names = "usb";
                        extcon = <0x21 0x0>;
                        status = "okay";
                        dr_mode = "host";

                        phandle = <0x54>;
                };    

DTC-compile .dts to .dtb
dtc -I dts -O dtb ./sun50i-a64-nanopi-a64_guido3.dts -o sun50i-a64-nanopi-a64_temp.dtb

then copy it to /boot/dtb/allwinner and reboot
cp sun50i-a64-nanopi-a64_temp.dtb /boot/dtb/allwinner/sun50i-a64-nanopi-a64.dtb

Now congrats, you have an Armbian that works with the USB! It’s time to try to use the GPIO! After cloning the libgpiod git and compiling it with (I added the binding for python):

   ./autogen.sh --enable-tools=yes --enable-bindings-python
    make
    make install

Hurray libgpiod is installed let’s try the command available!

root@nanopia64:#   gpiodetect   
gpiochip0 [1f02c00.pinctrl] (32 lines)    
gpiochip1 [1c20800.pinctrl] (256 lines)  
gpiochip2 [axp20x-gpio] (2 lines)    

So our gpiochip are detected, that means we can have access our GPIO! So let’s try to use the GPIO header. I put a little led on the pin40 of the header called GPIOD1. First guess for me it’s either the line 40 or the line 1 of one of the gpiochip, guess what it’s not… With a little "for loop”, I found that this GPIOD1 is the line 97 of gpiochip1. Why is that? At this point, I did some research on Nanopi GPIOand found on the friendlyARM wiki a GPIO part. With that, I learned a bit about the offset and understand a bit better how I could find the number of my GPIOs. I also did the command proposed on this wiki and here are the results:

root@nanopia64:~#   cd /sys/class/gpio              
root@nanopia64:/sys/class/gpio# for i in   gpiochip* ; do echo `cat $i/label`: `cat $i/base` ; done   
1c20800.pinctrl: 0       
1f02c00.pinctrl: 352       
axp20x-gpio: 510              
root@nanopia64:/sys/class/gpio# cat   /sys/kernel/debug/gpio       
gpiochip1: GPIOs 0-255, parent:   platform/1c20800.pinctrl, 1c20800.pinctrl:   
gpio-120 ( nanopi-a64:blue:stat)   out hi ACTIVE LOW 
gpio-166 (|cd ) in  lo ACTIVE LOW  
gpiochip0: GPIOs 352-383, parent:   platform/1f02c00.pinctrl,
1f02c00.pinctrl:        gpio-354 (|reset) out hi ACTIVE LOW  
gpiochip2: GPIOs 510-511, parent:   platform/axp20x-gpio, axp20x-gpio, can sleep:    

With that and a lot of time, I mapped all the GPIO on the header of the Nanopi a64, all of them have been tested with gpioset and gpioget from libgpiod and also with the python binding:

GPIO A64 GPIO.PNG

As you could see I only tried the GPIO available on the header, I didn’t try the DVP Camera IF Pin and the MIPI-DSI Pin but the process must be the same and numbering too then. On the right you can see the corresponding GPIO line offset that I found. Sadly I didn’t succeed to access GPIOE (pin 3 and 5 on the header) and when I tried to access from gpio 192 to 223 of gpiochip1, the Nanopi crashed.

So now you have my results! I succeeded finally to access those GPIO on the Nanopi A64! Still some work to do to try all the GPIO and all of their features (right now working on the I2C). If you have a Nanopi A64 and try to access the GPIO I would love to hear about it!