Beagleboard xM PinMux Ubuntu

Hi, folks!

I'm trying to configure the PinMux configuration of my Beagleboard xM.
There are some introductions like http://elinux.org/BeagleBoardPinMux
around, nevertheless I had to invest days to get it running the first
time and it's still not the way I'd wish. Thant's why I decided to
condense all Ubuntu+BBxM+PinMux specific information I found so far
combined with all my questions...
I'd be very happy for some tips, if I got something wrong please
correct this as well.
I'm a Linux beginner, that's why I have to ask some questions which
may be banal for you, hope you don't mind...
[I'm using BeagleBoard xM Rev. B, running Ubuntu 11.10 from the
prebuild image of Robert Nelson http://elinux.org/BeagleBoardUbuntu#Oneiric_11.10
, and xubuntu-desktop GUI, hopping to find a way to adopt this for my
needs. For compiling/preparing microSD-card I'm using a machine
running Ubuntu 10.10]

I came across three possibilities for PinMux/pin value manipulation
and some pros and cons for each:
[1]>>>u-boot-PinMux<<<
  Default settings of boatloader, used if the CONFIG_OMAP_MUX flag is
not set/defined.
  For changes you need to edit the u-boot boatloader source files,
rebuild it and then replace the existing
        u-boot.bin on the microSD-card
[1.1] + easy to configure with the help of TI's PinMux Utility (for
Windows)
[1.2] + compiling u-boot can be done in a few minutes (unlike
rebuilding the kernel)
  + permanent changes
[1.3] - uboot is corresponding to the kernel you are using, where
necessary
  - without PinMux Utility manipulation needs to be done carefully
          (http://elinux.org/
BeagleBoardPinMux#A_word_of_warning_about_beagle.h )

Hi, folks!

I'm trying to configure the PinMux configuration of my Beagleboard xM.
There are some introductions like BeagleBoardPinMux - eLinux.org
around, nevertheless I had to invest days to get it running the first
time and it's still not the way I'd wish. Thant's why I decided to
condense all Ubuntu+BBxM+PinMux specific information I found so far
combined with all my questions...
I'd be very happy for some tips, if I got something wrong please
correct this as well.
I'm a Linux beginner, that's why I have to ask some questions which
may be banal for you, hope you don't mind...
[I'm using BeagleBoard xM Rev. B, running Ubuntu 11.10 from the
prebuild image of Robert Nelson BeagleBoardUbuntu - eLinux.org
, and xubuntu-desktop GUI, hopping to find a way to adopt this for my
needs. For compiling/preparing microSD-card I'm using a machine
running Ubuntu 10.10]

I came across three possibilities for PinMux/pin value manipulation
and some pros and cons for each:
[1]>>>u-boot-PinMux<<<
Default settings of boatloader, used if the CONFIG_OMAP_MUX flag is
not set/defined.
For changes you need to edit the u-boot boatloader source files,
rebuild it and then replace the existing
u-boot.bin on the microSD-card
[1.1] + easy to configure with the help of TI's PinMux Utility (for
Windows)
[1.2] + compiling u-boot can be done in a few minutes (unlike
rebuilding the kernel)
+ permanent changes
[1.3] - uboot is corresponding to the kernel you are using, where
necessary
- without PinMux Utility manipulation needs to be done carefully
(http://elinux.org/
BeagleBoardPinMux#A_word_of_warning_about_beagle.h )
----------------------------------------------------------------------------------------------------------------------------------------------------
@[1.3] Where can I find the right source files for uboot if using a
prebuild image?
In free-electrons.com/doc/u-boot.pdf I found the advice that [...]The
kernel image that U-Boot loads and boots must be prepared, so that an
U-Boot specific header is added in front of the image […] What does
this mean in my case?

@[1.1] Following the instruction of TI's PinMux Utility, you should:
1) Replace the mux.h header file with the mux.h output file from Pin
Mux Utility
→ in my case found at
…./ubuntu-11.10-r3-minimal-armel/stable-kernel/KERNEL/arch/arm/mach-
omap2/mux.h
2) Copy the pinmux.h output file from Pin Mux Utility into the
directory containing the evm.h file.
→ in my case found at
…./ubuntu-11.10-r3-minimal-armel/stable-kernel/KERNEL/include/config/
i2c/taos
3) Modify the original evm.h file, commenting out or deleting the
original section of code that
makes the pin mux programming macro calls.
→ file was empty in my case !?
4) Replace this code with #include "pinmux.h"
Everything right so far? The elinux-instruction says the changes
should take place in board/ti/beagle/beagle.h (but there the used OS
is openEmbedded)!?

