How to expand GPIO outputs for Android 9 app

Hi everyone,

I recently bought the VIM3 board because I’d like to develop an Android 9 app where control 6 GPIO outputs for blink some leds. I’ve been searching info through the forum, documentation, etc, and (if I’m not wrong) I’ve seen that VIM3 comes with only 2 GPIO outputs enabled by default on Android. Also I’ve read here (Unexportable GPIO pins on VIM3L) and here (VIM3L GPIO capability) that it’s possible to expand this number of outputs but it seems that it’s only for linux.

Can somebody confirm me if it’s that possible for Android? In that case, could you please explain me or at least guide me on how to do this for investigate on depth?

Thanks in advance.

Hello again!

Since yesterday I’d been investigating and searching information around this community and I found some interesting post that shed some light on the matter.

About this post by @Beir8 (How to access GPIO on Android pie?) I clarified that there is a way to configure more than one pin of the 40-pin GPIO header to make them work as digital input/output on Android Pie. Additionally, @Beir8 's post explains how to modify files in kernel to achieve that GPIO functionality. In there it indicates that it’s necessary to rebuild the Android image to apply that settings. I’ve never done this so I searched on the forum again and I found a related topic where it’s explained how to do it (Building Android Pie for VIM3).

In my application I would like to use the 6 yellow highlighted pins:

Five of them are used for I2S audio, but I think that they can be defined for GPIO as we can see here:

On the other hand, in one of the above mentioned post I found that @quatro explains how it’s posible to disable I2S audio to gain access to pins 29 to 33. The last one (pin 39) I think that is already available by default for GPIO. Therefore, my goal is for the pins to be as follows:

PIN 29 - GPIOA_1
PIN 30 - GPIOA_0
PIN 31 - GPIOA_3
PIN 32 - GPIOA_2
PIN 33 - GPIOA_4
PIN 39 - GPIOZ_15

At this point a question arises for me:

  • How do we calculate the GPIO number list for those pins export?

I would appreciate any suggestion to achieve my objective or any recommendation on that topic. Thanks in advance!

The PIN29 ~ PIN33 is configured as i2s output. You must build your android ROM with source code If you want to use these pins as gpio

Thank you for your reply @Terry !

So is it possible to do it following the steps that you explain here? (Android 7, GPIO)
In that post for Android 7 on VIM1 you say that it’s necessary to modify two files “kvim.dts” and “mesongxl.dtsi”. It is the same for Android 9 on VIM3?

Thank you.

HI, 你好, 也在这贴一起问下,
参考
image
NAME NUM MAX
GPIOA 0-15 16
GPIOAO 0-11 12
GPIOH 0-8 9
GPIOC 0-7 8
GPIOE 0-2 3
GPIOX 0-19 20
GPIOZ 0-15 16

console:/sys/class/gpio # ls
export gpiochip410 gpiochip496 unexport
这些引脚GPIO的地址是如何分配的?

起点410? 最大496, 那每组GPIO的顺序是怎么样的? 就是每组的每个GPIO是如何计算地址值的,

统计了下GPIO只有84个, 496-410有86个, 比84多出了2个.

谢谢, 待复!

你可以进/sys/kernel/debug/pinctrl看下这些管脚。

At the end, I achieved to expand the number of GPIO digital outputs for my android application. As I explained above, I followed various tips that I found on the forum (thanks @Terry), but the key one was (Unexportable GPIO pins on VIM3L - #13 by quatro) by @quatro. Commenting “pinctrl-0” line of tdmb device on /common/arch/arm64/boot/dts/amlogic/kvim3.dts file, it disabled I2S audios and allowed to export GPIOA_0 to GPIOA_4 pins.
I hope that can help other people with the same matter on the future.

3 Likes

Hello, antoniayza.

I’m very interested in your post, and I’m facing same issue with you.
At startup of your post, you wrote that you have seen that VIM3 comes with only 2GPIO outputs enabled by default on Android.

Can you please explain in detail how did you find this?
Thanks

Hello @ming2022 ,

I found this on Khadas Docs: Access GPIO Uasge | Khadas Documentation

It shows a table with available GPIOs:

image

Hi! Do I understand right, if I make changes in kvim3.dts, then building boot image and then flashing it on my device, it will apply changes? Or how did u do it?

I tried to flash dt.img and now I can access this pins! Hooray!

1 Like

Hi @AllCach ,

Which ROM version did you use? I tried with newest versions and this method is not working anymore for me.

Did you make any additional configuration to enable the GPIOs that is not mentioned above?

Thanks!

Hi @antoniayza!
I compiled Android according to the instructions in the official documentation, it’s Android Pie(9.0). I installed this OS on VIM3. Then I edited the dts file, built the boot image, flash the dt image and that’s it.
I’m sorry, I don’t know how to help you

OK, so I understand that you downloaded directly from source code, right?

Yes, I did it with
repo init -u https://github.com/khadas/android_manifest.git -b khadas-vim3-p-64bit --depth=1