GNU/Linux - U-BOOT的GPIO command

在嵌入式Linux开发中,先运行的是u-boot,然后再加载Linux内核。

启动时如果设置了u-boot等待时间,在等待时间内,按任意键就会进入u-boot命令行环境。

在u-boot命令行环境下,可以使用gpio命令来操作GPIO。

Synopsis

gpio <input|set|clear|toggle> <pin>

gpio read <name> <pin>

gpio status [-a] [<bank>|<pin>]

gpio 命令用于访问通用输入/输出。

The gpio command is used to access General Purpose Inputs/Outputs.

gpio input

将 GPIO 引脚切换为输入模式。

Switch the GPIO pin to input mode.

gpio set

将 GPIO 引脚切换至输出模式,并将信号设置为 1。

Switch the GPIO pin to output mode and set the signal to 1.

gpio clear

将 GPIO 引脚切换至输出模式,并将信号设置为 0。

Switch the GPIO pin to output mode and set the signal to 0.

gpio toggle

将 GPIO 引脚切换至输出模式,并反转信号状态。

Switch the GPIO pin to output mode and reverse the signal state.

gpio read

读取 GPIO 引脚的信号状态,并将其保存在环境变量名称中。

Read the signal state of the GPIO pin and save it in environment variable name.

gpio status

显示一个或多个 GPIO 的状态。默认情况下,只显示声称的 GPIO。 gpio status 命令的输出字段有:

Display the status of one or multiple GPIOs. By default only claimed GPIOs are displayed. gpio status command output fields are:

<name>: <function>: <value> [x] <label>

函数可以取以下值:

function can take the following values:

  • output

pin configured in gpio output, value indicates the pin’s level

  • input

pin configured in gpio input, value indicates the pin’s level

  • func

pin configured in alternate function, followed by label which shows pinmuxing label.

  • unused

pin not configured

[x] or [ ] indicate respectively if the gpio is used or not.

label shows the gpio label.

Parameters

  • -a

Display GPIOs irrespective of being claimed. 显示 GPIO,无论其是否被申领。

  • bank

Name of a bank of GPIOs to be displayed. 显示 GPIO 组的名称。

  • pin

Name of a single GPIO to be displayed or manipulated.要显示或操作的单个 GPIO 的名称。

Examples

Switch the status of a GPIO:

=> gpio set a5

gpio: pin a5 (gpio 133) value is 1

=> gpio clear a5

gpio: pin a5 (gpio 133) value is 0

=> gpio toggle a5

gpio: pin a5 (gpio 133) value is 1

=> gpio read myvar a5

gpio: pin a5 (gpio 133) value is 1

=> echo $myvar

1

=> gpio toggle a5

gpio: pin a5 (gpio 133) value is 0

=> gpio read myvar a5

gpio: pin a5 (gpio 133) value is 0

=> echo $myvar

0

Show the GPIO status:

=> gpio status

Bank GPIOA:

GPIOA1: func rgmii-0

GPIOA2: func rgmii-0

GPIOA7: func rgmii-0

GPIOA10: output: 0 [x] hdmi-transmitter@39.reset-gpios

GPIOA13: output: 1 [x] red.gpios

Bank GPIOB:

GPIOB0: func rgmii-0

GPIOB1: func rgmii-0

GPIOB2: func uart4-0

GPIOB7: input: 0 [x] mmc@58005000.cd-gpios

GPIOB11: func rgmii-0

Configuration

gpio 命令只有在 CONFIG_CMD_GPIO=y 时可用。gpio 读取命令只有在 CONFIG_CMD_GPIO_READ=y 时可用。

The gpio command is only available if CONFIG_CMD_GPIO=y. The gpio read command is only available if CONFIG_CMD_GPIO_READ=y.

Return value

如果命令成功执行,返回值 $? 设置为 0;如果命令出错,返回值 $? 设置为 1。

If the command succeds the return value $? is set to 0. If an error occurs, the return value $? is set to 1.


我的u-boot版本和构建信息:

u-boot=> help

...

version   - print monitor, compiler and linker version

...

u-boot=> version

U-Boot 2023.04-lf_v2023.04+g49b102d988 (Nov 21 2023 - 07:28:53 +0000)

aarch64-poky-linux-gcc (GCC) 12.3.0

GNU ld (GNU Binutils) 2.40.0.20230703

u-boot=> gpio status -a

Bank GPIO2_:

GPIO2_0: input: 1 [ ]

GPIO2_1: output: 0 [ ]