@[1.2]What's the way you would recommend for easy/quick compiling
uboot?
----------------------------------------------------------------------------------------------------------------------------------------------------
[2]>>>Kernel-PinMux<<<
Kernle specific pinMux setting if ONFIG_OMAP_MUX flag is set/defined
[2.1] For changes you need to edit the kernel source files, rebuild it
and then replace the existing uImage on the
microSD-card
For following the instruction BeagleBoardPinMux - eLinux.org
you need to know that BB xM's DM3730 is using CBP Package (?!, btw. I
didn't find differences at the
register names used in CBB package (used by standard BB), but
I only glanced trough …??)
+ permanent changes
+ no need to change u-boot
[2.2] - takes long to compile
----------------------------------------------------------------------------------------------------------------------------------------------------
@[2.1]I made similar steps as Brian Hensly used to modify the kernel,
using nice scrips from Robert again...
SPI working on the Beagleboard XM rev C - Brian Hensley

sudo apt-get install gcc-arm-linux-gnueabi git
sudo apt-get install ccache libncurses5-dev u-boot-tools
git clone git://github.com/RobertCNelson/stable-kernel.git
cd stable-kernel
git checkout origin/v3.1.x -b v3.1.x
gedit build_kernel.sh # Is there a Patch I should un-commend?
# In .../stable-kernel/patches/beagle I saw 0001-beagle-hack-
enable-1Ghz.patch …?
cp system.sh.sample system.sh
gedit system.sh # → un-commend CC=arm-linux-gnueabi-
cd ~/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

