Jetson TX2 GPIO权限设置,Jetson.GPIO提供的99-gpio.rules文件没有效果

这篇具有很好参考价值的文章主要介绍了Jetson TX2 GPIO权限设置,Jetson.GPIO提供的99-gpio.rules文件没有效果。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

快速通道

在此之前得确认1. 用户组gpio是否存在getent group | grep gpio (如果没创建就groupadd -r gpio创建)2. 当前用户是否已经加入gpio用户组groups | grep gpio(如果没加入就usermod -aG gpio 当前用户名加入)
不过一般Jetson

把以下内容写到/etc/udev/rules.d/99-gpio.rules中去

SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", GROUP="gpio", MODE="0660"
#SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", \
#    PROGRAM="/bin/sh -c 'chown root:gpio /dev/%k; chmod 660 /dev/%k'"

SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/{,un}export; chmod 220 /sys%p/{,un}export'"
SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="change", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/%E{EXPORT}/{period,duty_cycle,enable}; chmod 660 /sys%p/%E{EXPORT}/{period,duty_cycle,enable}'"

SUBSYSTEM=="spidev", KERNEL=="spidev*", ACTION=="add", \
    GROUP="gpio", MODE="0660"

然后运行

sudo udevadm control --reload-rules && sudo udevadm trigger

背景

  打算使用JetsonTX2的IO口,跟着Jetson.GPIO 2.1.1 PyPI的教程[1]来复制规则,发现不行,重启了也不行,最后鉴定为他的规则有问题,搞了好久,垃圾东西。

历程

  安装了Jetson.GPIO 2.1.1之后,按照教程将他的规则文件复制到/etc/udev/rules.d/

pip install Jetson.GPIO
sudo updatedb
locate 99-gpio.rules
# 然后将返回的路径复制到/etc/udev/rules.d/去
sudo cp 返回的路径venv/lib/pythonNN/site-packages/Jetson/GPIO/99-gpio.rules /etc/udev/rules.d/

  重启,没用

使用udevadm test进行调试

  Jetson.GPIO提供的规则文件如下

SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", \
    PROGRAM="/bin/sh -c 'chown root:gpio /dev/%k; chmod 660 /dev/%k'"

SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/{,un}export; chmod 220 /sys%p/{,un}export'"
SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="change", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/%E{EXPORT}/{period,duty_cycle,enable}; chmod 660 /sys%p/%E{EXPORT}/{period,duty_cycle,enable}'"

SUBSYSTEM=="spidev", KERNEL=="spidev*", ACTION=="add", \
    GROUP="gpio", MODE="0660"

  在网上查了一下发现可以使用udevadm test进行调试看看规则是否起作用
  sudo udevadm info --name=/dev/gpiochip0 --query=pathsudo udevadm info --name=/dev/gpiochip0 --query=all可以查询设备路径信息

nvidia@nvidia-desktop /e/u/rules.d> sudo udevadm info --name=/dev/gpiochip0 --query=path
/devices/2200000.gpio/gpiochip0

  sudo udevadm test path可以让规则生效并且输出过程

nvidia@nvidia-desktop:~$ sudo udevadm test $(udevadm info -q path -n /dev/gpiochip0) 2>&1 
calling: test
version 237
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because 
some values may be different, or not available at a simulation run.     