GPIO2_2: input: 0 [ ]

GPIO2_3: input: 0 [ ]

GPIO2_4: input: 0 [ ]

GPIO2_5: input: 0 [ ]

GPIO2_6: input: 0 [ ]

GPIO2_7: input: 0 [ ]

GPIO2_8: input: 0 [ ]

GPIO2_9: input: 0 [ ]

GPIO2_10: input: 0 [ ]

GPIO2_11: output: 0 [ ]

GPIO2_12: input: 0 [ ]

GPIO2_13: input: 1 [ ]

GPIO2_14: input: 0 [ ]

GPIO2_15: input: 0 [ ]

GPIO2_16: input: 0 [ ]

GPIO2_17: input: 0 [ ]

GPIO2_18: input: 0 [ ]

GPIO2_19: input: 0 [ ]

GPIO2_20: input: 0 [ ]

GPIO2_21: input: 0 [ ]

GPIO2_22: input: 1 [ ]

GPIO2_23: input: 0 [ ]

GPIO2_24: input: 0 [ ]

GPIO2_25: input: 0 [ ]

GPIO2_26: input: 0 [ ]

GPIO2_27: input: 0 [ ]

GPIO2_28: input: 1 [ ]

GPIO2_29: input: 0 [ ]

GPIO2_30: input: 0 [ ]

GPIO2_31: input: 0 [ ]

Bank GPIO3_:

GPIO3_0: input: 1 [x] mmc@42860000.cd-gpios

GPIO3_1: input: 0 [ ]

GPIO3_2: input: 0 [ ]

GPIO3_3: input: 0 [ ]

GPIO3_4: input: 0 [ ]

GPIO3_5: input: 0 [ ]

GPIO3_6: input: 0 [ ]

GPIO3_7: input: 0 [ ]

GPIO3_8: input: 0 [ ]

GPIO3_9: input: 0 [ ]

GPIO3_10: input: 0 [ ]

GPIO3_11: input: 0 [ ]

GPIO3_12: input: 0 [ ]

GPIO3_13: input: 0 [ ]

GPIO3_14: input: 0 [ ]

GPIO3_15: input: 0 [ ]

GPIO3_16: input: 0 [ ]

GPIO3_17: input: 0 [ ]

GPIO3_18: input: 0 [ ]

GPIO3_19: input: 0 [ ]

GPIO3_20: input: 0 [ ]

GPIO3_21: input: 0 [ ]

GPIO3_22: input: 0 [ ]

GPIO3_23: input: 0 [ ]

GPIO3_24: input: 0 [ ]

GPIO3_25: input: 0 [ ]

GPIO3_26: input: 0 [ ]

GPIO3_27: input: 0 [ ]

GPIO3_28: input: 0 [ ]

GPIO3_29: input: 0 [ ]

GPIO3_30: input: 0 [ ]

GPIO3_31: input: 0 [ ]

Bank GPIO4_:

GPIO4_0: input: 0 [ ]

GPIO4_1: input: 0 [ ]

GPIO4_2: input: 0 [ ]

GPIO4_3: input: 0 [ ]

GPIO4_4: input: 0 [ ]

GPIO4_5: input: 0 [ ]

GPIO4_6: input: 0 [ ]

GPIO4_7: input: 0 [ ]

GPIO4_8: input: 0 [ ]

GPIO4_9: input: 0 [ ]

GPIO4_10: input: 0 [ ]

GPIO4_11: input: 0 [ ]

GPIO4_12: input: 0 [ ]

GPIO4_13: input: 0 [ ]

GPIO4_14: input: 0 [ ]

GPIO4_15: input: 0 [ ]

GPIO4_16: input: 0 [ ]

GPIO4_17: input: 1 [ ]

GPIO4_18: input: 0 [ ]

GPIO4_19: input: 0 [ ]

GPIO4_20: input: 0 [ ]

GPIO4_21: input: 0 [ ]

GPIO4_22: input: 0 [ ]

GPIO4_23: input: 0 [ ]

GPIO4_24: input: 1 [ ]

GPIO4_25: input: 0 [ ]

GPIO4_26: input: 0 [ ]

GPIO4_27: input: 0 [ ]

GPIO4_28: input: 0 [ ]

GPIO4_29: input: 0 [ ]

GPIO4_30: input: 0 [ ]

GPIO4_31: input: 0 [ ]

Bank GPIO1_:

GPIO1_0: input: 1 [ ]

GPIO1_1: input: 1 [ ]

GPIO1_2: input: 0 [ ]