→ change …./arch/arm/mach-omap2/board-omap3beagle.c like explained in
BeagleBoardPinMux - eLinux.org
I changed the relevant part to
------
#ifdef CONFIG_OMAP_MUX
static struct omap_board_mux board_mux __initdata = {
{OMAP_MUX(MCBSP1_FSX, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(MCBSP1_DR, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(MCBSP1_CLKR, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(SDMMC2_DAT7, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(SDMMC2_DAT6, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(SDMMC2_DAT5, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(SDMMC2_DAT4, OMAP_MUX_MODE4 | OMAP_PIN_OUTPUT),
OMAP_MUX(UART2_CTS, OMAP_MUX_MODE2 | OMAP_PIN_OUTPUT),
OMAP_MUX(UART2_TX, OMAP_MUX_MODE2 | OMAP_PIN_OUTPUT),
OMAP_MUX(UART2_RTS, OMAP_MUX_MODE2 | OMAP_PIN_OUTPUT),
OMAP_MUX(MCBSP1_DX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLDOWN),
OMAP_MUX(MCBSP1_CLKX, OMAP_MUX_MODE4 | OMAP_PIN_INPUT_PULLUP),
.reg_offset = OMAP_MUX_TERMINATOR },
};
#endif

//GPIO_161 EXP-Pin 16
//GPIO_159 EXP-Pin 18
//GPIO_156, EXP-Pin 20
//GPIO_139, EXP-Pin 3
//GPIO_138, EXP-Pin 5
//GPIO_137, EXP-Pin 7
//GPIO_136, EXP-Pin 9
//GPT9_PWMEVT ->PWM, EXP-Pin 4
//GPT11_PWMEVT->PWM, EXP-Pin 6
//GPT10_PWMEVT->PWM, EXP-Pin 10
//GPIO_158, EXP-Pin 12
//GPIO_162, EXP-Pin 14
------
cd~/
cd stable-kernel
./build_kernel.sh
→ by using this script (the first time!?) the make menuconfig is
executed, there you have to set the flag CONFIG_OMAP_MUX by selecting
System Type --> TI OMAP Implementations --> OMAP multiplexing support
Device Drivers --> GPIO Support --> /sys/class/gpio/... (sysfs
interface)

When kernel is build

cd ~/
cd stable-kernel/
gedit system.sh
#CHANGE the MMC and un-comment"#" in front of the ZRELADDR:
→MMC=/dev/sdb #make sure sdb is the right drive letter first!!!

Are you sure your mmc/sd card adapter is using /dev/sdb?

→ZRELADDR=0x80008000

. ./tools/load_uImage.sh # will copy the uImage to microSD-card

Yeah, that's always just been a quick hack, i really need to rewrite
it with error checking because more people are using it, and it
assumes some things..

For some reasons this didn't work, did you see something I did wrong?
May I not use the build_kernel.sh script, use the mkimage command
instead?

(that's all that script does..)

@[2.2] Is it possible to use ./tools/rebuild.sh if the kernel was
compiled once and some changes made in the source code, e.g. in board-
omap3beagle.c ?

Yeap, that's what that script is for. :wink:

-----------------------------------------------------------------------------------------------------------------------
[3]Access from userspace
+ For quick tries you can use the sysfs-interface, but
- changes are only temporary, need to be done EACH time you reboot
- access only for superuser, to edit pin values from a script you
have to change permissions

Here some sample code for using GPIO 139:
cd /sys/class/gpio
sudo su
echo 139 > export
cd gpio139
echo “out” > direction
chmod 666 value
exit
echo 1 > value
echo 0 > value

----------------------------------------------------------------------------------------------------------------------------------------------------
[4]Some more questions:

[4.1]Would you recommend to use make menuconfig to set the
CONFIG_OMAP_MUX flag
or is there the possibility to set CONFIG_OMAP_MUX=y in a kernel
config file?

WIth my images, it's on by default:

voodoo@beagle-xma-512mb:~$ zcat /proc/config.gz | grep OMAP_MUX
CONFIG_OMAP_MUX=y
CONFIG_OMAP_MUX_DEBUG=y
CONFIG_OMAP_MUX_WARNINGS=y

[4.2]Where can I check if the CONFIG_OMAP_MUX is set if using a
prebuild image?

[4.3]If I got the PinMux right, where can I decide if a GPIO-output is
high or low as default?

[4.4]What do I have to change to make sure the GPIOs are mounted as
default at /sys/class/gpio?

[4.5]Where would you change the permissions for these PINs? I want to
change the high/low status just by executing a Python script later,
e.g.
--------
import sys
import time

print "Test gpio139"
print "Enter CTRL+C to exit"

def high():
x =open("/sys/class/gpio/gpio139/value", "w")
x.write(str(1))
x.close()
print "high"
def low():
x =open("/sys/class/gpio/gpio139/value", "w")
x.write(str(0))
x.close()
print "low"
while 1:
high()
time.sleep(3)
low()
time.sleep(3)
--------

[4.6]In the BBxM Reference Manual I found on p.26
[..] 4.14 User Button
A button is provided on the BeagleBoard to be used as an application
button that can be used by SW as needed. As there is no NAND boot
option on the board, this button is no longer needed to force an SD
card boot. It is can be used by the UBoot SW to switch between user
scripts to allow different boot configurations to be selected as long
as that feature is included in the UBoot used. If you press this
button on power up, the board will not boot properly. [..]
How would you implement these option?

u-boot reads/scans the status of the button on the xM's...

Regards,