GPIO dev/mem (mmap) on Beaglebone

Hi All!

I’m trying to use GPIO via dev/mem on my beaglebone and the first step is to write to the pin mux.

Code something like this: (C code)

const unsigned long GPIO_CONTROL_MODULE_REGISTER_BASE_ADDRESS = 0x44E10000;
unsigned long * control_register;
gpio_fd = open("/dev/mem", O_RDWR | O_SYNC);
control_register = (unsigned long *) mmap(NULL, 0x1FFF, PROT_READ | PROT_WRITE, MAP_SHARED, gpio_fd, 0x44E10000);

control_register[gpio_control_table[_pin].pad_ctrl_address / 4] = 0x2F;

Reading is no problem all values set by

echo 7 > /sys/kernel/debug/omap_mux/gpmc_ad6

can be reed back with cat command or my program

name: gpmc_ad6.gpio1_6 (0x44e10818/0x818 = 0x0007), b NA, t NA
signals: gpmc_ad6 | mmc1_dat6 | NA | NA | NA | NA | NA | gpio1_6

My program: (gpio_control_table[_pin].pad_ctrl_address / 4 is only last 16-bit)

data = m_controlModule[gpio_control_table[_pin].pad_ctrl_address / 4]; // Read value

[GPIO] : Pin MUX for P8_3 (gpmc_ad6) @ [0x44E10818] is set to 0x07

I have tested this with different values… And no problem to read them.

But it is not possible to write a new value :frowning:

I set the value and read it back.

When running ubuntu the value does not change after writing new value and read-back.

[GPIO] : Pin MUX for P8_3 (gpmc_ad6) @ [0x44E10818] is set to 0x07
(Set new value)
[GPIO] : Pin MUX for P8_3 (gpmc_ad6) @ [0x44E10818] is set to 0x07

In Angström the value changes but not it has not changed when you cat /sys/kernel/debug/omap_mux/gpmc_ad6

[GPIO] : Pin MUX for P8_3 (gpmc_ad6) @ [0x44E10818] is set to 0x07
(Set new value)
[GPIO] : Pin MUX for P8_3 (gpmc_ad6) @ [0x44E10818] is set to 0x2F

Ofc you can not read the pin because it is still in output mode…

Any idéas?


You have to be in privileged mode to write to any control module registers including the pin mux registers. See section 9.1 [1] of the reference manual. Also check out Alexander Hiam’s article [2].

Luckily you can still write to the GPIO modules in user mode. So you can use the /sys/kernel/debug driver to set up your pin mux and then user mode to twiddle the GPIOs. Check out my hobby project [3] for an example. It uses the PRU-ICSS to drive the pins but it’s the same concept.




Hello Lyren!

Thanx for your answer I will use the /sys/kernel/debug/omap_mux/ instead.


check this out:

I have explained how to use /dev/mmap in beaglebone black

I cannot get this mmap to work. I think you left out a few steps. For example what is the overlay you used for the DT?

Now working. Just operator error. Plugged into the wrong header.

I will share what I have:

overlay file Modified from BB-GPIOHELP-00A0.dts for just P9.12.