Discussion:
GPIO dev/mem (mmap) on Beaglebone
Andreas
2012-12-05 20:23:41 UTC
Permalink
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
mode: OMAP_PIN_OUTPUT | OMAP_MUX_MODE7
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 :(

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?

Best,
Andreas

--
Lyren Brown
2012-12-06 17:45:43 UTC
Permalink
a***@public.gmane.org
2013-12-05 23:48:18 UTC
Permalink
check this out:
http://chiragnagpal.github.io/examples.html
I have explained how to use /dev/mmap in beaglebone black
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
j***@public.gmane.org
2014-06-16 12:36:35 UTC
Permalink
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?
Post by a***@public.gmane.org
http://chiragnagpal.github.io/examples.html
I have explained how to use /dev/mmap in beaglebone black
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
j***@public.gmane.org
2014-06-17 05:50:12 UTC
Permalink
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.

*

* Copyright (C) 2013 Pantelis Antoniou <panto-wVdstyuyKrO8r51toPun2/***@public.gmane.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/dts-v1/;
/plugin/;

/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";

/* identification */
part-number = "BB-GPIOP912";
version = "00A0";

/* state the resources this cape uses */
exclusive-use =
/* the pin header uses */
"P9.12", /* gpio */
/* the hardware IP uses */
"gpio1_28";

***@0 {
target = <&am33xx_pinmux>;
__overlay__ {
gpio_helper_pins: pinmux_gpio_helper_pins {
pinctrl-single,pins = <
0x078 0x07 /* P9.12 GPIO1_28: MODE7 | OUTPUT */
Post by j***@public.gmane.org
;
};
};
};

***@2 {
target = <&ocp>;
__overlay__ {

gpio_helper {
compatible = "gpio-of-helper";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&gpio_helper_pins>;

/* declare your gpios */
test_led {
gpio-name = "test_led";
gpio = <&gpio2 12 0x00>; /* gpio2 is gpio1 */
output;
};

};
};
};
};


===========================================
next the uEnv.txt file:

optargs=quiet drm.debug=7 capemgr.enable_partno=BB-GPIOP912


===========================================

next the c program: added the sleep(1)& printf in between toggles.
this program was written by: Chirag Nagpal


#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "beaglebone_gpio.h"

int main(int argc, char *argv[]) {
volatile void *gpio_addr = NULL;
volatile unsigned int *gpio_oe_addr = NULL;
volatile unsigned int *gpio_setdataout_addr = NULL;
volatile unsigned int *gpio_cleardataout_addr = NULL;
unsigned int reg;

int fd = open("/dev/mem", O_RDWR);

printf("Mapping %X - %X (size: %X)\n", GPIO1_START_ADDR,
GPIO1_END_ADDR, GPIO1_SIZE);

gpio_addr = mmap(0, GPIO1_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, GPIO1_START_ADDR);

gpio_oe_addr = gpio_addr + GPIO_OE;
gpio_setdataout_addr = gpio_addr + GPIO_SETDATAOUT;
gpio_cleardataout_addr = gpio_addr + GPIO_CLEARDATAOUT;

if(gpio_addr == MAP_FAILED) {
printf("Unable to map GPIO\n");
exit(1);
}
printf("GPIO mapped to %p\n", gpio_addr);
printf("GPIO OE mapped to %p\n", gpio_oe_addr);
printf("GPIO SETDATAOUTADDR mapped to %p\n",
gpio_setdataout_addr);
printf("GPIO CLEARDATAOUT mapped to %p\n",
gpio_cleardataout_addr);

reg = *gpio_oe_addr;
printf("GPIO1 configuration: %X\n", reg);
reg = reg & (0xFFFFFFFF - PIN);
*gpio_oe_addr = reg;
printf("GPIO1 configuration: %X\n", reg);

printf("Start toggling PIN \n");
while(1) {

*gpio_setdataout_addr= PIN;
printf("on\n");
sleep(1);
*gpio_cleardataout_addr = PIN;
printf("off\n");
sleep(1);
}

close(fd);
return 0;
}
Post by j***@public.gmane.org
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?
Post by a***@public.gmane.org
http://chiragnagpal.github.io/examples.html
I have explained how to use /dev/mmap in beaglebone black
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Loading...