Load module index
Network interface NamePolicy= disabled on kernel command line, ignoring.
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
Reading rules file: /lib/udev/rules.d/01-md-raid-creating.rules
Reading rules file: /lib/udev/rules.d/39-usbmuxd.rules
Reading rules file: /lib/udev/rules.d/40-usb-media-players.rules        
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/40-vm-hotadd.rules
Reading rules file: /lib/udev/rules.d/50-apport.rules
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/55-ippusbxd.rules
Reading rules file: /etc/udev/rules.d/55-primesense-usb.rules
Reading rules file: /lib/udev/rules.d/56-lvm.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-bridge-network-interface.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-crda.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-gpsd.rules
Reading rules file: /lib/udev/rules.d/60-i2c-tools.rules
Reading rules file: /lib/udev/rules.d/60-input-id.rules
Reading rules file: /lib/udev/rules.d/60-inputattach.rules
Reading rules file: /lib/udev/rules.d/60-jetson-gpio-common.rules
Reading rules file: /lib/udev/rules.d/60-libfreenect0.5.rules
Reading rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
Reading rules file: /lib/udev/rules.d/60-libopenni-sensor-pointclouds0.rules
Reading rules file: /lib/udev/rules.d/60-libopenni2-0.rules
Reading rules file: /lib/udev/rules.d/60-libsane1.rules
Reading rules file: /lib/udev/rules.d/60-openobex.rules
Reading rules file: /lib/udev/rules.d/60-pcmcia.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-qemu-system-common.rules
Reading rules file: /lib/udev/rules.d/60-sensor.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/61-gdm.rules
Reading rules file: /lib/udev/rules.d/61-gnome-settings-daemon-rfkill.rules
Reading rules file: /lib/udev/rules.d/61-persistent-storage-android.rules
Reading rules file: /lib/udev/rules.d/63-md-raid-arrays.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/64-md-raid-assembly.rules
Reading rules file: /lib/udev/rules.d/64-xorg-xkb.rules
Reading rules file: /lib/udev/rules.d/65-libwacom.rules
Reading rules file: /lib/udev/rules.d/66-snapd-autoimport.rules
Reading rules file: /lib/udev/rules.d/69-cd-sensors.rules
Reading rules file: /lib/udev/rules.d/69-libmtp.rules
Reading rules file: /lib/udev/rules.d/69-lvm-metad.rules
Reading rules file: /lib/udev/rules.d/69-md-clustered-confirm-device.rules
Reading rules file: /lib/udev/rules.d/69-wacom.rules
Reading rules file: /lib/udev/rules.d/70-joystick.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-printers.rules
Reading rules file: /lib/udev/rules.d/70-spice-vdagentd.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-u2f.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-power-switch-proliant.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/77-mm-cinterion-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-dell-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-ericsson-mbm.rules
Reading rules file: /lib/udev/rules.d/77-mm-fibocom-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-haier-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-huawei-net-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-longcheer-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-mtk-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-nokia-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-qdl-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-sierra.rules
Reading rules file: /lib/udev/rules.d/77-mm-simtech-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-telit-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-ublox-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-usb-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-usb-serial-adapters-greylist.rules
Reading rules file: /lib/udev/rules.d/77-mm-x22x-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-zte-port-types.rules
Reading rules file: /lib/udev/rules.d/78-graphics-card.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-ifupdown.rules
Reading rules file: /lib/udev/rules.d/80-iio-sensor-proxy.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-mm-candidate.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/80-uvcdynctrl.rules
Reading rules file: /lib/udev/rules.d/84-nm-drivers.rules
Reading rules file: /lib/udev/rules.d/85-brltty.rules
Reading rules file: /lib/udev/rules.d/85-nm-unmanaged.rules
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /etc/udev/rules.d/90-alsa-asound-tegra.rules
Reading rules file: /lib/udev/rules.d/90-alsa-restore.rules
Reading rules file: /lib/udev/rules.d/90-bolt.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/90-fwupd-devices.rules
Reading rules file: /lib/udev/rules.d/90-libgpod.rules
Reading rules file: /lib/udev/rules.d/90-libinput-model-quirks.rules
Reading rules file: /lib/udev/rules.d/90-pulseaudio.rules
Reading rules file: /etc/udev/rules.d/91-xorg-conf-tegra.rules
Reading rules file: /etc/udev/rules.d/92-hdmi-audio-tegra.rules
Reading rules file: /lib/udev/rules.d/95-cd-devices.rules
Reading rules file: /lib/udev/rules.d/95-dm-notify.rules
Reading rules file: /lib/udev/rules.d/95-ucm-soundcard-name.rules
Reading rules file: /lib/udev/rules.d/95-upower-csr.rules
Reading rules file: /lib/udev/rules.d/95-upower-hid.rules
Reading rules file: /lib/udev/rules.d/95-upower-wup.rules
Reading rules file: /lib/udev/rules.d/97-hid2hci.rules
Reading rules file: /etc/udev/rules.d/99-gpio.rules
Reading rules file: /etc/udev/rules.d/99-nv-l4t-usb-device-mode.rules
Reading rules file: /etc/udev/rules.d/99-nv-l4t-usb-host-config.rules
Reading rules file: /etc/udev/rules.d/99-nv-ufs-mount.rules
Reading rules file: /etc/udev/rules.d/99-nv-wifibt.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
Reading rules file: /etc/udev/rules.d/99-tegra-devices.rules
Reading rules file: /etc/udev/rules.d/99-tegra-mmc-ra.rules
Reading rules file: /etc/udev/rules.d/99-video-device.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 41041 bytes strings
25987 strings (224102 bytes), 22534 de-duplicated (186515 bytes), 3454 trie nodes used
PROGRAM '/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'' /lib/udev/rules.d/60-jetson-gpio-common.rules:23
starting '/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport''
Process '/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'' succeeded.
PROGRAM '/bin/sh -c 'chown root:gpio /dev/gpiochip0; chmod 660 /dev/gpiochip0'' /etc/udev/rules.d/99-gpio.rules:23
starting '/bin/sh -c 'chown root:gpio /dev/gpiochip0; chmod 660 /dev/gpiochip0''
Process '/bin/sh -c 'chown root:gpio /dev/gpiochip0; chmod 660 /dev/gpiochip0'' succeeded.
handling device node '/dev/gpiochip0', devnum=c254:0, mode=0600, uid=0, gid=0
set permissions /dev/gpiochip0, 020600, uid=0, gid=0
preserve already existing symlink '/dev/char/254:0' to '../gpiochip0'
ACTION=add
DEVNAME=/dev/gpiochip0
DEVPATH=/devices/2200000.gpio/gpiochip0
MAJOR=254
MINOR=0
OF_COMPATIBLE_0=nvidia,tegra186-gpio
OF_COMPATIBLE_N=1
OF_FULLNAME=/gpio@2200000
OF_NAME=gpio
SUBSYSTEM=gpio
USEC_INITIALIZED=2764256
net.ifnames=0
Unload module index
Unloaded link configuration context.

  可以看到Process '/bin/sh -c 'chown root:gpio /dev/gpiochip0; chmod 660 /dev/gpiochip0'' succeeded.但是后面三行又将其设置回来了set permissions /dev/gpiochip0, 020600, uid=0, gid=0,很迷,问了很久ChatGPT也没问出来,最后看到ChatGPT说SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", GROUP="gpio", MODE="0660"权限这样设置,而且树莓派的GPIO也是这样设置[2],最后参考这个形式修改规则文件就行了(Jetson.GPIO什么shaB写法,不过为什么好像没查到别人有遇到这个问题)。
  最后将规则文件改成一下格式就行了。

SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", GROUP="gpio", MODE="0660"
#SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", \
#    PROGRAM="/bin/sh -c 'chown root:gpio /dev/%k; chmod 660 /dev/%k'"

SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="add", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/{,un}export; chmod 220 /sys%p/{,un}export'"
SUBSYSTEM=="pwm", KERNEL=="pwmchip*", ACTION=="change", \
    PROGRAM="/bin/bash -c 'chown root:gpio /sys%p/%E{EXPORT}/{period,duty_cycle,enable}; chmod 660 /sys%p/%E{EXPORT}/{period,duty_cycle,enable}'"

SUBSYSTEM=="spidev", KERNEL=="spidev*", ACTION=="add", \
    GROUP="gpio", MODE="0660"

总结

  只能认为/dev/里面的设备不能用PROGRAM="/bin/sh -c 'chown root:gpio /dev/%k; chmod 660 /dev/%k'"这种方式来修改权限,如果没有设置 GROUP="gpio", MODE="0660"默认可能就会采用默认设置root 600,即使用PROGRAM="/bin/sh -c 'chown root:gpio /dev/%k; chmod 660 /dev/%k'"修改了权限,最后也被默认权限给覆盖了,而 GROUP="gpio", MODE="0660"能够覆盖默认的root 600
  真是的,明明系统就已经提供了 GROUP="", MODE=""这类的方式来修改权限,为什么Jetson.GPIO还要用PROGRAM命令来修改。

参考

[1]  Jetson.GPIO 2.1.1 - PyPI (拉跨)
[2]  树莓派GPIO权限设置文章来源地址https://www.toymoban.com/news/detail-716945.html

