如何从 OpenWRT 构建的 UBoot 读取 GPIO 值

How to read a GPIO value from UBoot built by OpenWRT

我正在尝试在由 OpenWRT 驱动的开发板上实现恢复模式。 我有一个按钮连接到一些 GPIO:GPIO_PL4.

我使用下一个表达式将 gpio 名称转换为数字表示形式:

(position of letter in alphabet - 1) * 32 + pin number

所以我得到了 PL4 -- 356 映射。

我试图将下一行添加到 uboot 环境文件 uEnv-default.txt:

  if gpio input 356; then
     echo "The button is pressed";
  fi;

但是在启动过程中收到错误消息:

  gpio: requesting pin 356 failed
  gpio - query and control gpio pins

  Usage:
  gpio <input|set|clear|toggle> <pin>
      - input/set/clear/toggle the specified pin
  gpio status [-a] [<bank> | <pin>]  - show [all/claimed] GPIOs

然后我尝试使用 gpio status -a:

获取有关 GPIO 的信息
gpio status -a (within uEnv-default.txt)

得到下一个输出:

Bank PA:
...
Bank PL:
PL0: func
...
PL4: func     // does it mean that I'm not able to use it as an input
...
PL11: func
PL12: input: 0 [ ]
PL13: input: 0 [ ]
....

所以问题是:我能否使用 PL4 gpio 引脚作为当前 gpio 配置的输入,如果不能,我如何更改此引脚的 gpio 配置(如果可能的话)?

我想,我必须在 U-Boot 上应用补丁才能进行正确的 gpio 配置,对吗?

我找到了解决办法。有两个问题:

  1. U-boot (2018.11) for sunxi-8 devices, 至少,不使用上面的表达式将 gpio 名称转换为数字表示(可以为 u-boot 输入 gpio 名称 gpio 命令:gpio input pl4).
  2. 端口L,默认情况下在sunxi-8 cpus 上是未时钟/未供电的,至少是sun8i-h2-plus-orangepi-zero板,所以它必须是clocked/powered 通过 prcm_apb0_enable。看看https://forum.armbian.com/topic/10111-orange-pi-zero-u-boot-gpio-access/?tab=comments#comment-76996