GPIO export on Ubuntu is not working. What's the problem?

I’m using Vim_Ubuntu-mate-16.04_Linux-4.9_V170605
And it’s not working:
root@Khadas:/sys/class/gpio# echo 176 > export
bash: echo: write error: Invalid argument

wrong gpio export number? Can you please tell me the correct ones?

Hi kkkkk,

For ubuntu version Vim_Ubuntu-mate-16.04_Linux-4.9_V170605 gpio number is:

PIN         GPIO         Number
PIN37       GPIOH5         31
PIN33       GPIOAO6        6

Thank you. :flushed: only 2? There’re at least 6 of them on your scheme. What happened to others?

Hi kkkkk,

GPIOH_6/7/8/9 are default configured as JTAG. So if you want to use them as GPIO you have to disable JTAG function.

Enter uboot command line and append jtag=disable to bootargs to disable JTAG.

diff --git a/board/khadas/configs/kvim.h b/board/khadas/configs/kvim.h
index 540b09c..bb00e10 100644
--- a/board/khadas/configs/kvim.h
+++ b/board/khadas/configs/kvim.h
@@ -88,7 +88,7 @@
     "fb_height=1080\0" \
     "bootdisk=ramdisk\0" \
        "bootargs=" \
-            "root=LABEL=ROOTFS rootflags=data=writeback rw logo=osd1,loaded,0x3d800000,1080p60hz vout=1080p60hz,enable hdmimode=1080p60hz console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.repair=yes net.ifnames=0\0" \
+            "root=LABEL=ROOTFS rootflags=data=writeback rw logo=osd1,loaded,0x3d800000,1080p60hz vout=1080p60hz,enable hdmimode=1080p60hz console=ttyS0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.repair=yes net.ifnames=0 jtag=disable\0" \
     "\0" \

Then GPIO_H6/7/8/9 is

PIN         GPIO         Number
PIN30       GPIOH6         32
PIN29       GPIOH7         33
PIN32       GPIOH8         34
PIN31       GPIOH9         35

thank you! Can you please tell me the correct /etc/fw_env.config for your image?
I’ve tried to use "/dev/mmcblk0 0x80000 0x8000"
but after fw_setenv jtag=disable vim doesn’t load anymore with:

DataBus test pass!
AddrBus test pass!
-s
Load fip header from eMMC, src: 0x0000c200, des: 0x01400000, size: 0x00004000
New fip structure!
Load bl30 from eMMC, src: 0x00010200, des: 0x01100000, size: 0x0000d600
Load bl31 from eMMC, src: 0x00020200, des: 0x10100000, size: 0x00015400
Load bl33 from eMMC, src: 0x00038200, des: 0x01000000, size: 0x000a5c00
aml log : SIG CHK : 300 for address 0x01000000
reset...

But it’s a good reason to install new Ubuntu image you’ve made. Still the question how to write uboot env persist.

Hi!
For my application requirements, I also need to know the numbers for some other PINs. Please kindly help me out here. Thank you.

PIN10
PIN12
PIN15
PIN16
PIN19

PIN33
PIN35
PIN37
PIN39

Hi chrislin,

For current firmware, the following PINs can’t use as GPIO.

PIN10 --> ADC_CH0
PIN12 --> ADC_CH2
PIN15 --> UART_RX_AO_B
PIN16 --> UART_TX_AO_B
PIN19 --> Linux_TX

Other GPIOs:

PIN       GPIO         Number
PIN33     GPIOAO_6      6
PIN35     GPIOAO_3      3
PIN37     GPIOH5        32
PIN39     GPIODV_13     73

Hi! Please kindly advise me how to modify firmware, if possible, so that I can use PIN10, PIN12, PIN15, PIN16, PIN19 instead. Thank you in advance.

Hi chrislin,

Are you a developer? If so you can try to build your own image, and you can modify the kernel as you want. Please refer to the following topic.
http://forum.khadas.com/t/use-fenix-scripts-to-build-your-own-ubuntu-image/1256

Good Luck!

Hi! After checking with the support, it seems the following PINs can be used as well. Please kindly provide me their “Number” respectively.

PIN13
PIN15
PIN16
PIN25
PIN26

By the way, please kindly advise me how to get the “Number” for some other PINs by myself?

Thank you in advance.

Cheers,

Hi chrislin,

For linux 4.9.40, you can find the GPIO number here:

For example,

PIN33 --> GPIOAO_6 --> MESON_PIN(GPIOAO_6, 0),

GPIOAO_6-- > 6, so PIN33--> (6 + 0)=6

Hi!
I have VIM2 with VIM2_DualOS_Nougat_Ubuntu-16.04_V170818.
In МАТЕ terminal I wrote:
root@khadas: echo 73 > /sys/class/gpio/export
root@khadas: echo out > /sys/class/gpio/gpio73/direction
root@khadas: echo 0 > /sys/class/gpio/gpio73/value
I expected to see 0V on pin 39, but in fact there is 1.5V.
Next I wrote:
root@khadas: echo 1 > /sys/class/gpio/gpio73/value
I expected to see 3.3V on pin 39, but in fact there is 1.5V.

What did I do wrong? How should I do it?
Is it possible to connect a LED with a 220 ohm resistor to the GPIO?

Hmmm… PIN6 work fine… I do not understand anything …

Dear Khadas staff,

WHY are you messing up all the GPIO numbers every time you create a new Linux image? With the latest [VIM1_Ubuntu-xfce-bionic_Linux-4.9_arm64_EMMC_V20190830] the GPIO is totally unusable for me once again.

root@Khadas:/sys/class/gpio# echo 176 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 6 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 31 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 33 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 34 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 35 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 73 > export
-su: echo: write error: Invalid argument
root@Khadas:/sys/class/gpio# echo 3 > export
-su: echo: write error: Invalid argument

PLEASE keep some GPIO numbering consistency from a version to a version. I’m lucky to have an UART/Modbus channel to my I/O over ttyS4, but it would be nice if the few indicator LEDs could also continue to work after kernel upgrades.