到了这里,关于Jetson TX2 GPIO权限设置,Jetson.GPIO提供的99-gpio.rules文件没有效果的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【AI】YOLOv7部署在NVIDIA Jetson TX2上

    Micro controller Unit, 微处理器 在单片机上也能跑的AI算法,好神奇啊,比如MCUNet Central Processing Unit,中央处理器 一般的框架都有CPU版本,当然速度会慢一些,在x86电脑上勉强能用,在嵌入式ARM板上几乎无法使用 Graphics Processing Unit,图形处理器 例如英伟达的各种显卡等,具有强

    2024年02月04日
    浏览(83)
  • jetson nano GPIO控制说明

    GPIO(General Purpose Input Output)通用输入输出。有时候我们会简称为“IO口”。GPIO口在智能硬件开发中是一个比较重要的概念,用户可以通过GPIO口和硬件进行数据交互(如UART),控制硬件工作(如LED、蜂鸣器等),读取硬件的工作状态信号(如中断信号)等。Jetson TX1、TX2、AGX Xavier和

    2024年02月16日
    浏览(47)
  • STM32 GPIO设置(GPIO初始化)学习笔记

    GPIO 都知道是 通用输入输出接口 的意思就不详细解释 那么我们就直接进入怎么设置GPIO接口: 这里我的编译软件是keil5,相信大家都应该知道stm32有各种的工作模式上拉、下拉、推挽、开漏等等。如果想要了解具体的工作模式原理这里我推荐大家看:推挽 开漏 高阻 这都是谁

    2024年03月28日
    浏览(59)
  • 【嵌入式Linux内核驱动】04_Jetson nano GPIO应用 | 驱动开发 | 官方gpiolib、设备树与chip_driver

    0.暴露给应用层 应用 解决调试目录为空的问题 调试信息 1.最简读写文件(在/SYS下) 设备树 验证测试 编译文件 驱动 of_get_named_gpio_flags //获取设备树节点的属性 gpio_is_valid //判断是否合法 devm_gpio_request //申请使用gpio,并调用设置pinctrl device_create_file //根据设备树节点属性,创建

    2024年02月07日
    浏览(61)
  • PX4与TX2通信

    PX4与TX2通信以及相关数据的获取 目录  1. PX4硬件接口 2. TELEM1、2接口线序 3.  PX4与TX2通信  PX4 IO口定义:   PX4硬件: 4. 通信测试 5. RTPS+ROS Jetson TX2终端:  pixhawk: 6. 提高IMU数据发布频率  方法一:通过mavros包话题订阅频率  方法二:更改PX4启动文件 7. GPS数据获取     PX4是

    2024年02月14日
    浏览(35)
  • tx2开发板升级JetPack至最新

    最近一个项目用到了tx2, 上面的jetpack太老了需要更新,很久没和开发板打交道了,记录一下。中间没怎么截图,所以可能文字居多。 Ubuntu 18.04的机器,避免有坑,不要使用虚拟机,一定要是物理机,我就是刚开始用虚拟机,每次到99%,就卡住 TX2开发板 网线,tx2 USB连接线 S

    2024年01月20日
    浏览(42)
  • RK356x 在uboot下设置GPIO引脚默认电平

    在uboot启动的时候需要把某个CPU引脚拉高或者拉低,促使某个功能能正常运行。 思路一 首先打开RK356X的SDK软件包,查看一下uboot源码,这次我先在u-boot/common/board_f.c和board_r.c文件上添加GPIO口设置,虽然添加了gpio_direction_output()或者gpio_set_value()类似的GPIO设置的函数,但是用万用

    2024年02月10日
    浏览(45)
  • 【EHub_tx1_tx2_A200】Ubuntu18.04 + ROS_ Melodic + 锐驰LakiBeam 1L单线激光 雷达评测

            大家好,我是虎哥,最近这段时间,又手欠入手了锐驰LakiBeam 1L激光雷达,实在是性价比太优秀,话说,最近激光雷达圈确实有点卷。锐驰官网的资料已经很丰富,我这里总结一下自己的简单测试经验,分享给大家。          LakiBeam1L是锐驰智光面向中低速场

    2024年02月03日
    浏览(43)
  • uboot - pinctrl - FPGA回片前测试阶段 - 设置GPIO引脚复用失败

    pinctrl设置引脚复用失败,没有调用到controller中的set_groups_function函数。 pinctrl如何注册dm节点 如何进行设备树中各个设备节点下的复用配置 为什么没调用到控制器实现的set_groups_function函数 调用过程: 上面的调用过程是通过加log找出来的,log如下: 看着就是在pinctrl_select_st

    2024年03月26日
    浏览(50)
  • GPIO引脚的模式设置:开漏、推挽、拉高、拉低、中断输入、串行通信、模拟输入输出、容错输入、PWM输出。过零检测介绍。

    开漏输出(软件): 将GPIO口设置为开漏输出模式,可以实现开漏输出控制方式,输出电平只能被拉低,而不能被拉高。在使用开漏输出时,需要外部接上一个上拉电阻,将输出电平拉高到高电平。开漏输出常用于驱动I2C总线、LED灯等场景中。 硬件设置为开漏输出的情况(硬

    2024年02月08日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包