NVIDIA Jetson Xavier NX 计算GPIO编号

前言

公司产品使用了自主设计的载板,需要使用指定的GPIO引脚,在Linux系统中采用文件io的方式控制GPIO,所以必须计算出GPIO 编号。
当然不同公司的开发板GPIO计算公式并不一致,以下计算公式仅适用于NVIDIA公司的开发板。

准备工作

想要计算出GPIO编号,需先准备好两个文件:

  1. Jetson_Xavier_NX_Pinmux_Configuration_Template_v1.06.xlsm;[1]
  2. tegra-gpio.h;[2]
    [1]:NX pinmux配置模板表,下载链接:
    https://developer.nvidia.com/zh-cn/embedded/downloads#?search=Xavier%20NX%20Pinmux
    [2]:该头文件在NX内核源码目录中:/kernel-4.9/include/dt-bindings/gpio ,请自行下载。

计算步骤

GPIO映射公式计算可归纳为:

  1. 通过信号名在Jetson Xavier NX 引脚多路复用表格中找出对用的GPIO宏名编号(Jetson_Xavier_NX_Pinmux_Configuration_Template_v1.06.xlsm);
  2. 然后在内核头文件tegra-gpio.h中找出GPIO编号对应的端口宏定义;
  3. 在Jetson Xavier NX终端键入 dmesg | grep gpiochip_setup_dev 命令,搜索内核信息查找出每组GPIO的分配范围,目的是找出不同的GPIO组的偏移值;
  4. 根据((TEGRA_GPIO_PORT_##port * 8) + offset)公式计算出GPIO编号,offset是以初值为基础偏移。比如初值是288,管脚为GPIO3_PS.04,则offset = 288+4 。

计算示例

以计算信号名GPIO09为例:

  1. 通过信号名GPIO09在pinmux表格中找到对用的GPIO宏名编号为:GPIO3_PS.04
  2. 内核头文件tegra-gpio.h中 #define TEGRA_GPIO_PORT_S 18,故port = 18;
  3. 键入命令,根据如下输出可知基础偏移offset = 288;
    [ 0.895412]gpiochip_setup_dev: registered GPIOs 288 to 511 on device: gpiochip0 (tegra-gpio)
    [ 0.904338] gpiochip_setup_dev: registered GPIOs 248 to 287 on device: gpiochip1 (tegra-gpio-aon)
  4. GPIO编号 = 18*8+288+4 = 436 。

注意:

实测pinmux表中绝大部分GPIO编号可以由此公式计算出,且能够正常控制GPIO引脚。但GPIO12,即GPIO3_PCC.04的GPIO编号为268,超出288-511范围,且属于tegra-gpio-aon组,在248-287范围之内。
当然,既然知道GPIO3_PCC.04GPIO编号为268,GPIO3_PCC组其它编号也可推导出来。

【转载请注明出处】。

附件:tegra-gpio.h

// An highlighted block
/*
 * This header provides constants for binding nvidia,tegra*-gpio.
 *
 * The first cell in Tegra's GPIO specifier is the GPIO ID. The macros below
 * provide names for this.
 *
 * The second cell contains standard flag values specified in gpio.h.
 */

#ifndef _DT_BINDINGS_GPIO_TEGRA_GPIO_H
#define _DT_BINDINGS_GPIO_TEGRA_GPIO_H

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

#define TEGRA_GPIO_PORT_A 0
#define TEGRA_GPIO_PORT_B 1
#define TEGRA_GPIO_PORT_C 2
#define TEGRA_GPIO_PORT_D 3
#define TEGRA_GPIO_PORT_E 4
#define TEGRA_GPIO_PORT_F 5
#define TEGRA_GPIO_PORT_G 6
#define TEGRA_GPIO_PORT_H 7
#define TEGRA_GPIO_PORT_I 8
#define TEGRA_GPIO_PORT_J 9
#define TEGRA_GPIO_PORT_K 10
#define TEGRA_GPIO_PORT_L 11
#define TEGRA_GPIO_PORT_M 12
#define TEGRA_GPIO_PORT_N 13
#define TEGRA_GPIO_PORT_O 14
#define TEGRA_GPIO_PORT_P 15
#define TEGRA_GPIO_PORT_Q 16
#define TEGRA_GPIO_PORT_R 17
#define TEGRA_GPIO_PORT_S 18
#define TEGRA_GPIO_PORT_T 19
#define TEGRA_GPIO_PORT_U 20
#define TEGRA_GPIO_PORT_V 21
#define TEGRA_GPIO_PORT_W 22
#define TEGRA_GPIO_PORT_X 23
#define TEGRA_GPIO_PORT_Y 24
#define TEGRA_GPIO_PORT_Z 25
#define TEGRA_GPIO_PORT_AA 26
#define TEGRA_GPIO_PORT_BB 27
#define TEGRA_GPIO_PORT_CC 28
#define TEGRA_GPIO_PORT_DD 29
#define TEGRA_GPIO_PORT_EE 30
#define TEGRA_GPIO_PORT_FF 31

#define TEGRA_GPIO(port, offset) \
	((TEGRA_GPIO_PORT_##port * 8) + offset)

#endif

参考链接

建议有问题直接去nvidia官网查找技术资料,官方文档十分详细,以上参考自下列nvidia技术支持网站。
https://www.jetsonhacks.com/nvidia-jetson-xavier-nx-gpio-header-pinout/
https://docs.nvidia.com/jetson/archives/l4t-archived/l4t-3242/index.html#page/Tegra%2520Linux%2520Driver%2520Package%2520Development%2520Guide%2Fadaptation_and_bringup_xavier_nx.html%23wwpID0E06M0HA

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值