GPIO Toggling on Beagleboard

Hi,

I am a new user of the Beagleboard with very limited exposure to Linux. I have the latest demo image of Angstrom running on the Beagleboard successfully. I am trying to get a GPIO pin toggling. I have tried to follow the MAKE Magazine’s guide to toggling an LED on the Beagleboard, but without much success. I think it’s due to the incorrect pin mux configurations. Googling has led me to this page → http://www.hy-research.com/omap3_pinmux.html But I am unable to understand it at all! What is "arch/arm/plat-omap/mux.h" and where can I find this file?

Regards,
Carson Au

Hello Carson,

You can create a new function, for example my_gpio_init() to setup the GPIO pins. You do not need to change mux.h. Then, you can call the newly created function my_gpio_init() in your main to setup your GPIO pins. If you don’t know how to use ioremap, google it. You also need to get the TI’s OMAP http://focus.ti.com/lit/ug/spruf98d/spruf98d.pdf. The PAD configuration info starts from page 829.

/*** copied from root_dir_uboot/include/asm/arch/mux.h **/
/

  • IEN - Input Enable
  • IDIS - Input Disable
  • PTD - Pull type Down
  • PTU - Pull type Up
  • DIS - Pull type selection is inactive
  • EN - Pull type selection is active
  • M0 - Mode 0
    */

#define IEN (1 << 8)

#define IDIS (0 << 8)
#define PTU (1 << 4)
#define PTD (0 << 4)
#define EN (1 << 3)
#define DIS (0 << 3)

#define M0 0
#define M1 1
#define M2 2
#define M3 3
#define M4 4
#define M5 5
#define M6 6
#define M7 7
/*** copied from root_dir_uboot/include/asm/arch/mux.h ***/
#define PAD_CONF_MASK (IEN | PTU | EN | M7)

static void my_gpio_init(void)
{
unsigned int padconf;
void __iomem *padconfs, *gpio_156_padconf;

padconfs = ioremap(0x48002000, SZ_4K);
if (!padconfs) {
printf(“my_gpio_init failed due to ioremap failed!\n”);
return;
}
gpio_156_padconf = padconfs + 0x18c;
// setup GPIO_156 as output to turn on or off the switch
padconf = *(unsigned int *)gpio_156_padconf;
padconf &= 0xffff0000;
padconf |= (EN | PTD | M4); // 0x0000000c => pull-type is LOW, mode = 4
*(unsigned int *)gpio_156_padconf = padconf;
//
iounmap(padconfs);
}

void main()
{
my_gpio_init();
// you may need to create another function similar to the gpio_init function to write to the output port.
// you can find out the PAD memory I/O address from the TI technical reference manual.
}

Hi Eric,

Thanks for the help. Where is “root_dir_uboot”? I suppose uBoot is kept on the onboard NAND flash? If so, how can I access this through Angstrom?

With the C program, is this something I compile with GCC on the beagleboard itself?

Thanks,
Carson

Hi Carson,

I copied codes from the uboot source code when I made changes on uboot. Then built the uboot and put it in the DOS partition of my SD card. When I got the C4 beagleboard, I did not want to do that anymore. Instead, I did the GPIO setup in kernel driver code since I have already a small customization in the mmc driver. You do not need to get uboot source code. You can do the init function in the user space code. I have done that before to show the setting of the PINMUXes. The demo image of Angstrom should have gcc. If not, go to http://www.angstrom-distribution.org/repo/ to get what you want. You need to use opkg to do the installation.

Here is the source code to dump the configuration of the PINMUXes. In user space code, we do not use ioremap. See the source code below:

#include <stdio.h>
#include <sys/errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>

#define MMAP_START 0x48002000
#define MMAP_SIZE 1024
#define PADCONFS_START 0x48002030
#define PADCONFS_SIZE 564

int main(int argc, char *argv[])
{
int i = 0;
int rc = 0;
int fd;
unsigned long padconfig;
unsigned long *padconfig_start;
char *mmap_addr;

fd = open("/dev/mem", O_RDWR);
if (fd == -1) {
printf(“open() failed!\n”);
rc = -1;
}
mmap_addr = mmap(NULL, MMAP_SIZE, PROT_READ, MAP_PRIVATE, fd, MMAP_START);
if (mmap_addr == MAP_FAILED) {
printf(“mmap() failed!\n”);
rc = -ENOMEM;
goto exit;
}
padconfig_start = (unsigned long *)(mmap_addr + (PADCONFS_START - MMAP_START));
for (i = 0; i < PADCONFS_SIZE >> 2; i++) {
padconfig = padconfig_start[i];
printf(“0x%08x\t0x%08x\n”, PADCONFS_START+(i<<2), padconfig);
}
exit:
return rc;
}

Thanks! Do I have to get an OMAP/ARM specific version of GCC?

The demo image of Angstrom doesn’t seem to have gcc (i.e. just typing gcc on xterm doesn’t seem to invoke the compiler if it did exist).

I am still using Angstrom-Beagleboard-demo-image-glibc-ipk-2009.
X-stable-20090612–beagleboard.rootfs.tar.bz2. This package has the gcc. Version is 4.4.3 installed in /usr/bin/gcc. You can type /usr/bin/gcc -v to find out if it is there or not. If not you can get gcc 4.3.3-r1.1 by click this link. This is for the armv7a.

Once you download the gcc “ipk”, you can use “opkg install gcc_4.3.3-r1.1_arm7a.ipk” to do the installation.

root@beagleboard:~# which gcc
/usr/bin/gcc
root@beagleboard:~# gcc -v
Using built-in specs.
Target: arm-angstrom-linux-gnueabi
Configured with: /OE/angstrom-dev/work/armv7a-angstrom-linux-gnueabi/gcc-4.3.3-r1/gcc-4.3.3/configure --build=x86_64-linux --host=arm-angstrom-linux-gnueabi --target=arm-angstrom-linux-gnueabi --prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --sysconfdir=/etc --sharedstatedir=/usr/com --localstatedir=/var --libdir=/usr/lib --includedir=/usr/include --oldincludedir=/usr/include --infodir=/usr/share/info --mandir=/usr/share/man --with-gnu-ld --enable-shared --enable-target-optspace --enable-languages=c,c++,objc --enable-threads=posix --enable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=arm-angstrom-linux-gnueabi- --enable-cheaders=c_std --enable-libssp --disable-bootstrap --disable-libgomp --disable-libmudflap --with-local-prefix=/usr/local --with-gxx-include-dir=/usr/include/c++/4.3.3 --enable-__cxa_atexit
Thread model: posix
gcc version 4.3.3 (GCC)