Sunday, July 31, 2011

Compiling Qt Embedded 4.7.3

The version of Qt and tslib used in this article are:

qt-everywhere-opensource-src-4.7.3
tslib 2011.07.01 snapshot

Assume that the working directory is

/home/user

and all the required cross tool chain setting are already done. Be sure that you are using the same version of tool chain you have used for your ARM kernel. Otherwise tslib utilities won't work properly. If you don't have the following packages, get them now:

$ sudo apt-get install autoconf
$ sudo apt-get install libtool

tslib

Before you compile Qt embedded you may want compile tslib first. Fortunately it is quite straightforward. Get the most recent version of tslib via git

$ git clone https://github.com/kergoth/tslib.git

Configure it

$ cd tslib
$ ./autogen.sh
$ ./configure --prefix=$HOME/tslib_arm --host=arm-none-linux-gnueabi

Compile and install it

$ make
$ make install

Then you can find the resulting directories like:



At this point, you can test this on your device. Copy the resulting directories bin, etc, and lib with its subdirectory ts to the corresponding directories of your device, e.g.,

/usr/local/bin
/usr/local/etc
/usr/local/lib

The etc directory contains the configuration file, ts.conf. You need to edit the file and uncomment the line to load at least one input raw module, such as

module_raw input

And you set the following environment variables:

export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CALIBFILE=/usr/local/etc/pointercal
export TSLIB_CONFFILE=/usr/local/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/local/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0

You may also have to add the lib (/usr/local/lib) directory to your LD_LIBRARY_PATH :

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

You want to put the above in your default profile (/etc/profile). Each device name varies depending on your kernel. For the detailed explanation about the variables, you can refer README file comes with tslib source.

Now you can run some executable files comes with the tslib, such as

ts_calibrate
ts_test

For the plugins (/usr/local/lib/ts), you can safely delete files you don't need. Usually you need:

dejitter.so
input.so
linear.so
pthres.so
variance.so

for your plugins.

Qt embedded

Download the qt embedded source and expand it on your working directory, e.g.,

/home/user/qt-everywhere-opensource-src-4.7.3

Before do anything, edit qmake.conf for your toolchain
mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf
and add the following lines:

QMAKE_INCDIR = /home/user/tslib_arm/include
QMAKE_LIBDIR = /home/user/tslib_arm/lib
QMAKE_LFLAGS = -lts

The last line is important although it is not mentioned elsewhere.
Now you can run configure with basic parameters:

./configure -embedded arm -xplatform qws/linux-arm-gnueabi-g++ \
-qt-kbd-linuxinput -qt-mouse-tslib -qt-gfx-linuxfb \
-little-endian -prefix-install -depths 16,18,24 -optimized-qmake

You can add some additional parameters for your convenience:

-release -opensource -confirm-license

And you can also opt out unused components:

-no-webkit -no-cups -no-largefile -no-openssl -no-mmx -no-sse -no-sse2

For the explanation of each parameter you can find by running:

./configure -embedded -help

After the configure, you may want to edit ./src/corelib/Makefile and add librt link option:

set LFLAGS = -lrt ......

Now, you are ready to go

$ make
$ sudo make install

It will take more than 30minutes to finish. After deploying Qt to your device, you may have to copy additional libraries from your tool chain system such as:

(from arm-none-linux-gnueabi/libc/lib)
libdl*, libptread*, librt*
(from arm-none-linux-gnueabi/libc/usr/lib)
libstdc++.so*

Qt also requires some environmental variables to run. Add following line to your profile

export QTDIR=/usr/local/QtEmbedded-4.7.3-arm
export PATH=$QTDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:/usr/local/lib:$LD_LIBRARY_PATH
export QWS_MOUSE_PROTO="TSLIB:/dev/input/event1"
export QWS_KEYBOARD=TTY:/dev/tty1

Be sure to give -qws option for the first qt application you want to run.

If you have a warning like

Could not read calibration: "/etc/pointercal"

when you run qt application, then probably your calibration file is located elsewhere (/usr/local/etc) as in this example. So you have to set an environmental variable

export POINTERCAL_FILE=/usr/local/etc/pointercal

to override the default hard coded calibration file location.

additional information

Qt embedded uses /tmp as its temporary data storage. To change this, use

#define QT_PRIVATE_QWS 1
#define QT_QWS_TEMP_DIR "/usr/local/tmp

when you compile Qt.

Tuesday, July 19, 2011

Cross Compiling MTD Utils

Cross-compiling MTD utils is tricky and eLinux wiki article is out-dated. So you may need some tweaks. As of this writing, we will use the most recent versions of :
  • mtd-utils - Jul. 4 2011 snapshot
  • e2fsprogs-1.41.14
  • lzo-2.05
  • zlib-1.2.5
As in the eLinux wiki, we take

/home/user/mtd

as build directory and

/home/user/mtd/install

as target path. First, you want extract all sources under /home/user/mtd, so your build directory looks like


zlib

Go to the source directory and execute configuration utility

~/mtd$ cd zlib-1.2.5
~/mtd/zlib-1.2.5$ ./configure --prefix=/usr

prefix option here is required if you want /usr as your target root for resulting output, otherwise /usr/local will be the target directory like most cases. We have chosen to use /usr. It is yours to decide. Before building anything you have to edit the Makefile.

CROSS = arm-none-linux-gnueabi-
CC = $(CROSS)gcc
LDSHARED = $(CROSS)gcc -shared ...
CPP = $(CROSS)gcc -E
AR = $(CROSS)ar rc
RANLIB = $(CROSS)ranlib

Then you are ready to go

~/mtd/zlib-1.2.5$ make
~/mtd/zlib-1.2.5$ make install DESTDIR=/home/user/mtd/install


lzo

lzo is cross build friendly. So it is straightforward to do.

~/mtd/lzo-2.05$ ./configure --host=arm-none-linux-gnueabi --prefix=/usr
~/mtd/lzo-2.05$ make
~/mtd/lzo-2.05$ make install DESTDIR=/home/user/mtd/install


e2fsprogs

Building e2fsprogs is same with lzo

~/mtd/e2fsprogs-1.41.14$ ./configure --host=arm-none-linux-gnueabi --prefix=/usr
~/mtd/e2fsprogs-1.41.14$ make
~/mtd/e2fsprogs-1.41.14$ make install DESTDIR=/home/user/mtd/install

But for some reason, you have to copy following two files to the target directory

~/mtd/e2fsprogs-1.41.14$ mkdir ../install/usr/include/uuid
~/mtd/e2fsprogs-1.41.14$ cp lib/uuid/uuid.h ../install/usr/include/uuid
~/mtd/e2fsprogs-1.41.14$ cp lib/libuuid.a ../install/usr/lib

Note that the target directories for the above cp operation are related to your choice of --prefix option before. If you have chosen not to change the default directory, then you have to do like:

~/mtd/e2fsprogs-1.41.14$ mkdir ../install/usr/local/include/uuid
~/mtd/e2fsprogs-1.41.14$ cp lib/uuid/uuid.h ../install/usr/local/include/uuid
~/mtd/e2fsprogs-1.41.14$ cp lib/libuuid.a ../install/usr/local/lib


mtd-utils

First, You have to edit Makefile and add following at the top of the file

INSTALLDIR = /home/user/mtd/install/usr
ZLIBCPPFLAGS = -I$(INSTALLDIR)/include
LZOCPPFLAGS = -I$(INSTALLDIR)/include
ZLIBLDFLAGS = -L$(INSTALLDIR)/lib
LZOLDFLAGS = -L$(INSTALLDIR)/lib
WITHOUT_XATTR = 1
CROSS = arm-none-linux-gnueabi-
LDFLAGS += $(ZLIBLDFLAGS) $(LZOLDFLAGS)

