Thursday, March 29, 2012

'findViewById()' error in Android development

Each time after adding a new widget into my Android project, the system always posts a null-point error. I am pretty sure the code should be fine as I just did Ctrl+C & Ctr+V. Some suggests to add 'this.' before calling this function. Something like:

Button myBtn = (Button) this.findViewById(R.id.myBtn);

However, it does not work for me. Eventually, I got a useful answer. It's better to clean the entire project before compiling the updated source code. Since I am using 'ant' for the compilation, it will be like this:

> ant clean
> ant debug
> adb -d install -r bin\xxx-debug.apk


Saturday, March 24, 2012

Enabling SPI on BeagleBoard

Here is the reference blog to enable SPI on BeagleBoard with Angstrom.
[1] http://linuxdeveloper.blogspot.ca/2011/10/enabling-spi-on-beagleboard-xm.html

pin-mux:
Do not forget to patch /arch/arm/mach-omap2/board-omap3beagle.c
See [2] http://elinux.org/BeagleBoard/SPI for details. Here is the patch file:
[3] http://elinux.org/BeagleBoard/SPI/Patch-2.6.37

Actually, one can also customize U-boot to setup the pin-mux. Let's focus on the way provided by reference [2] now. After activating CONFIG_OMAP_MUX (You can do this by selecting 'System Type --> TI OMAP Implementations --> OMAP multiplexing support' in the kernel's make menuconfig. See [4] http://elinux.org/BeagleBoardPinMux for details.), I got a kernel panic error as mentioned in reference [2] and the following links:
[5] https://groups.google.com/forum/?fromgroups#!topic/beagleboard/Tmt1PS6KGmg
[6] https://groups.google.com/forum/?fromgroups#!topic/beagleboard/On9iVpUnWBI
(According to my tests, this panic error always occurs on the xM board. It may not happen on the original BeagleBoard as outlined by reference [6].)

To fix it up, reference [2], [5], and [6] gave a solution by commenting the line 'omap_cfg_reg(AH8_34XX_GPIO29);'. However, I cannot find this line in 'board-omap3beagle.c'. My kernel version is 2.6.34. Take a look at the git log, you'll find that new kernel versions do not support 'omap_cfg_reg()' anymore. I believe it was replaced by function 'omap_mux_init_gpio()', which appears in my 'board-omap3beagle.c'. Anyway, after commenting out lines:
'omap_mux_init_gpio(29, OMAP_PIN_INPUT);',
'omap_mux_init_gpio(23, OMAP_PIN_INPUT);',
and 'mmc[0].gpio_wp = 23;',
the panic error was gone.


The kernel image has been tested on both original BeagleBoard and xM board. 'spidev_test' results are good for /dev/spidev4.0, /dev/spidev3.0, and /dev/spidev3.1.

My next plan is to remap SPI3 on header P17 rather than the expansion header. I tried to modify 'board-omap3beagle.c' as follows:

static void __init omap3_beagle_config_mcspi3_mux(void)
{
// NOTE: Clock pins need to be in input mode
omap_mux_init_signal("etk_d3.mcspi3_clk",
OMAP_PIN_INPUT);
omap_mux_init_signal("etk_d2.mcspi3_cs0",
OMAP_PIN_OUTPUT);
omap_mux_init_signal("etk_d7.mcspi3_cs1",
OMAP_PIN_OUTPUT);
omap_mux_init_signal("etk_d0.mcspi3_simo",
OMAP_PIN_OUTPUT);
omap_mux_init_signal("etk_d1.mcspi3_somi",
OMAP_PIN_INPUT_PULLUP);
}

However, it does not work. I am still trying to figure out a solution.