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

Ad

I am creating a new application using the Beaglebone Black. I need to configure GPIOs for different functions. I will have some GPIOs, some PWMs, and probably some other functions.

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;
  • I can do the same in Javascript;
  • I can make and compile a device tree overlay source file (.dts), and use it;
  • I could do a bash script and echo 'out' and 'in' and so forth to the different device definitions in the filesystem;
  • I imagine there's a C API, though I wouldn't use it for this application.

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.

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?

Ad

Answer

Ad

The pin multiplexers are configured through registers in the AM335x processor's control module subsystem. 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.

On the BeagleBone, there is a driver called bone-pinmux-helper, which allows for runtime changing between different pinmux configurations from userspace. 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. 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.

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.

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. 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.

Ad
source: stackoverflow.com
Ad