Again note that INSTALLDIR corresponds to --prefix option before. If you have chosen not to change the target, then your INSTALLDIR here should be

INSTALLDIR = /home/user/mtd/install/usr/local

Edit common.mk and change the CFLAGS,

CFLAGS ?= -O2 -g $(ZLIBCPPFLAGS) $(LZOCPPFLAGS)

and replace the BUILDDIR

ifndef BUILDDIR
#ifeq ($(origin CROSS),undefined)
# BUILDDIR := $(CURDIR)
#else
## Remove the trailing slash to make the directory name
# BUILDDIR := $(CURDIR)/$(CROSS:-=)
#endif
BUILDDIR := $(CURDIR)
endif

Now, you are ready to build mtd-utils

~/mtd/mtd-utils$ make
~/mtd/mtd-utils$ make install DESTDIR=/home/user/mtd/install

You can find some of precompiled files here.

Tuesday, June 28, 2011

Porting FreeRTOS on miniSTM32

FreeRTOS source comes with a bunch of demos for various boards. You can choose the project for Atollic (CORTEX_STM32F100_Atollic) for your starting point. Atollic TrueSTUDIO is nothing but Eclipse with GCC, so it is almost ready to go if you are using gnu tool-chain. Besides, it has recent version of ST peripheral library. Actually this is only ST library compliant with CMSIS standard among the FreeRTOS demos.

First, gather the source code you need and put them under the ST peripheral library tree (stm32f10x_stdperiph_lib). There is a batch file in the CORTEX_STM32F100_Atollic directory:

$ CreateProjectDirectoryStructure.bat

So, you just fire it up then it will do the job for you. It collects the FreeRTOS source files and put them in the

$ FreeRTOS_Source

directory. Copy this directory under the ST library tree. Also create a demo project directory(you can use CodeLite as described in the previous post) and copy these two files:

$ Simple_Demo\FreeRTOSConfig.h
$ main.c


into the project directory. Then the directory structure would be


In the above tree, FreeRTOS_Demo is the project directory. Other file you need in the project directory is

$ stm32f10x_conf.h

Unlike other project,

$ stm32f10x_it.c
$ stm32f10x_it.h


are not used here. It's routines are replaced by FreeRTOS.

As usual, prepare Makefile and a linker script. Be sure to include the following paths

$ INCLUDEPATHS += -I ../../FreeRTOS_Source/include
$ INCLUDEPATHS += -I ../../FreeRTOS_Source/portable/GCC/ARM_CM3


in your INCLUDEPATHES and the following source codes

$ C_SRC += ../../FreeRTOS_Source/list.c
$ C_SRC += ../../FreeRTOS_Source/queue.c
$ C_SRC += ../../FreeRTOS_Source/tasks.c
$ C_SRC += ../../FreeRTOS_Source/timers.c
$ C_SRC += ../../FreeRTOS_Source/portable/GCC/ARM_CM3/port.c
$ C_SRC += ../../FreeRTOS_Source/portable/MemMang/heap_1.c


in your source list to compile. Others are pretty much the same with other projects.

In order to run the demo, you will need BSP(board support package) for your board. Fortunately, ST library comes with plenty of BSP source code for varous STM32 evaluation board and it is quite well organized. So, it is easy to make a BSP by yourself. Create a directory under Utilities/STM32_EVAL tree for miniSTM32


and write your BSP files there. STM32100E_EVAL source would be a good reference. If there is no error in the BSP, FreeRTOS demo code will be compiled with no problem.

Monday, June 27, 2011

STM32F GCC IDE on Windows(2)

Test Project Build
Let's test build with some examples provided by ST. First copy the GPIO/IOToggle source files to the project directory just created.



Then create a make file and linker script file for the project. In this state, you can build(F7) and clean the project as you typed in the previous post. Actually everything is done by make utility and CodeLite is just invoking it.

It would be nice you can navigate and edit each file. At the left Workspace pane, right click on the project name and select the "Import Files from Directory".


Then you can select directories(and files) you want to show on your Workspace pane, which will probably match the source list of your Makefile. If there is no (sub)directories to select, you can choose as many as you want by clicking the Browse button on the top right of the dialog.


Resulting directory structure probably matches the source list of your Makefile. Be sure to remember that this tree is created regardless of project structure itself and you are not suppose to compile each individual file.

Flash Utility Integration
You can bring up the external flash utilities by registering those as external tools. Select Plugins-> External tools ->Configure external tools or just click the corresponding button from the menu bar


Then you can register your flash program.


Surely it is not as convenient as a native flasher but it is still useful.

Sunday, June 26, 2011

STM32F GCC IDE on Windows(1)

You can easily build a GCC IDE for Cortex-M3 using a open source IDE.  If you are not a big fan of Eclipse like me, you will probably like CodeLite or Geany. Both programs are cross platform, open source, and light-weight. Geany is more minimalistic of two. If you are familiar with Visual Studio, you will find CodeLite is more comfortable.

I'm going to use the following programs:


GCC and Make
For the CSG++ Lite, be sure to download the installer version(EABI). Install is straight forward. You don't have to change any settings. After install, you should add the following directory to your PATH.

> C:\Program Files\CodeSourcery\Sourcery G++ Lite\bin

You can verify that your PATH is set up correctly by running

> arm-none-eabi-gcc -v

on your console window.
Other than the compiler collection, you may need at least GNU make utility. You can install Cygwin for the make utility. But the simplest way is using GnuWin32. Download and install the GnuWin32 make package. You also have to add its bin directory to you PATH. You can install as many GnuWin32 packages as you need.

> C:\Program Files\GnuWin32\bin

STM32F Library and CodeLite Project
Download the library(stm32f10x_stdperiph_lib.zip) and extract it on your work directory. Then install CodeLite and fire it up to create initial workspace and project. For convenience, create a Codelite workspace under the STM32F library directory. (Workspace->New Workspace)


By selecting the workspace name and path as shown and deselecting the "Create the workspace under a separate directory" check box, you can use the STM32F library project directory as your workspace. But it is only for convenience sake. You can choose your workspace anywhere you like.

Now create a new project.(Workspace->New Project)


For the Categories, choose "Others" then you can select "Custom Makefile" type for the template. Type in your project name. And select compiler type. Compiler type here is not important because you will use your own build and compile command strings. Resulting directory structure would be



For now, there is no file under GpioTest directory except the CodeLite project file.

After the  project creation, go to the project settings by right click on the project "GpioTest" and select the last menu item.


Go to "Customize" on the left, then check "Enable custom build". You want  change "Working Directory" from $(WorkspacePath) to $(ProjectPath) where you have your own Makefile. Now fill in the Build Command with "make" and the Clean Command with "make clean". In this way, you can use your Makefile to build your project instead of CodeLite's own makefile.

Sunday, May 8, 2011

JLink with BeagleBoard

If you hook-up JLink to BeagleBoard and execute JLink commander, then you probably get the following error:

****** Error: DBEGN is not asserted.

And fail to recognise the target. This is because TI OMAP3530 needs a special setup sequence for JLink to connect, which is controlled by JLink script file (Default.JLinkScript)

Find the script file:

$JLINK_INST_DIR$\Samples\JLink\Scripts\ScriptBeagleBoard...

Copy it to the base directory(Windows) or the current directory(Linux) and rename it to

Default.JLinkScript

Then you can successfully connect to the board.

VMware Player on Xubuntu

Xubuntu : 10.10 / 11.04
VMware-Player : 3.1.3-385536

Be sure to install the following packages before installing vmware-player

- libglibmm-2.4-1c2a
- libgnomecanvasmm-2.6-1c2a

Otherwise you cannot fire-up the installer, not to mention the player itself.
If you encounter another issue after the install, check this out.