TX2/Xavier Linux GPIO 计算

这篇博客详细介绍了如何在Jetson TX2和Xavier上进行Linux GPIO的计算和配置。通过Linux命令行操作GPIO,如导出、设置方向和读写值,并解析了GPIO编号的计算方法,引用了相关的Linux内核头文件。还提供了开机脚本设置的提示,以及针对不同设备GPIO计算的差异。

Linux GPIO子系统

Linux命令行常用echo, cat等操作GPIO:

# 列出Linux GPIO空间目录
$ ls /sys/class/gpio
export  gpiochip232  gpiochip240  gpiochip256  gpiochip320  unexport

# 导出GPIO到用户空间
# GPIO4_CAM_STROBE -> GPIO3_PV.05 -> V=>2, 2*8+256+5=277
$ echo 277 > /sys/class/gpio/export
# 取消导出把export换成unexport

$ ls /sys/class/gpio
export  gpio277  gpiochip232  gpiochip240  gpiochip256  gpiochip320  unexport

# 设置GPIO方向为输出
$ echo out > /sys/class/gpio/gpio277/direction

# 输出高电平
$ echo 1 > /sys/class/gpio/gpio277/value

# 查看电平
$ cat /sys/class/gpio/gpio277/value
1

当然这些命令断电失效, 可以写成脚本设置开机运行, 有兴趣搜索Ubuntu16,或者Ubuntu18设置开机脚本.

TX2 Linux GPIO计算

于上面277的由来 GPIO4_CAM_STROBE -> GPIO3_PV.05 -> V=>2, 2*8+256+5=277
原理图中用的是GPIO4_CAM_STROBE这个引脚:
在这里插入图片描述
Jetson TX2 Series Pinmux 这个xls表格:
在这里插入图片描述
表格中 GPIO4_CAM_STROBE -> GPIO3_PV.05.
https://github.com/torvalds/linux/blob/master/include/dt-bindings/gpio/tegra186-gpio.h github , linux的代码对TX2端口进行了编号(TX2->tegra186-gpio.h, Xavier->tegra194-gpio.h):

/* GPIOs implemented by main GPIO controller */
#define TEGRA186_MAIN_GPIO_PORT_A 0
#define TEGRA186_MAIN_GPIO_PORT_B 1
#define TEGRA186_MAIN_GPIO_PORT_C 2
#define TEGRA186_MAIN_GPIO_PORT_D 3
#define TEGRA186_MAIN_GPIO_PORT_E 4
#define TEGRA186_MAIN_GPIO_PORT_F 5
#define TEGRA186_MAIN_GPIO_PORT_G 6
#define TEGRA186_MAIN_GPIO_PORT_H 7
#define TEGRA186_MAIN_GPIO_PORT_I 8
#define TEGRA186_MAIN_GPIO_PORT_J 9
#define TEGRA186_MAIN_GPIO_PORT_K 10
#define TEGRA186_MAIN_GPIO_PORT_L 11
#define TEGRA186_MAIN_GPIO_PORT_M 12
#define TEGRA186_MAIN_GPIO_PORT_N 13
#define TEGRA186_MAIN_GPIO_PORT_O 14
#define TEGRA186_MAIN_GPIO_PORT_P 15
#define TEGRA186_MAIN_GPIO_PORT_Q 16
#define TEGRA186_MAIN_GPIO_PORT_R 17
#define TEGRA186_MAIN_GPIO_PORT_T 18
#define TEGRA186_MAIN_GPIO_PORT_X 19
#define TEGRA186_MAIN_GPIO_PORT_Y 20
#define TEGRA186_MAIN_GPIO_PORT_BB 21
#define TEGRA186_MAIN_GPIO_PORT_CC 22

#define TEGRA186_MAIN_GPIO(port, offset) \
    ((TEGRA186_MAIN_GPIO_PORT_##port * 8) + offset)

/* GPIOs implemented by AON GPIO controller */
#define TEGRA186_AON_GPIO_PORT_S 0
#define TEGRA186_AON_GPIO_PORT_U 1
#define TEGRA186_AON_GPIO_PORT_V 2
#define TEGRA186_AON_GPIO_PORT_W 3
#define TEGRA186_AON_GPIO_PORT_Z 4
#define TEGRA186_AON_GPIO_PORT_AA 5
#define TEGRA186_AON_GPIO_PORT_EE 6
#define TEGRA186_AON_GPIO_PORT_FF 7

#define TEGRA186_AON_GPIO(port, offset) \
    ((TEGRA186_AON_GPIO_PORT_##port * 8) + offset)
  • TEGRA186_MAIN_GPIO, 也就是tegra-gpio, at base index 320, 来源 TX2 GPIO Changes
  • TEGRA186_AON_GPIO, 也就是tegra-gpio-aon, at base index 256
  • offset = base + pin
  • TEGRA186_AON_GPIO_PORT_V对应2, 属于tegra-gpio-aon组, 基值是256, 那么 GPIO3_PV.05 对应的就是TEGRA186_MAIN_GPIO(V, (256+5)) => ((TEGRA186_MAIN_GPIO_PORT_V* 8) + offset) = 2*8+256+5 = 277.

Xavier Linux GPIO计算

tegra194-gpio.h, 这里把Xavier的 linux/include/dt-bindings/gpio/tegra194-gpio.h github也贴过来方便查阅:

#ifndef _DT_BINDINGS_GPIO_TEGRA194_GPIO_H
#define _DT_BINDINGS_GPIO_TEGRA194_GPIO_H

#include <dt-bindings/gpio/gpio.h>

/* GPIOs implemented by main GPIO controller */
#define TEGRA194_MAIN_GPIO_PORT_A 0
#define TEGRA194_MAIN_GPIO_PORT_B 1
#define TEGRA194_MAIN_GPIO_PORT_C 2
#define TEGRA194_MAIN_GPIO_PORT_D 3
#define TEGRA194_MAIN_GPIO_PORT_E 4
#define TEGRA194_MAIN_GPIO_PORT_F 5
#define TEGRA194_MAIN_GPIO_PORT_G 6
#define TEGRA194_MAIN_GPIO_PORT_H 7
#define TEGRA194_MAIN_GPIO_PORT_I 8
#define TEGRA194_MAIN_GPIO_PORT_J 9
#define TEGRA194_MAIN_GPIO_PORT_K 10
#define TEGRA194_MAIN_GPIO_PORT_L 11
#define TEGRA194_MAIN_GPIO_PORT_M 12
#define TEGRA194_MAIN_GPIO_PORT_N 13
#define TEGRA194_MAIN_GPIO_PORT_O 14
#define TEGRA194_MAIN_GPIO_PORT_P 15
#define TEGRA194_MAIN_GPIO_PORT_Q 16
#define TEGRA194_MAIN_GPIO_PORT_R 17
#define TEGRA194_MAIN_GPIO_PORT_S 18
#define TEGRA194_MAIN_GPIO_PORT_T 19
#define TEGRA194_MAIN_GPIO_PORT_U 20
#define TEGRA194_MAIN_GPIO_PORT_V 21
#define TEGRA194_MAIN_GPIO_PORT_W 22
#define TEGRA194_MAIN_GPIO_PORT_X 23
#define TEGRA194_MAIN_GPIO_PORT_Y 24
#define TEGRA194_MAIN_GPIO_PORT_Z 25
#define TEGRA194_MAIN_GPIO_PORT_FF 26
#define TEGRA194_MAIN_GPIO_PORT_GG 27

#define TEGRA194_MAIN_GPIO(port, offset) \
    ((TEGRA194_MAIN_GPIO_PORT_##port * 8) + offset)

/* GPIOs implemented by AON GPIO controller */
#define TEGRA194_AON_GPIO_PORT_AA 0
#define TEGRA194_AON_GPIO_PORT_BB 1
#define TEGRA194_AON_GPIO_PORT_CC 2
#define TEGRA194_AON_GPIO_PORT_DD 3
#define TEGRA194_AON_GPIO_PORT_EE 4

#define TEGRA194_AON_GPIO(port, offset) \
    ((TEGRA194_AON_GPIO_PORT_##port * 8) + offset)

#endif

基地值也变了:

  • tegra-gpio, at base index 288
  • tegra-gpio-aon, at base index 248
    如 原理图中的信号 SPI1_SCK:
  • Jetson AGX Xavier Pinmux表格, 对应 GPIO3_PZ.03
  • 上面头文件tegra194-gpio.h定义了#define TEGRA194_MAIN_GPIO_PORT_Z 25
  • TEGRA194_MAIN_GPIO, 也就是tegra-gpio, 基值为288
  • Linux GPIO计算结果: 25*8 + 288 + 3 = 491
    待续…
    TX2/Xavier Linux GPIO 计算
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值