GPIO1_3: input: 0 [ ]

GPIO1_4: input: 0 [ ]

GPIO1_5: input: 0 [ ]

GPIO1_6: input: 0 [ ]

GPIO1_7: input: 1 [ ]

GPIO1_8: input: 0 [ ]

GPIO1_9: input: 0 [ ]

GPIO1_10: input: 0 [ ]

GPIO1_11: input: 0 [ ]

GPIO1_12: input: 0 [ ]

GPIO1_13: input: 0 [ ]

GPIO1_14: input: 0 [ ]

GPIO1_15: input: 0 [ ]

GPIO1_16: input: 0 [ ]

GPIO1_17: input: 0 [ ]

GPIO1_18: input: 0 [ ]

GPIO1_19: input: 0 [ ]

GPIO1_20: input: 0 [ ]

GPIO1_21: input: 0 [ ]

GPIO1_22: input: 0 [ ]

GPIO1_23: input: 0 [ ]

GPIO1_24: input: 0 [ ]

GPIO1_25: input: 0 [ ]

GPIO1_26: input: 0 [ ]

GPIO1_27: input: 0 [ ]

GPIO1_28: input: 0 [ ]

GPIO1_29: input: 0 [ ]

GPIO1_30: input: 0 [ ]

GPIO1_31: input: 0 [ ]

GPIO bank和pin name可以参照status的结果,然后运行gpio命令:

u-boot=> gpio status GPIO3_

Bank GPIO3_:

GPIO3_0: input: 1 [x] mmc@42860000.cd-gpios

u-boot=> gpio status GPIO3_0

Bank GPIO3_:

GPIO3_0: input: 1 [x] mmc@42860000.cd-gpios

u-boot=> gpio status GPIO3_1

Bank GPIO3_:

GPIO3_1: input: 0 [ ]

u-boot=> gpio set GPIO2_11

gpio: pin GPIO2_11 (gpio 11) value is 1

u-boot=> gpio clear GPIO2_11

gpio: pin GPIO2_11 (gpio 11) value is 0

参考:

gpio command — Das U-Boot unknown version documentation

### LoongArch GNU 工具链配置详情及 GCC 版本信息 #### 配置细节 LoongArch GNU 工具链的目标架构为 `loongarch64-linux-gnu`,其对应的 GCC 编译器版本为 8.3.0。此工具链支持龙芯自主指令集体系结构(LoongArch),并针对该架构进行了优化[^1]。 在构建过程中,GCC 的配置选项通常会指定目标平台以及所需的特性支持。对于 LoongArch 架构而言,常见的配置命令可能如下所示: ```bash ./configure --target=loongarch64-linux-gnu \ --prefix=/opt/loongson/toolchain \ --enable-languages=c,c++ \ --disable-multilib \ --with-system-zlib \ --with-gmp=/usr/local/gmp \ --with-mpfr=/usr/local/mpfr \ --with-mpc=/usr/local/mpc \ --with-isl=/usr/local/isl ``` 上述配置说明了以下几点: - 使用 `--target=loongarch64-linux-gnu` 来定义目标平台。 - 设置安装路径为 `/opt/loongson/toolchain`。 - 启用了 C 和 C++ 支持。 - 关闭多库模式以减少复杂度。 - 指定了依赖项的位置,例如 GMP、MPFR、MPC 和 ISL 库。 #### GCC 版本信息 所使用的 GCC 版本为 8.3.0,这是由官方预先编译好的二进制文件提供[^4]。通过解压预编译的工具链包即可获得完整的开发环境。例如,在 Linux 下可以通过以下命令完成解压操作: ```bash tar -xvf loongson-gnu-toolchain-8.3-src-loongarch64-linux-gnu-rc1.2.tar ``` 这一步骤将提取出所有必要的组件,包括编译器、汇编器和链接器等工具。 此外,动态链接库的信息也表明系统中存在兼容的 libc 实现。例如,标准 C 库的共享对象文件位于 `/lib/x86_64-linux-gnu/libc.so.6` 中[^3]。尽管此处提到的是 x86_64 平台上的实现,但在 LoongArch 上也会有类似的对应版本。 --- ### 总结 综上所述,LoongArch GNU 工具链基于 GCC 8.3.0 开发,并专门适配于 `loongarch64-linux-gnu` 目标平台。它不仅提供了高效的编译能力,还包含了经过验证的标准库支持。用户可以按照既定流程下载并部署这一工具链至本地环境中,从而开展面向 LoongArch 架构的应用程序开发工作。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值