简体   繁体   English

在Beaglebone Black上配置GPIO的不同方式的优缺点是什么?

[英]What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?

I am creating a new application using the Beaglebone Black. 我正在使用Beaglebone Black创建一个新的应用程序。 I need to configure GPIOs for different functions. 我需要为不同的功能配置GPIO。 I will have some GPIOs, some PWMs, and probably some other functions. 我将拥有一些GPIO,一些PWM以及其他一些功能。

I note there are different ways to do that. 我注意到有不同的方法可以做到这一点。 These are in order of preference: 这些是按优先顺序排列的:

  • I can write code using Adafruit's Python library to say 'set this pin up as a PWM' and so forth; 我可以使用Adafruit的Python库编写代码,说“将该引脚设置为PWM”,等等。
  • I can do the same in Javascript ; 我可以用Javascript同样的事情;
  • I can make and compile a device tree overlay source file (.dts), and use it; 我可以制作和编译设备树覆盖源文件(.dts),并使用它;
  • I could do a bash script and echo 'out' and 'in' and so forth to the different device definitions in the filesystem; 我可以做一个bash脚本,并在文件系统中回显“ out”和“ in”,等等。
  • I imagine there's a C API, though I wouldn't use it for this application. 我想象有一个C API,尽管我不会在此应用程序中使用它。

My big need here is replicability. 我这里最需要的是可复制性。 I don't need high performance. 我不需要高性能。 I just need to be able to set up a bunch of Beaglebone Blacks the same way and have them behave reliably. 我只需要能够以相同的方式设置一堆Beaglebone Black,并使它们可靠地运行即可。

Is there some advantage I'm not seeing to doing a device tree overlay and all of that? 我没有看到进行设备树覆盖以及所有这些的优势吗? When would someone choose one method over another? 有人什么时候会选择一种方法而不是另一种方法?

The pin multiplexers are configured through registers in the AM335x processor's control module subsystem. 引脚多路复用器通过AM335x处理器控制模块子系统中的寄存器进行配置。 When running GNU/Linux, the control module registers can only be accessed from kernel space, and therefore has to be done by a kernel driver. 运行GNU / Linux时,只能从内核空间访问控制模块寄存器,因此必须由内核驱动程序完成。

On the BeagleBone, there is a driver called bone-pinmux-helper, which allows for runtime changing between different pinmux configurations from userspace. 在BeagleBone上,有一个称为bone-pinmux-helper的驱动程序,该驱动程序允许在用户空间的不同pinmux配置之间进行运行时更改。 The configurations need to be setup and passed to the driver beforehand with a Device Tree overlay. 需要先配置配置,然后通过设备树覆盖将其传递给驱动程序。 For example, in PyBBIO I have a script which generates overlays for each of the GPIO pins. 例如,在PyBBIO中,我有一个脚本,可为每个GPIO引脚生成覆盖 They setup the different possible modes (in, out, pullup, pulldown, etc.), then pass those all to the bone-pinmux-helper driver as different modes. 他们设置了不同的可能模式(进,出,上拉,下拉等),然后将所有这些模式作为不同的模式传递给骨头-多路复用器辅助驱动程序。 Then when the pinMode() functino is called, PyBBIO uses the capemgr driver to load the generated overlay for the pin, then uses the sysfs entry that it creates for that pin to set it to the requested mode. 然后,当pinMode()函数时,PyBBIO使用capemgr驱动程序为该引脚加载生成的覆盖图,然后使用为其创建的sysfs条目将其设置为请求的模式。

Bonescript uses the same method as PyBBIO, and IIRC Adafruit_BBIO doesn't have overlays for pinmuxing and requires the user to do it separately. Bonescript使用与PyBBIO相同的方法,并且IIRC Adafruit_BBIO没有用于pinmuxing的叠加层,需要用户单独进行。

So, long story short, Device Tree overlays are the only way to do pinmuxing, and userspace libraries like PyBBIO and bonescript are just abstracting that away. 因此,长话短说,设备树覆盖是进行pinmuxing的唯一方法,而PyBBIO和bonescript等用户空间库只是将其抽象化。 If you want to have total control, then write and compile your own overlays. 如果要完全控制,请编写和编译自己的叠加层。 If you don't want to deal with writing DT overlays or to worry about compatibility as things may change over time, use a library like PyBBIO or Bonescript which abstract away that level and trust that they will make sure things keep working. 如果您不想处理DT覆盖图或担心兼容性,因为事情可能会随着时间的变化而变化,请使用PyBBIO或Bonescript之类的库来抽象化该级别,并相信它们将确保一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM