Change the pinmux mode at runtime programmatically

Hi all,

i ask if it is possible to change the pin mode at runtime programmatically (C code) , my goal is use a particular pin both from ARM and PRU when needed.
Surely i could export and unexport overlay for different pin configuration but i’m afraid that it is not stable and i need a different solution.

Thank in advanda for any suggestion.


You can use one the universal device tree overlays by Charles Steinkuehler, shipped with newer OSs (since 2014 June). Write the required state by spawning

echo MODE > /sys/devices/ocp./XX-pinmux./state


where MODE is a pre-defined mode (human readable) and XX is the header pin (I’m not sure regarding the exact syntax).

An alternative is the universal device tree overlay libpruio-0A00.dtbo included in libpruio-0.2. It works similar to the first solution, but uses a hexadecimal value for the mode and the CPU ball number instead of the header pin position. Therefor, it can operate on all CPU balls and is better for automatic program operation. A mode change looks like (CPU ball 12h = P9_14 in mode 0Eh = PWM output, no resistor):

echo x0E > /sys/devices/ocp./pruio-12./state


libpruio-0.2 also includes a tools to create, compile and install further universal overlays with customized pin claiming (to easily avoid interferences with other capes / overlays).

Both methods require your program running with administrator privileges.